Skip to content

Commit 48f060b

Browse files
Fixed coverity issues (#555)
1 parent 89c100f commit 48f060b

File tree

8 files changed

+33
-14
lines changed

8 files changed

+33
-14
lines changed

onnxruntime/core/providers/openvino/backend_utils.cc

+23-6
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,24 @@ 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+
size_t safe_num_dimensions = num_dimensions;
94+
95+
if(num_dimensions == 0 || safe_num_dimensions > MAX_SAFE_DIMENSIONS) {
96+
ORT_THROW("Invalid number of dimensions provided.");
97+
}
98+
try {
99+
value.dimensions.resize(safe_num_dimensions);
100+
} catch (const std::bad_alloc&) {
101+
ORT_THROW("Error: Memory allocation failed while resizing dimensions.");
102+
}
103+
87104
for (auto& dim : value.dimensions) {
88105
stream >> dim;
89106
}
@@ -235,23 +252,23 @@ int GetFirstAvailableDevice(SessionContext& session_context) {
235252
void FillOutputsWithConstantData(std::shared_ptr<ov::Node> node, Ort::UnownedValue& out_tensor) {
236253
switch (node->get_element_type()) {
237254
case ov::element::Type_t::f32: {
238-
FillOutputHelper<float>(out_tensor, node);
255+
FillOutputHelper<float>(out_tensor, std::move(node));
239256
break;
240257
}
241258
case ov::element::Type_t::boolean: {
242-
FillOutputHelper<char>(out_tensor, node);
259+
FillOutputHelper<char>(out_tensor, std::move(node));
243260
break;
244261
}
245262
case ov::element::Type_t::i32: {
246-
FillOutputHelper<int32_t>(out_tensor, node);
263+
FillOutputHelper<int32_t>(out_tensor, std::move(node));
247264
break;
248265
}
249266
case ov::element::Type_t::i64: {
250-
FillOutputHelper<int64_t>(out_tensor, node);
267+
FillOutputHelper<int64_t>(out_tensor, std::move(node));
251268
break;
252269
}
253270
case ov::element::Type_t::f16: {
254-
FillOutputHelper<float>(out_tensor, node);
271+
FillOutputHelper<float>(out_tensor, std::move(node));
255272
break;
256273
}
257274
default:

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

+2-2
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/onnx_ctx_model_helper.cc

+1-1
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

+1-1
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_provider_factory.cc

+2-2
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ GetCapability::GetCapability(const EPCtxHandler& ep_ctx_handler,
3232
const std::string device_type_param,
3333
const bool enable_qdq_optimizer) : ep_ctx_handler_(ep_ctx_handler),
3434
graph_viewer_(graph_viewer_param),
35-
device_type_(device_type_param) {
35+
device_type_(std::move(device_type_param)) {
3636
bool npu_qdq_optimizer_enabled = false;
3737
if (device_type_.find("NPU") != std::string::npos) {
3838
device_type_ = "CPU";

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

+1-1
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

+2
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)