From 0a8fb52d3ec2f0b1cee14ea7b5858b8ce3703293 Mon Sep 17 00:00:00 2001 From: Donghyeon Jeong Date: Wed, 31 Jan 2024 15:28:38 +0900 Subject: [PATCH] [coverity] Fix coverity issues This PR resolves the coverity issues that were identified. **Changes proposed in this PR:** - Specify the return type of the lambda function - Use reference to not copy the object. This fixes: - Use of auto that causes a copy (AUTO_CAUSES_COPY) **Self-evaluation:** 1. Build test: [X]Passed [ ]Failed [ ]Skipped 2. Run test: [X]Passed [ ]Failed [ ]Skipped Signed-off-by: Donghyeon Jeong --- nntrainer/layers/layer_context.h | 2 +- nntrainer/layers/layer_node.cpp | 10 ++++++---- nntrainer/models/neuralnet.cpp | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/nntrainer/layers/layer_context.h b/nntrainer/layers/layer_context.h index 02dc08e..f86491e 100644 --- a/nntrainer/layers/layer_context.h +++ b/nntrainer/layers/layer_context.h @@ -217,7 +217,7 @@ public: bool trainable = false, TensorLifespan lifespan = TensorLifespan::ITERATION_LIFESPAN, bool private_ = true) { - auto prefix_ = private_ ? this->name : this->prefix; + const auto &prefix_ = private_ ? this->name : this->prefix; tensors_spec.emplace_back(dim, init, trainable, prefix_ + ":" + name, lifespan); return tensors_spec.size() - 1; diff --git a/nntrainer/layers/layer_node.cpp b/nntrainer/layers/layer_node.cpp index cedb3ca..937ee43 100644 --- a/nntrainer/layers/layer_node.cpp +++ b/nntrainer/layers/layer_node.cpp @@ -305,9 +305,11 @@ const std::vector LayerNode::getInputLayers() const { std::get>(*layer_node_props); std::vector names; names.reserve(input_connections.size()); - std::transform(input_connections.begin(), input_connections.end(), - std::back_inserter(names), - [](const Connection &con) { return con.getName(); }); + std::transform( + input_connections.begin(), input_connections.end(), + std::back_inserter(names), [](const Connection &con) -> const auto & { + return con.getName(); + }); return names; } @@ -572,7 +574,7 @@ LayerNode::finalize(const std::vector &input_dims, layer = std::move(dlayer); } - auto scope = getSharedFrom().empty() ? getName() : getSharedFrom(); + const auto &scope = getSharedFrom().empty() ? getName() : getSharedFrom(); float max_norm = 0.0; if (!std::get(*layer_node_props).empty()) max_norm = std::get(*layer_node_props).get(); diff --git a/nntrainer/models/neuralnet.cpp b/nntrainer/models/neuralnet.cpp index 5b1cccc..9223c4a 100644 --- a/nntrainer/models/neuralnet.cpp +++ b/nntrainer/models/neuralnet.cpp @@ -1203,7 +1203,8 @@ void NeuralNetwork::print(std::ostream &out, unsigned int flags, std::vector column_size = {20, 20, 20, 20}; auto print_graph_layer_info = [column_size](std::ostream &out, std::vector layer_info) { - auto trim_string = [](std::string str, unsigned int column_width) { + const auto &trim_string = [](std::string str, + unsigned int column_width) { return str.size() < column_width ? str : str.substr(0, column_width - 1); }; -- 2.7.4