all: improve C++ static analyzers

This commit is contained in:
Markus F.X.J. Oberhumer
2023-07-26 22:28:47 +02:00
parent 5a1203be0d
commit 053e95033f
24 changed files with 107 additions and 46 deletions
+4
View File
@@ -306,9 +306,13 @@ TEST_CASE("MemBuffer global overloads") {
mb.clear();
mb4.clear();
CHECK(memcmp(mb, "\x00", 1) == 0);
// NOLINTNEXTLINE(bugprone-unused-return-value)
CHECK_THROWS(memcmp(mb, "\x00\x00", 2));
// NOLINTNEXTLINE(bugprone-unused-return-value)
CHECK_THROWS(memcmp("\x00\x00", mb, 2));
// NOLINTNEXTLINE(bugprone-unused-return-value)
CHECK_THROWS(memcmp(mb, mb4, 2));
// NOLINTNEXTLINE(bugprone-unused-return-value)
CHECK_THROWS(memcmp(mb4, mb, 2));
CHECK_NOTHROW(memset(mb, 255, 1));
CHECK_THROWS(memset(mb, 254, 2));
+3 -1
View File
@@ -265,7 +265,9 @@ void upx_memswap(void *a, void *b, size_t n) {
char *x = (char *) a;
char *y = (char *) b;
do {
char tmp = *x;
// strange clang-analyzer-15 false positive when compiling in Debug mode
// clang-analyzer-core.uninitialized.Assign
char tmp = *x; // NOLINT(*core.uninitialized.Assign) // bogus clang-analyzer warning
*x++ = *y;
*y++ = tmp;
} while (--n != 0);
+3 -3
View File
@@ -150,9 +150,9 @@ using OwningPointer = T *;
#else
// simple class with just a number of no-ops
// also works: a simple class with just a number of no-ops
template <class T>
struct OwningPointer {
struct OwningPointer final {
static_assert(std::is_class_v<T>); // UPX convention
typedef typename std::add_lvalue_reference<T>::type reference;
typedef typename std::add_lvalue_reference<const T>::type const_reference;
@@ -167,7 +167,7 @@ struct OwningPointer {
inline pointer operator->() noexcept { return ptr; }
inline const_pointer operator->() const noexcept { return ptr; }
};
// overload mem_clear()
// must overload mem_clear()
template <class T>
inline void mem_clear(OwningPointer<T> object) noexcept {
mem_clear((T *) object);