Skip to content

Commit 0b65389

Browse files
Fixed coverity issues
1 parent f5c980b commit 0b65389

File tree

10 files changed

+38
-21
lines changed

10 files changed

+38
-21
lines changed

onnxruntime/core/providers/openvino/backend_utils.cc

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,22 @@ std::istream& operator>>(std::istream& stream, SharedContext::SharedWeights::Met
8383
stream >> value.size;
8484
size_t num_dimensions;
8585
stream >> num_dimensions;
86-
value.dimensions.resize(num_dimensions);
86+
87+
if (stream.fail()) {
88+
ORT_THROW("Error: Failed to read num_dimensions from stream.");
89+
}
90+
91+
constexpr size_t MAX_SAFE_DIMENSIONS = 1024;
92+
93+
if (num_dimensions == 0 || num_dimensions > MAX_SAFE_DIMENSIONS) {
94+
ORT_THROW("Invalid number of dimensions: " + std::to_string(num_dimensions));
95+
}
96+
try {
97+
value.dimensions.resize(num_dimensions);
98+
} catch (const std::bad_alloc&) {
99+
ORT_THROW("Error: Memory allocation failed while resizing dimensions.");
100+
}
101+
87102
for (auto& dim : value.dimensions) {
88103
stream >> dim;
89104
}
@@ -235,23 +250,23 @@ int GetFirstAvailableDevice(SessionContext& session_context) {
235250
void FillOutputsWithConstantData(std::shared_ptr<ov::Node> node, Ort::UnownedValue& out_tensor) {
236251
switch (node->get_element_type()) {
237252
case ov::element::Type_t::f32: {
238-
FillOutputHelper<float>(out_tensor, node);
253+
FillOutputHelper<float>(out_tensor, std::move(node));
239254
break;
240255
}
241256
case ov::element::Type_t::boolean: {
242-
FillOutputHelper<char>(out_tensor, node);
257+
FillOutputHelper<char>(out_tensor, std::move(node));
243258
break;
244259
}
245260
case ov::element::Type_t::i32: {
246-
FillOutputHelper<int32_t>(out_tensor, node);
261+
FillOutputHelper<int32_t>(out_tensor, std::move(node));
247262
break;
248263
}
249264
case ov::element::Type_t::i64: {
250-
FillOutputHelper<int64_t>(out_tensor, node);
265+
FillOutputHelper<int64_t>(out_tensor, std::move(node));
251266
break;
252267
}
253268
case ov::element::Type_t::f16: {
254-
FillOutputHelper<float>(out_tensor, node);
269+
FillOutputHelper<float>(out_tensor, std::move(node));
255270
break;
256271
}
257272
default:

onnxruntime/core/providers/openvino/backends/basic_backend.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ BasicBackend::BasicBackend(std::unique_ptr<ONNX_NAMESPACE::ModelProto>& model_pr
114114
if (!subgraph_context.has_dynamic_input_shape) {
115115
delete model_proto.release();
116116
}
117-
ov_model = CreateOVModel(model, session_context_, const_outputs_map_);
117+
ov_model = CreateOVModel(std::move(model), session_context_, const_outputs_map_);
118118
}
119119
exe_network_ = OVCore::CompileModel(
120120
ov_model, hw_target, device_config, subgraph_context_.subgraph_name);
@@ -141,7 +141,7 @@ BasicBackend::BasicBackend(std::unique_ptr<ONNX_NAMESPACE::ModelProto>& model_pr
141141
}
142142
};
143143
}
144-
inferRequestsQueue_ = std::unique_ptr<InferRequestsQueue>(new InferRequestsQueue(exe_network_, num_infer_req, initializer));
144+
inferRequestsQueue_ = std::unique_ptr<InferRequestsQueue>(new InferRequestsQueue(exe_network_, num_infer_req, std::move(initializer)));
145145
}
146146

147147
bool BasicBackend::ValidateSubgraph(std::map<std::string, std::shared_ptr<ov::Node>>& const_outputs_map) {

onnxruntime/core/providers/openvino/contexts.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ struct SessionContext : ProviderInfo {
104104
std::vector<bool> deviceAvailableList = {true, true, true, true, true, true, true, true};
105105
std::filesystem::path onnx_model_path_name;
106106
uint32_t onnx_opset_version{0};
107-
mutable bool is_wholly_supported_graph = false; //Value is set to mutable to modify from capability
108-
mutable bool has_external_weights = false; //Value is set to mutable to modify from capability
107+
mutable bool is_wholly_supported_graph = false; // Value is set to mutable to modify from capability
108+
mutable bool has_external_weights = false; // Value is set to mutable to modify from capability
109109
const std::vector<uint32_t> OpenVINO_Version = {OPENVINO_VERSION_MAJOR, OPENVINO_VERSION_MINOR};
110110
const std::string openvino_sdk_version = std::to_string(OPENVINO_VERSION_MAJOR) + "." + std::to_string(OPENVINO_VERSION_MINOR);
111111
};

onnxruntime/core/providers/openvino/onnx_ctx_model_helper.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace onnxruntime {
1212
namespace openvino_ep {
1313

14-
EPCtxHandler::EPCtxHandler(std::string ov_sdk_version, const logging::Logger& logger) : openvino_sdk_version_(ov_sdk_version), logger_(logger) {
14+
EPCtxHandler::EPCtxHandler(std::string ov_sdk_version, const logging::Logger& logger) : openvino_sdk_version_(std::move(ov_sdk_version)), logger_(logger) {
1515
epctx_model_ = Model::Create("ovep_context_model", false, logger_);
1616
}
1717

onnxruntime/core/providers/openvino/openvino_execution_provider.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ common::Status OpenVINOExecutionProvider::Compile(
257257
}
258258
};
259259

260-
node_compute_funcs.push_back(compute_info);
260+
node_compute_funcs.push_back(std::move(compute_info));
261261

262262
if (!status.IsOK()) {
263263
break;

onnxruntime/core/providers/openvino/openvino_execution_provider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class OpenVINOExecutionProvider : public IExecutionProvider {
5050

5151
std::vector<std::unique_ptr<ComputeCapability>>
5252
GetCapability(const GraphViewer& graph_viewer,
53-
const IKernelLookup& /*kernel_lookup*/) const override ;
53+
const IKernelLookup& /*kernel_lookup*/) const override;
5454

5555
Status Compile(const std::vector<FusedNodeAndGraph>& fused_nodes,
5656
std::vector<NodeComputeInfo>& node_compute_funcs) override;

onnxruntime/core/providers/openvino/openvino_provider_factory.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void ParseProviderOptions([[maybe_unused]] ProviderInfo& result, [[maybe_unused]
160160

161161
struct OpenVINOProviderFactory : IExecutionProviderFactory {
162162
OpenVINOProviderFactory(ProviderInfo provider_info, SharedContext& shared_context)
163-
: provider_info_(provider_info), shared_context_(shared_context) {}
163+
: provider_info_(std::move(provider_info)), shared_context_(shared_context) {}
164164

165165
~OpenVINOProviderFactory() override {}
166166

@@ -333,7 +333,7 @@ struct OpenVINO_Provider : Provider {
333333
if (pi.so_share_ep_contexts) {
334334
ov::AnyMap map;
335335
map["NPU_COMPILATION_MODE_PARAMS"] = "enable-wd-blockarg-input=true compute-layers-with-higher-precision=Sqrt,Power,ReduceSum";
336-
pi.load_config["NPU"] = map;
336+
pi.load_config["NPU"] = std::move(map);
337337
}
338338

339339
return std::make_shared<OpenVINOProviderFactory>(pi, shared_context_);

onnxruntime/core/providers/openvino/ov_versions/capability.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <map>
44
#include <unordered_set>
55
#include <type_traits>
6+
#include <utility>
67

78
#include "core/providers/shared_library/provider_api.h"
89
#include "core/providers/openvino/backend_utils.h"
@@ -32,7 +33,7 @@ GetCapability::GetCapability(const EPCtxHandler& ep_ctx_handler,
3233
const std::string device_type_param,
3334
const bool enable_qdq_optimizer) : ep_ctx_handler_(ep_ctx_handler),
3435
graph_viewer_(graph_viewer_param),
35-
device_type_(device_type_param) {
36+
device_type_(std::move(device_type_param)) {
3637
bool npu_qdq_optimizer_enabled = false;
3738
if (device_type_.find("NPU") != std::string::npos) {
3839
device_type_ = "CPU";
@@ -170,15 +171,14 @@ std::vector<std::unique_ptr<ComputeCapability>> GetCapability::Execute() {
170171
int no_of_clusters = 0;
171172

172173
for (auto this_cluster : connected_clusters) {
173-
174174
// If subgraph has less then three, graph is considered trivial unless its an epctx cluster
175175
if (this_cluster.size() < 3) {
176176
bool is_epctx_node = false;
177-
for(auto node_idx:this_cluster){
178-
if(graph_viewer_.GetNode(node_idx)->OpType() == "EPContext")
177+
for (auto node_idx : this_cluster) {
178+
if (graph_viewer_.GetNode(node_idx)->OpType() == "EPContext")
179179
is_epctx_node = true;
180180
}
181-
if(!is_epctx_node)
181+
if (!is_epctx_node)
182182
continue;
183183
}
184184

onnxruntime/core/providers/openvino/ov_versions/data_ops.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class DataOps {
8484
const std::string dev_id, const bool npu_qdq_optimizer_enabled)
8585
: graph_viewer_(graph_viewer_param),
8686
version_id_(ver),
87-
device_id_(dev_id),
87+
device_id_(std::move(dev_id)),
8888
npu_qdq_optimizer_enabled_(npu_qdq_optimizer_enabled) {
8989
populate_op_mode_supported();
9090
populate_types_supported();

onnxruntime/core/providers/openvino/qdq_transformations/qdq_stripping.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,8 @@ Status CreateModelWithStrippedQDQNodes(const GraphViewer& src_graph,
712712
// Will set inputs after deciding fate oif all internal and external initializers
713713
// accumulated_inputs container will store input of the original graph and initializer with ext data
714714
InlinedVector<const NodeArg*> accumulated_inputs;
715+
accumulated_inputs.reserve(dst_graph_inputs.size());
716+
715717
// dst_graph.SetInputs(dst_graph_inputs);
716718
dst_graph.SetOutputs(dst_graph_outputs);
717719

0 commit comments

Comments
 (0)