The following issues were found

caffe2/core/net_dag_utils_test.cc
1 issues
syntax error
Error

Line: 71

              }
} // namespace

TEST(DagUtilTest, Empty) {
  const auto spec = R"DOC(
    name: "test0"
    type: "async_scheduling"
    )DOC";
  Workspace ws;

            

Reported by Cppcheck.

caffe2/core/net_async_tracing_test.cc
1 issues
syntax error
Error

Line: 28

                EXPECT_EQ(extractShardId(name), expectedId);
}

TEST(NetAsyncTracingTest, ExtractShardId) {
  testExtractShardId("ABCDEFshard:1705!!A", 1705);
  // Should use the last one
  testExtractShardId("ABCDEFshard:4324!!Ashard:01220b", 1220);
  // Nothing to extract
  testExtractShardId("ABCDEFsha:222", -1);

            

Reported by Cppcheck.

caffe2/core/module_test.cc
1 issues
syntax error
Error

Line: 30

                Caffe2ModuleTestStaticDummy, Caffe2ModuleTestStaticDummyOp);
OPERATOR_SCHEMA(Caffe2ModuleTestStaticDummy);

TEST(ModuleTest, StaticModule) {
  const string name = "caffe2_module_test_static";
  const auto& modules = CurrentModules();
  EXPECT_EQ(modules.count(name), 1);
  EXPECT_TRUE(HasModule(name));


            

Reported by Cppcheck.

caffe2/core/init_test.cc
1 issues
syntax error
Error

Line: 35

              char** dummy_argv = const_cast<char**>(&dummy_name);
} // namespace

TEST(InitTest, TestInitFunctionHasRun) {
  caffe2::GlobalInit(&dummy_argc, &dummy_argv);
  EXPECT_TRUE(gTestInitFunctionHasBeenRun);
  EXPECT_FALSE(gTestFailInitFunctionHasBeenRun);
}


            

Reported by Cppcheck.

caffe2/core/graph_test.cc
1 issues
syntax error
Error

Line: 60

                }
}

TEST(GraphTest, TestGenerateGraphChain) {
  Workspace ws;
  ws.CreateBlob("in");
  NetDef netdef;
  AddOp(&netdef, "GraphDummyOp1", {"in"}, {"mid1"});
  AddOp(&netdef, "GraphDummyOp2", {"mid1"}, {"mid2"});

            

Reported by Cppcheck.

caffe2/core/event_test.cc
1 issues
syntax error
Error

Line: 25

                event.Wait(CPU, &context);
}

TEST(EventCPUTest, EventErrors) {
  DeviceOption device_option;
  device_option.set_device_type(PROTO_CPU);
  Event event(device_option);

  event.SetFinished();

            

Reported by Cppcheck.

caffe2/core/context_test.cc
1 issues
syntax error
Error

Line: 17

                }
}

TEST(CPUContextTest, TestAllocDealloc) {
  auto data_ptr = CPUContext::New(10 * sizeof(float));
  float* data = static_cast<float*>(data_ptr.get());
  EXPECT_NE(data, nullptr);
  auto dst_data_ptr = CPUContext::New(10 * sizeof(float));
  float* dst_data = static_cast<float*>(dst_data_ptr.get());

            

Reported by Cppcheck.

caffe2/core/context_gpu_test.cc
1 issues
syntax error
Error

Line: 16

                EXPECT_TRUE(HasCudaRuntime());
}

TEST(CUDAContextTest, TestAllocDealloc) {
  if (!HasCudaGPU()) return;
  CUDAContext context(0);
  context.SwitchToDevice();
  auto data = CUDAContext::New(10 * sizeof(float));
  EXPECT_NE(data.get(), nullptr);

            

Reported by Cppcheck.

caffe2/core/context.cc
1 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 34 Column: 3 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

                }
  CAFFE_ENFORCE(src);
  CAFFE_ENFORCE(dst);
  memcpy(dst, src, nbytes);
}

void CopyBytesWrapper(
    size_t nbytes,
    const void* src,

            

Reported by FlawFinder.

caffe2/core/common_test.cc
1 issues
syntax error
Error

Line: 24

                EXPECT_EQ(i_std, i_caffe2);
}

TEST(CommonTest, TestStod) {
  // Full string is parsed.
  string s = "1.234";
  std::size_t p_std = 0, p_caffe2 = 0;
  double d_std = std::stod(s, &p_std);
  double d_caffe2 = ::c10::stod(s, &p_caffe2);

            

Reported by Cppcheck.