Skip to content

Commit ef9c8d9

Browse files
praaszt-jankowskimitruska
authored
[core] Fix issue reported by Coverity in core sub-component (#30753)
### Details: - Fix most of issue in core component ### Tickets: - CVS-167271 --------- Signed-off-by: Pawel Raasz <[email protected]> Co-authored-by: Tomasz Jankowski <[email protected]> Co-authored-by: Katarzyna Mitrus <[email protected]>
1 parent 51b00a6 commit ef9c8d9

40 files changed

+176
-184
lines changed

src/core/include/openvino/core/descriptor/input.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class OPENVINO_API Input {
104104
Input(const Input&) = default;
105105
Input(Input&&) = default;
106106
Input& operator=(const Input&) = default;
107+
Input& operator=(Input&&) = default;
107108

108109
protected:
109110
// owner of an argument node (in lieu of m_arguments)

src/core/include/openvino/core/enum_names.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class EnumNames {
4848
/// Creates the mapping.
4949
EnumNames(const std::string& enum_name, const std::vector<std::pair<std::string, EnumType>> string_enums)
5050
: m_enum_name(enum_name),
51-
m_string_enums(string_enums) {}
51+
m_string_enums(std::move(string_enums)) {}
5252

5353
/// Must be defined to returns a singleton for each supported enum class
5454
static EnumNames<EnumType>& get();

src/core/include/openvino/core/type.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ is_type(Value value) {
9898
}
9999

100100
/// \brief Tests if value is a pointer/shared_ptr that can be statically cast to any of the specified types
101-
template <typename Type, typename... Types, typename Value>
102-
bool is_type_any_of(Value value) {
103-
return is_type<Type>(value) || (is_type_any_of<Types>(value) || ...);
101+
template <typename... Types, typename Value>
102+
bool is_type_any_of(Value&& value) {
103+
return (is_type<Types>(std::forward<Value>(value)) || ...);
104104
}
105105

106106
/// Casts a Value* to a Type* if it is of type Type, nullptr otherwise

src/core/include/openvino/op/interpolate.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class OPENVINO_API Interpolate : public Op {
6363
return m_attrs;
6464
}
6565

66-
void set_attrs(Attributes attrs);
66+
void set_attrs(Attributes&& attrs);
67+
void set_attrs(const Attributes& attrs);
6768

6869
private:
6970
Attributes m_attrs;

src/core/include/openvino/op/prior_box.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class OPENVINO_API PriorBox : public Op {
5656
const Attributes& get_attrs() const {
5757
return m_attrs;
5858
}
59-
void set_attrs(Attributes attrs);
59+
void set_attrs(Attributes&& attrs);
60+
void set_attrs(const Attributes& attrs);
6061

6162
bool visit_attributes(AttributeVisitor& visitor) override;
6263
bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override;
@@ -117,7 +118,8 @@ class OPENVINO_API PriorBox : public Op {
117118
const Attributes& get_attrs() const {
118119
return m_attrs;
119120
}
120-
void set_attrs(Attributes attrs);
121+
void set_attrs(Attributes&& attrs);
122+
void set_attrs(const Attributes& attrs);
121123

122124
bool visit_attributes(AttributeVisitor& visitor) override;
123125
bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override;

src/core/include/openvino/op/proposal.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ class OPENVINO_API Proposal : public Op {
6868
/**
6969
* @brief Set the Proposal operator attributes.
7070
* @param attrs Attributes to be set.
71+
* @{
7172
*/
72-
void set_attrs(Attributes attrs);
73+
void set_attrs(Attributes&& attrs);
74+
void set_attrs(const Attributes& attrs);
75+
/** @} */
7376

7477
bool visit_attributes(AttributeVisitor& visitor) override;
7578

src/core/include/openvino/pass/manager.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ class OPENVINO_API Manager {
9090
std::shared_ptr<T> push_pass(Args&&... args) {
9191
static_assert(std::is_base_of<pass::PassBase, T>::value, "pass not derived from pass base");
9292
auto pass = std::make_shared<T>(std::forward<Args>(args)...);
93-
auto pass_base = std::static_pointer_cast<PassBase>(pass);
94-
m_pass_list.push_back(pass_base);
93+
m_pass_list.push_back(pass);
9594
return pass;
9695
}
9796

src/core/reference/include/openvino/reference/reduce_mean.hpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
#include "openvino/core/shape_util.hpp"
1111
#include "openvino/reference/reduce_sum.hpp"
1212

13-
namespace ov {
14-
namespace reference {
13+
namespace ov::reference {
1514

1615
/**
1716
* @brief Reference implementation of ReduceMean operator.
@@ -25,16 +24,13 @@ template <class T>
2524
void reduce_mean(const T* in, T* out, const Shape& in_shape, const AxisSet& reduction_axes) {
2625
reduce_sum(in, out, in_shape, reduction_axes);
2726

28-
const auto out_shape = util::reduce(in_shape, reduction_axes);
29-
if (shape_size(in_shape) == 0) {
30-
return;
27+
if (const auto input_size = shape_size(in_shape); input_size != 0) {
28+
const auto out_shape = util::reduce(in_shape, reduction_axes);
29+
const auto out_size = shape_size(out_shape);
30+
const auto count = input_size / out_size;
31+
std::transform(out, std::next(out, out_size), out, [count = static_cast<T>(count)](auto&& value) -> T {
32+
return value / count;
33+
});
3134
}
32-
33-
const auto out_size = shape_size(out_shape);
34-
const auto count = static_cast<T>(shape_size(in_shape) / out_size);
35-
std::transform(out, std::next(out, out_size), out, [count](const T value) {
36-
return value / count;
37-
});
3835
}
39-
} // namespace reference
40-
} // namespace ov
36+
} // namespace ov::reference

src/core/reference/include/openvino/reference/rounding_guard.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class RoundingGuard {
2323
RoundingGuard(int mode);
2424
~RoundingGuard();
2525

26+
RoundingGuard(const RoundingGuard&) = delete;
27+
RoundingGuard& operator=(const RoundingGuard&) = delete;
28+
2629
private:
2730
int m_prev_round_mode;
2831
};

src/core/reference/include/openvino/reference/scatter_elements_update.hpp

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
#include <cfenv>
88
#include <cstring>
99
#include <iterator>
10+
#include <optional>
1011

1112
#include "openvino/core/except.hpp"
1213
#include "openvino/core/shape.hpp"
1314
#include "openvino/op/scatter_elements_update.hpp"
15+
#include "openvino/reference/rounding_guard.hpp"
1416
#include "openvino/reference/utils/coordinate_index.hpp"
1517
#include "openvino/reference/utils/coordinate_transform.hpp"
1618

@@ -133,25 +135,6 @@ typename std::enable_if<std::is_integral<T>::value, T>::type arithmetic_mean(con
133135
return value;
134136
}
135137

136-
template <typename T>
137-
struct RoundingDirectionGuard {
138-
RoundingDirectionGuard() {
139-
if (std::is_integral<T>::value) {
140-
m_original_mode = std::fegetround();
141-
std::fesetround(FE_DOWNWARD);
142-
}
143-
}
144-
145-
~RoundingDirectionGuard() {
146-
if (std::is_integral<T>::value) {
147-
std::fesetround(m_original_mode);
148-
}
149-
}
150-
151-
private:
152-
decltype(std::fegetround()) m_original_mode;
153-
};
154-
155138
template <typename DataType>
156139
void scatter_elem_update_with_reduction(const int64_t* indices,
157140
const DataType* updates,
@@ -210,11 +193,14 @@ void scatter_elem_update_with_reduction(const int64_t* indices,
210193
if (reduction_type == ov::op::v12::ScatterElementsUpdate::Reduction::MEAN) {
211194
// this object will change the rounding mode only for integer types which is required to match torch
212195
// upon destruction the previously used rounding mode will be restored
213-
RoundingDirectionGuard<DataType> rounding_guard;
214-
for (const auto& counter : mean_reduction_counters) {
196+
std::optional<RoundingGuard> r_guard;
197+
if constexpr (std::is_integral_v<DataType>) {
198+
r_guard.emplace(FE_DOWNWARD);
199+
}
200+
for (const auto& [idx, count] : mean_reduction_counters) {
215201
// include the initial value in the arithmetic mean divisor (if needed)
216-
const auto N = counter.second + static_cast<int32_t>(use_init_val);
217-
out_buf[counter.first] = arithmetic_mean<DataType>(out_buf[counter.first], N);
202+
const auto N = count + static_cast<int32_t>(use_init_val);
203+
out_buf[idx] = arithmetic_mean<DataType>(out_buf[idx], N);
218204
}
219205
}
220206
}

0 commit comments

Comments
 (0)