[ coverity ] Fix coverity issue
authorskykongkong8 <ss.kong@samsung.com>
Thu, 21 Mar 2024 10:34:32 +0000 (19:34 +0900)
committerjijoong.moon <jijoong.moon@samsung.com>
Thu, 28 Mar 2024 23:42:43 +0000 (08:42 +0900)
- Fix coverity issue 17742301774235177423817742391774243

Resolves:
```
Use of auto that causes a copy (AUTO_CAUSES_COPY)
auto_causes_copy: This lambda has an unspecified return type
copy: This return statement creates a copy.
```

**Self evaluation:**
1. Build test:  [X]Passed [ ]Failed [ ]Skipped
2. Run test:  [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: skykongkong8 <ss.kong@samsung.com>
test/unittest/layers/layers_golden_tests.cpp
test/unittest/models/unittest_models_multiout.cpp
test/unittest/unittest_nntrainer_graph.cpp
test/unittest/unittest_nntrainer_modelfile.cpp

index eac8872750509cef424df757edf8881bcda843e0..4c0e3ceb3c251dfc5f5526267dc74e9f20cc1c2c 100644 (file)
@@ -298,25 +298,32 @@ static void compareRunContext(RunLayerContext &rc, std::ifstream &file,
 
   constexpr bool skip_compare = true;
 
-  compare_tensors(rc.getNumWeights(),
-                  [&rc](unsigned idx) { return rc.getWeight(idx); },
-                  always_read, skip_compare, skip_cos_sim, "initial_weights");
-  compare_tensors(rc.getNumInputs(),
-                  [&rc](unsigned idx) { return rc.getInput(idx); }, always_read,
-                  !skip_compare, skip_cos_sim, "inputs");
   compare_tensors(
-    rc.getNumOutputs(), [&rc](unsigned idx) { return rc.getOutput(idx); },
+    rc.getNumWeights(),
+    [&rc](unsigned idx) -> const auto & { return rc.getWeight(idx); },
+    always_read, skip_compare, skip_cos_sim, "initial_weights");
+  compare_tensors(
+    rc.getNumInputs(),
+    [&rc](unsigned idx) -> const auto & { return rc.getInput(idx); },
+    always_read, !skip_compare, skip_cos_sim, "inputs");
+  compare_tensors(
+    rc.getNumOutputs(),
+    [&rc](unsigned idx) -> const auto & { return rc.getOutput(idx); },
     always_read, !skip_compare, skip_cos_sim, "outputs", match_percentage);
-  compare_tensors(rc.getNumWeights(),
-                  [&rc](unsigned idx) { return rc.getWeightGrad(idx); },
-                  only_read_trainable, skip_grad, skip_cos_sim, "gradients");
-  compare_tensors(rc.getNumWeights(),
-                  [&rc](unsigned idx) { return rc.getWeight(idx); },
-                  always_read, !skip_compare, skip_cos_sim, "weights");
-  compare_tensors(rc.getNumInputs(),
-                  [&rc](unsigned idx) { return rc.getOutgoingDerivative(idx); },
-                  always_read, skip_deriv, skip_cos_sim, "derivatives",
-                  match_percentage);
+  compare_tensors(
+    rc.getNumWeights(),
+    [&rc](unsigned idx) -> const auto & { return rc.getWeightGrad(idx); },
+    only_read_trainable, skip_grad, skip_cos_sim, "gradients");
+  compare_tensors(
+    rc.getNumWeights(),
+    [&rc](unsigned idx) -> const auto & { return rc.getWeight(idx); },
+    always_read, !skip_compare, skip_cos_sim, "weights");
+  compare_tensors(
+    rc.getNumInputs(),
+    [&rc](unsigned idx) -> const auto & {
+      return rc.getOutgoingDerivative(idx);
+    },
+    always_read, skip_deriv, skip_cos_sim, "derivatives", match_percentage);
 }
 
 LayerGoldenTest::~LayerGoldenTest() {}
index e262b7c28c6038d581acc50925e711cef5285a01..303fc8a4e1a66f8d2d878bf7523d1c4c0f4ad3a1 100644 (file)
@@ -249,6 +249,5 @@ GTEST_PARAMETER_TEST(
     mkModelTc_V2(split_and_join_dangle, "split_and_join_dangle",
                  ModelTestOption::ALL_V2),
   }),
-  [](const testing::TestParamInfo<nntrainerModelTest::ParamType> &info) {
-    return std::get<1>(info.param);
-  });
+  [](const testing::TestParamInfo<nntrainerModelTest::ParamType> &info)
+    -> const auto & { return std::get<1>(info.param); });
index 19b835b404c93e33a35c8acb4e5b1b6ce475e4a3..60ffbf7d4fd9c5a6d83923dd26c100c59fd3492b 100644 (file)
@@ -37,7 +37,7 @@ protected:
     name = std::string(std::get<0>(GetParam()));
     std::cout << "starting test case : " << name << std::endl << std::endl;
 
-    auto sections = std::get<1>(GetParam());
+    const auto &sections = std::get<1>(GetParam());
 
     ini = nntrainer::IniWrapper(name, sections);
 
index 18ff8f1a65c662dee29c3d33a7f4bc24c6c7848e..ad7b476bfb56260331a1c933e863d71e2ab09f90 100644 (file)
@@ -54,7 +54,7 @@ protected:
     name = std::string(std::get<0>(GetParam()));
     std::cout << "starting test case : " << name << std::endl << std::endl;
 
-    auto sections = std::get<1>(GetParam());
+    const auto &sections = std::get<1>(GetParam());
 
     ini = nntrainer::IniWrapper(name, sections);