Skip to content

Commit 3e2454d

Browse files
committed
more coverity fixes
1 parent 3dfaf30 commit 3e2454d

10 files changed

Lines changed: 18 additions & 9 deletions

doc/modules/ROOT/examples/accept_no_visitors.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct Plus : Node {
2525
Plus(
2626
shared_virtual_ptr<const Node> left,
2727
shared_virtual_ptr<const Node> right)
28-
: left(left), right(right) {
28+
: left(std::move(left)), right(std::move(right)) {
2929
}
3030

3131
shared_virtual_ptr<const Node> left, right;
@@ -35,7 +35,7 @@ struct Times : Node {
3535
Times(
3636
shared_virtual_ptr<const Node> left,
3737
shared_virtual_ptr<const Node> right)
38-
: left(left), right(right) {
38+
: left(std::move(left)), right(std::move(right)) {
3939
}
4040

4141
shared_virtual_ptr<const Node> left, right;

include/boost/openmethod/core.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ struct use_class_aux<Registry, mp11::mp_list<Class, Bases...>>
359359
resolve_type_ids();
360360
}
361361

362+
// coverity[uninit] - zero-initialized static storage
362363
Registry::classes.push_back(*this);
363364
}
364365

@@ -2403,6 +2404,8 @@ method<Id, ReturnType(Parameters...), Registry>::method() {
24032404
this->not_implemented = reinterpret_cast<void (*)()>(fn_not_implemented);
24042405
this->ambiguous = reinterpret_cast<void (*)()>(fn_ambiguous);
24052406

2407+
// zero-initalized static variable
2408+
// coverity[uninit_use]
24062409
Registry::methods.push_back(*this);
24072410
}
24082411

include/boost/openmethod/interop/std_unique_ptr.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ struct virtual_traits<std::unique_ptr<Class>, Registry> {
4343
if constexpr (detail::requires_dynamic_cast<Class&, Derived&>) {
4444
auto p = &Registry::rtti::template dynamic_cast_ref<
4545
typename Derived::element_type&>(*ptr);
46+
// coverity[alloc_fn]
4647
ptr.release();
4748
return Derived(p);
4849
} else {
4950
auto p = &static_cast<typename Derived::element_type&>(*ptr);
51+
// coverity[alloc_fn]
5052
ptr.release();
5153
return Derived(p);
5254
}

include/boost/openmethod/policies/default_error_handler.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,9 @@ struct default_error_handler : error_handler {
9494
//!
9595
//! @param new_handler the new function.
9696
//! @return The previous function.
97+
// coverity[auto_causes_copy]
9798
static auto set(function_type new_handler) -> function_type {
98-
auto prev = handler;
99-
handler = std::move(new_handler);
100-
101-
return prev;
99+
return std::exchange(handler, std::move(new_handler));
102100
}
103101

104102
//! The default error handler function.

test/test_compiler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ template<typename... Ts>
4747
auto sstr(Ts... args) {
4848
std::vector<class_*> vec{args...};
4949
std::sort(vec.begin(), vec.end());
50+
5051
return str(vec);
5152
}
5253

test/test_dispatch_intrusive_ptr.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ BOOST_AUTO_TEST_CASE(intrusive_virtual_ptr_by_value) {
136136
}
137137
} // namespace BOOST_OPENMETHOD_GENSYM
138138

139-
140139
namespace BOOST_OPENMETHOD_GENSYM {
141140

142141
// -----------------------------------------------------------------------------

test/test_shared_virtual_ptr_value_semantics.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(
194194
shared_virtual_ptr<Dog, Registry> q(std::move(p));
195195
BOOST_TEST(q.get() == snoopy.get());
196196
BOOST_TEST(q.vptr() == Registry::template static_vptr<Dog>);
197+
// coverity[use_after_move]
197198
BOOST_TEST(p.get() == nullptr);
198199
BOOST_TEST(p.vptr() == nullptr);
199200
}

test/test_smart_virtual_ptr_value_semantics.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(
259259
dog_virtual_ptr q(std::move(p));
260260
BOOST_TEST(q.get() == snoopy.get());
261261
BOOST_TEST(q.vptr() == default_registry::template static_vptr<Dog>);
262+
// coverity[use_after_move]
262263
BOOST_TEST(p.get() == nullptr);
263264
BOOST_TEST(p.vptr() == nullptr);
264265
}
@@ -385,6 +386,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(
385386
BOOST_TEST(dog.get() == p);
386387

387388
if (smart::cast_moves()) {
389+
// coverity[use_after_move]
388390
BOOST_TEST(animal.get() == nullptr);
389391
}
390392
}

test/test_static_list.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ BOOST_AUTO_TEST_CASE(test_list) {
101101
}
102102

103103
struct static_value : static_list<static_value>::static_link {
104+
// coverity[uninit_in_ctor]
105+
// coverity[uninit_use_in_call]
104106
explicit static_value(static_list<static_value>& reg) {
105107
reg.push_back(*this);
106108
}

test/test_unique_virtual_ptr_value_semantics.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(
116116
unique_virtual_ptr<Dog, Registry> p(std::make_unique<Dog>());
117117
auto dog = p.get();
118118
unique_virtual_ptr<Dog, Registry> q(std::move(p));
119-
// coverity[use_after_move]
120119
BOOST_TEST(q.get() == dog);
121120
BOOST_TEST(q.vptr() == Registry::template static_vptr<Dog>);
121+
// coverity[use_after_move]
122122
BOOST_TEST(p.get() == nullptr);
123123
BOOST_TEST(p.vptr() == nullptr);
124124
}
@@ -128,9 +128,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(
128128
unique_virtual_ptr<Dog, Registry> p(std::make_unique<Dog>());
129129
auto dog = p.get();
130130
unique_virtual_ptr<Animal, Registry> q(std::move(p));
131-
// coverity[use_after_move]
132131
BOOST_TEST(q.get() == dog);
133132
BOOST_TEST(q.vptr() == Registry::template static_vptr<Dog>);
133+
// coverity[use_after_move]
134134
BOOST_TEST(p.get() == nullptr);
135135
BOOST_TEST(p.vptr() == nullptr);
136136
}
@@ -271,6 +271,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(
271271
unique_virtual_ptr<Class>>(std::move(base));
272272
BOOST_TEST(derived.get() == p);
273273
BOOST_TEST(derived.vptr() == default_registry::static_vptr<Class>);
274+
// coverity[use_after_move]
274275
BOOST_TEST(base.get() == nullptr);
275276
}
276277

0 commit comments

Comments
 (0)