Skip to content

Commit

Permalink
Fix Coverity issues (openvinotoolkit#25494)
Browse files Browse the repository at this point in the history
Fix Coverity issues

Fix the following issues reported by Coverity:
* Overflowed constant
* Explicit null dereferenced
* Dereference null return value
* Using invalid iterator

### Tickets:
- CVS-145094

Signed-off-by: Andrii Staikov <[email protected]>

---------

Signed-off-by: Andrii Staikov <[email protected]>
  • Loading branch information
CuriousPanCake authored Jul 15, 2024
1 parent 29ccd41 commit 6e73933
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/common/low_precision_transformations/src/pad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ bool PadTransformation::canBeTransformed(const TransformationContext& context, s
}
}

if ((beginNonZeroIdx == -1) && (endNonZeroIdx == -1)) {
return true;
}

if ((beginNonZeroIdx != endNonZeroIdx) && (beginNonZeroIdx != -1) && (endNonZeroIdx != -1)) {
return false;
}
Expand Down
12 changes: 7 additions & 5 deletions src/common/snippets/src/lowered/pass/validate_unified_loops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ bool ValidateUnifiedLoops::run(LinearIR& linear_ir) {
// if the loop has different dimension indexes, it don't have to meet the split loop related requirements
if (dim_idx == LoopInfo::UNDEFINED_DIM_IDX)
continue;
if (std::find(dim_indexes.cbegin(), dim_indexes.cend(), dim_idx) != dim_indexes.cend()) {
OPENVINO_ASSERT(*dim_indexes.rbegin() == dim_idx,
"Incorrect Loop ID configuration: the Loops with splitted dimension should be successively nested");
OPENVINO_ASSERT(loop_manager->get_loop_info(loop_ids[i - 1])->get_increment() == loop_manager->get_loop_info(id)->get_work_amount(),
"Incorrect Loop ID configuration: the Loops with splitted dimension should be successively nested");
if (i > 0) {
if (std::find(dim_indexes.cbegin(), dim_indexes.cend(), dim_idx) != dim_indexes.cend()) {
OPENVINO_ASSERT(*dim_indexes.rbegin() == dim_idx,
"Incorrect Loop ID configuration: the Loops with splitted dimension should be successively nested");
OPENVINO_ASSERT(loop_manager->get_loop_info(loop_ids[i - 1])->get_increment() == loop_manager->get_loop_info(id)->get_work_amount(),
"Incorrect Loop ID configuration: the Loops with splitted dimension should be successively nested");
}
}
dim_indexes.push_back(dim_idx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,15 @@ ov::pass::RoPEShareCosSin::RoPEShareCosSin() {
if (!validator) {
return false;
}

auto it = pattern_map.find(const_inv_freq);
if (it == pattern_map.end()) {
return false;
}
auto cur_inv_freq = std::dynamic_pointer_cast<opset1::Constant>(it->second.get_node_shared_ptr());
if (!cur_inv_freq) {
return false;
}

// the first match is the one to be shared, collect all inputs
// and constants into the state capture by lambda
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ ov::pass::LSTMCellFusionWithJointWeights::LSTMCellFusionWithJointWeights() {

std::string f_activation_name = ft->get_type_name();

if (f_activation_name != it->get_type_name() || f_activation_name != ot->get_type_name())
if (!it || f_activation_name != it->get_type_name() || !ot || f_activation_name != ot->get_type_name())
return false;

f_activation_name[0] = std::tolower(f_activation_name[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,9 @@ ov::pass::EliminateSlice::EliminateSlice() {

ov::matcher_pass_callback matcher_pass_callback = [=](pattern::Matcher& m) {
auto slice = std::dynamic_pointer_cast<ov::op::v8::Slice>(m.get_match_root());
if (!slice) {
return false;
}

int64_t max_int = slice->input_value(2).get_element_type() == element::i32
? std::numeric_limits<int32_t>::max()
Expand Down Expand Up @@ -891,11 +894,10 @@ ov::pass::EliminateStridedSlice::EliminateStridedSlice() {
auto pattern = pattern::wrap_type<ov::op::v1::StridedSlice>({input, begin_const, end_const, optional_stride_const});

ov::matcher_pass_callback matcher_pass_callback = [=](pattern::Matcher& m) {
auto node = m.get_match_root();
if (node == nullptr) {
auto strided_slice_node = std::dynamic_pointer_cast<ov::op::v1::StridedSlice>(m.get_match_root());
if (!strided_slice_node) {
return false;
}
auto strided_slice_node = std::dynamic_pointer_cast<ov::op::v1::StridedSlice>(node);
// check that all values of the mask is equal 0
auto check_mask = [](const std::vector<int64_t>& mask_to_check) {
auto it = std::find_if(mask_to_check.begin(), mask_to_check.end(), [](const int64_t& value) {
Expand All @@ -913,7 +915,8 @@ ov::pass::EliminateStridedSlice::EliminateStridedSlice() {
return false;
}
// check that that we will take all values
if (node->get_input_size() == 4 && !op::util::is_constant_and_all_values_equal_int(node->input_value(3), 1)) {
if (strided_slice_node->get_input_size() == 4 &&
!op::util::is_constant_and_all_values_equal_int(strided_slice_node->input_value(3), 1)) {
return false;
}

Expand Down

0 comments on commit 6e73933

Please sign in to comment.