[coverity] fix coverity issues
authorhyeonseok lee <hs89.lee@samsung.com>
Mon, 25 Mar 2024 10:40:50 +0000 (19:40 +0900)
committerjijoong.moon <jijoong.moon@samsung.com>
Thu, 28 Mar 2024 23:45:26 +0000 (08:45 +0900)
 - Added const auto & to avoid copy of an object
 - Added missing lock

Signed-off-by: hyeonseok lee <hs89.lee@samsung.com>
nntrainer/dataset/iteration_queue.cpp
test/unittest/models/models_test_utils.cpp

index b5fbc6c..b200ac0 100644 (file)
@@ -170,9 +170,10 @@ IterationQueue::MarkableIteration::MarkableIteration(
   num_observed(0), iteration(input_dims, label_dims), iq(iq) {}
 
 IterationQueue::MarkableIteration::MarkableIteration(MarkableIteration &&rhs) :
-  num_observed(rhs.num_observed),
-  iteration(std::move(rhs.iteration)),
-  iq(rhs.iq) {}
+  iteration(std::move(rhs.iteration)), iq(rhs.iq) {
+  std::lock_guard notify_lock_guard(notify_mutex);
+  num_observed = rhs.num_observed;
+}
 
 void IterationQueue::MarkableIteration::reset() {
   std::lock_guard notify_lock_guard(notify_mutex);
index 7534676..741e008 100644 (file)
@@ -142,8 +142,9 @@ public:
     auto to_tensors = [](sharedConstTensors &sts) {
       std::vector<Tensor> ts;
       ts.reserve(sts.size());
-      std::transform(sts.begin(), sts.end(), std::back_inserter(ts),
-                     [](const auto &ts) { return *ts; });
+      std::transform(
+        sts.begin(), sts.end(), std::back_inserter(ts),
+        [](const auto &ts) -> const auto & { return *ts; });
       return ts;
     };
 
@@ -303,17 +304,14 @@ void NodeWatcher::backward(int iteration, bool verify_deriv, bool verify_grad) {
 }
 
 GraphWatcher::GraphWatcher(const std::string &config, const bool opt) :
-  nn(new nntrainer::NeuralNetwork()),
-  expected_losses{},
-  optimize(opt) {
+  nn(new nntrainer::NeuralNetwork()), expected_losses{}, optimize(opt) {
   nn->loadFromConfig(config);
   initialize();
 }
 
 GraphWatcher::GraphWatcher(std::unique_ptr<nntrainer::NeuralNetwork> &&net,
                            const bool opt) :
-  nn(std::move(net)),
-  optimize(opt) {
+  nn(std::move(net)), optimize(opt) {
   initialize();
 }