The following issues were found

torch/csrc/jit/python/script_init.cpp
1 issues
Syntax Error: AST broken, 'if' doesn't have two operands.
Error

Line: 976

                    {"__str__",
       [](const Object& self, py::args args, py::kwargs kwargs) -> py::object {
         auto method = self.find_method("__str__");
         if (!method) {
           return py::str("ScriptObject");
         }
         return invokeScriptMethodFromPython(
             *method,
             // NOLINTNEXTLINE(performance-move-const-arg)

            

Reported by Cppcheck.

torch/csrc/jit/python/init.cpp
1 issues
read - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 1054 Column: 12 CWE codes: 120 20

                    return memview;
    }

    size_t read(uint64_t pos, void* buf, size_t n, const char* what)
        const override {
      // Seek to desired position (NB: this has to be a Py_ssize_t or Python
      // throws a weird error)
      Py_ssize_t absolute_pos = start_offset_ + pos;
      buffer_.attr("seek")(absolute_pos);

            

Reported by FlawFinder.

torch/csrc/api/src/nn/init.cpp
1 issues
Returning object that points to local variable 'fan_out' that will be invalid when returning.
Error

Line: 249 CWE codes: 562

                  fan_in = num_input_fmaps * receptive_field_size;
    fan_out = num_output_fmaps * receptive_field_size;
  }
  return std::tie(fan_in, fan_out);
}

} // namespace init
} // namespace nn
} // namespace torch

            

Reported by Cppcheck.

torch/csrc/api/src/data/samplers/stream.cpp
1 issues
read - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 52 Column: 11 CWE codes: 120 20

              
void StreamSampler::load(serialize::InputArchive& archive) {
  auto tensor = torch::empty(1, torch::kInt64);
  archive.read(
      "examples_retrieved_so_far",
      tensor,
      /*is_buffer=*/true);
  examples_retrieved_so_far_ = tensor.item<int64_t>();
}

            

Reported by FlawFinder.

torch/csrc/api/src/data/samplers/sequential.cpp
1 issues
read - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 42 Column: 11 CWE codes: 120 20

              
void SequentialSampler::load(serialize::InputArchive& archive) {
  auto tensor = torch::empty(1, torch::kInt64);
  archive.read(
      "index",
      tensor,
      /*is_buffer=*/true);
  index_ = tensor.item<int64_t>();
}

            

Reported by FlawFinder.

torch/csrc/jit/passes/shape_analysis.cpp
1 issues
Syntax Error: AST broken, 'if' doesn't have two operands.
Error

Line: 906

                        auto input_type = node->input(0)->type()->cast<TensorType>();

          // Maps complex -> float
          if (input_type->scalarType()) {
            const auto scalar_type = *(input_type->scalarType());
            if (isComplexType(scalar_type)) {
              const auto out_type = c10::toValueType(scalar_type);
              return type_vec_t{
                  input_type->dimensionedOnly()->withScalarType(out_type)};

            

Reported by Cppcheck.

torch/csrc/jit/passes/remove_mutation.cpp
1 issues
Uninitialized variable: new_node
Error

Line: 66 CWE codes: 908

                } else {
    TORCH_INTERNAL_ASSERT(false);
  }
  new_node->copyMetadata(n);
  new_node->output()->setType(n->output()->type());
  return new_node;
}

bool removableSetItem(Node* n) {

            

Reported by Cppcheck.

torch/csrc/jit/passes/quantization/quantization_type.cpp
1 issues
setstate - This function is not sufficiently random for security-related functions such as key and nonce creation
Security

Line: 15 Column: 10 CWE codes: 327
Suggestion: Use a more secure technique for acquiring random values

                    os << "static";
      break;
    default:
      os.setstate(std::ios_base::failbit);
  }
  return os;
}

} // namespace jit

            

Reported by FlawFinder.

torch/csrc/jit/passes/peephole_list_idioms.cpp
1 issues
Non-local variable 'active_refinements_' will use object that points to local variable 'block_refinements'.
Error

Line: 126 CWE codes: 562

                          n, throwing_blocks_, boolean_value_refinements_);
      }
    }
    active_refinements_.pop_back();
    return block_refinements;
  };

  c10::optional<int64_t> tryFindRefinement(Value* v) {
    for (const auto& ref : active_refinements_) {

            

Reported by Cppcheck.

torch/csrc/jit/passes/integer_value_refinement.cpp
1 issues
Non-local variable 'active_refinements_' will use object that points to local variable 'block_refinements'.
Error

Line: 200 CWE codes: 562

                    }
    }

    active_refinements_.pop_back();
    return block_refinements;
  };

  c10::optional<int64_t> tryFindRefinement(Value* v) {
    for (const auto& ref : active_refinements_) {

            

Reported by Cppcheck.