Skip to content

Commit baf396c

Browse files
committed
[coverity] fix coverity issues
- Added const auto & to avoid copy of an object - Added missing lock Signed-off-by: hyeonseok lee <hs89.lee@samsung.com>
1 parent c625cdc commit baf396c

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

nntrainer/dataset/iteration_queue.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,17 @@ ScopedView<Sample> IterationQueue::requestEmptySlot() {
7676
current_iterator++;
7777
}
7878

79-
auto view =
80-
ScopedView<Sample>(&(*current_iterator),
81-
[current_being_filed = this->being_filled] {
82-
current_being_filed->markSampleFilled();
83-
},
84-
[this, current_being_filled = this->being_filled] {
85-
std::unique_lock lg(empty_mutex);
86-
this->markEmpty(current_being_filled);
87-
num_being_filled--;
88-
notify_emptied_cv.notify_all();
89-
});
79+
auto view = ScopedView<Sample>(
80+
&(*current_iterator),
81+
[current_being_filed = this->being_filled] {
82+
current_being_filed->markSampleFilled();
83+
},
84+
[this, current_being_filled = this->being_filled] {
85+
std::unique_lock lg(empty_mutex);
86+
this->markEmpty(current_being_filled);
87+
num_being_filled--;
88+
notify_emptied_cv.notify_all();
89+
});
9090
return view;
9191
}
9292

@@ -168,23 +168,22 @@ void IterationQueue::markEmpty(MarkableIteration *iteration) {
168168
IterationQueue::MarkableIteration::MarkableIteration(
169169
const std::vector<ml::train::TensorDim> &input_dims,
170170
const std::vector<ml::train::TensorDim> &label_dims, IterationQueue *iq) :
171-
num_observed(0),
172-
iteration(input_dims, label_dims),
173-
iq(iq) {}
171+
num_observed(0), iteration(input_dims, label_dims), iq(iq) {}
174172

175173
IterationQueue::MarkableIteration::MarkableIteration(MarkableIteration &&rhs) :
176-
num_observed(rhs.num_observed),
177-
iteration(std::move(rhs.iteration)),
178-
iq(rhs.iq) {}
174+
iteration(std::move(rhs.iteration)), iq(rhs.iq) {
175+
std::lock_guard notify_lock_guard(notify_mutex);
176+
num_observed = rhs.num_observed;
177+
}
179178

180179
void IterationQueue::MarkableIteration::reset() {
181180
std::lock_guard notify_lock_guard(notify_mutex);
182181
num_observed = 0;
183182
iteration.setEndSample();
184183
}
185184

186-
IterationQueue::MarkableIteration &IterationQueue::MarkableIteration::
187-
operator=(MarkableIteration &&rhs) {
185+
IterationQueue::MarkableIteration &
186+
IterationQueue::MarkableIteration::operator=(MarkableIteration &&rhs) {
188187
if (this == &rhs) {
189188
return *this;
190189
}

test/unittest/models/models_test_utils.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ class IterationForGolden {
142142
auto to_tensors = [](sharedConstTensors &sts) {
143143
std::vector<Tensor> ts;
144144
ts.reserve(sts.size());
145-
std::transform(sts.begin(), sts.end(), std::back_inserter(ts),
146-
[](const auto &ts) { return *ts; });
145+
std::transform(
146+
sts.begin(), sts.end(), std::back_inserter(ts),
147+
[](const auto &ts) -> const auto & { return *ts; });
147148
return ts;
148149
};
149150

@@ -303,17 +304,14 @@ void NodeWatcher::backward(int iteration, bool verify_deriv, bool verify_grad) {
303304
}
304305

305306
GraphWatcher::GraphWatcher(const std::string &config, const bool opt) :
306-
nn(new nntrainer::NeuralNetwork()),
307-
expected_losses{},
308-
optimize(opt) {
307+
nn(new nntrainer::NeuralNetwork()), expected_losses{}, optimize(opt) {
309308
nn->loadFromConfig(config);
310309
initialize();
311310
}
312311

313312
GraphWatcher::GraphWatcher(std::unique_ptr<nntrainer::NeuralNetwork> &&net,
314313
const bool opt) :
315-
nn(std::move(net)),
316-
optimize(opt) {
314+
nn(std::move(net)), optimize(opt) {
317315
initialize();
318316
}
319317

0 commit comments

Comments
 (0)