Skip to content

Commit 2695fc7

Browse files
authored
[CPU] Fix arithmetic related Coverity remarks (#30445)
### Details: Fix Coverity remarks: - 2358662, 2356860: Overflowed constant - 2352647: Macro compares unsigned to 0 - 2356729, 2354785, 2354110: Argument cannot be negative - 2352647: Macro compares unsigned to 0 - 2358684: Division or modulo by zero ### Tickets: - 167163 - 167164
1 parent 5309562 commit 2695fc7

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

src/plugins/intel_cpu/src/dnnl_postops_composer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ DnnlPostOpsComposer::DnnlPostOpsComposer(const PostOps& postOps,
4747
outDataType(outDataType),
4848
useLegacyPostOps(useLegacyPostOps),
4949
useLegacyZeroPoints(useLegacyZeroPoints) {
50-
OPENVINO_ASSERT(idxOC >= 0 && static_cast<size_t>(idxOC) < outputDims.size());
50+
OPENVINO_ASSERT(idxOC < outputDims.size());
5151
OC = outputDims[idxOC];
5252
dimsPerOC = dimsPerTensor = VectorDims(outputDims.size(), 1);
5353
dimsPerOC[idxOC] = OC;

src/plugins/intel_cpu/src/emitters/plugin/x64/jit_emitter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ void jit_emitter::emitter_preamble(const std::vector<size_t>& in_idxs,
173173

174174
if (!entry_map_.empty()) {
175175
// last aux_gpr_idx is for p_table, we can use aux_gpr_idxs from idx 0 for other purpose
176+
OPENVINO_ASSERT(!aux_gpr_idxs.empty(), "No aux gprs available");
176177
p_table = Reg64(aux_gpr_idxs[aux_gprs_count() - 1]);
177178
aux_gpr_idxs.erase(aux_gpr_idxs.end() - 1);
178179
}

src/plugins/intel_cpu/src/graph_optimizer.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ void GraphOptimizer::FuseConvMatmulFCDeconvAndDQScales(Graph& graph) {
246246
auto scaleDimsCheck = [](const NodePtr& node, const NodePtr& scales) {
247247
const auto nodeOutDims = node->getOutputShapeAtPort(0).getDims();
248248
const auto channelAxis = node->getFusingAxis();
249+
OPENVINO_ASSERT(channelAxis >= 0 && channelAxis < static_cast<int>(nodeOutDims.size()),
250+
"Incorrect channel axis for Conv/Deconv/MatMul node: ",
251+
node->getName(),
252+
", channel axis: ",
253+
nodeOutDims.size());
249254
auto OC = nodeOutDims[channelAxis];
250255

251256
if (Shape::UNDEFINED_DIM == OC) {
@@ -363,6 +368,11 @@ void GraphOptimizer::FuseConvolutionMatMulDeconvAndBias(Graph& graph) {
363368
}
364369

365370
const auto channelAxis = parentNode->getFusingAxis();
371+
OPENVINO_ASSERT(channelAxis >= 0 && channelAxis < static_cast<int>(parentOutDims.size()),
372+
"Incorrect channel axis for Conv/Deconv/MatMul node: ",
373+
parentNode->getName(),
374+
", output dims size: ",
375+
parentOutDims.size());
366376
if (!dimsEqualStrong(biasDims[channelAxis], parentOutDims[channelAxis])) {
367377
return false;
368378
}
@@ -2454,6 +2464,11 @@ void GraphOptimizer::FusePerformedAsScaleShiftAndFakeQuantize(Graph& graph) {
24542464
}
24552465
}
24562466

2467+
OPENVINO_ASSERT(channelPos < static_cast<int>(outputDims.size()),
2468+
"Channel position is out of bounds. Channel position: ",
2469+
channelPos,
2470+
", output dims size: ",
2471+
outputDims.size());
24572472
scalesBuffer = makeAlignedBuffer(outputDims[channelPos], scalesBuffer, 1);
24582473
shiftsBuffer = makeAlignedBuffer(outputDims[channelPos], shiftsBuffer, 1);
24592474

src/plugins/intel_cpu/src/nodes/subgraph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ Subgraph::ControlFlowPasses Subgraph::getControlFlowPasses() {
626626

627627
uint32_t Subgraph::getBroadcastingMask(const std::vector<VectorDims>& input_shapes) {
628628
uint32_t mask = 0;
629-
OPENVINO_ASSERT(broadcastable_inputs.size() <= sizeof(mask) * CHAR_BIT,
629+
OPENVINO_ASSERT(broadcastable_inputs.size() < sizeof(mask) * CHAR_BIT,
630630
"Incorrect size of broadcastable inputs of Subgraph");
631631
for (const auto& broadcastable_input : broadcastable_inputs) {
632632
const auto& shape = input_shapes[broadcastable_input.first];

src/plugins/intel_cpu/src/transformations/snippets/x64/pass/lowered/insert_brgemm_copy_buffers.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ bool InsertBrgemmCopyBuffers::run(LinearIR& linear_ir, LinearIR::constExprIt beg
5555
OPENVINO_ASSERT(!ov::snippets::utils::is_dynamic_value(M_blk), "M blk cannot be dynamic!");
5656

5757
const auto vnni_factor = brgemm_utils::compute_vnni_factor(src_dt);
58+
OPENVINO_ASSERT(vnni_factor > 0, "vnni_factor cannot be zero!");
5859
const auto inner_k_blk = brgemm_utils::repacking::compute_inner_k_block(src_dt);
5960
OPENVINO_ASSERT(inner_k_blk > 0, "inner_k_blk cannot be zero!");
6061
const auto tile_scratch_size = BrgemmCPU::SCRATCH_BYTE_SIZE;

0 commit comments

Comments
 (0)