Fix clang-tidy bugprone-sizeof-expression warnings in headers

This one is weird. This checker complains because we tend to use PList,
which sets the type of T to a pointer. The checker is making note that
we're doing sizeof() on a pointer, which always returns the same value
every time. It's asking whether we meant to do that, or if we meant to
pass the actual type to sizeof.
This commit is contained in:
Tim Wojtulewicz 2025-06-09 13:34:09 -07:00
parent 3dae1fa46e
commit bdd1909c61

View file

@ -50,6 +50,7 @@ public:
max_entries = size; max_entries = size;
// NOLINTNEXTLINE(bugprone-sizeof-expression)
entries = (T*)util::safe_malloc(max_entries * sizeof(T)); entries = (T*)util::safe_malloc(max_entries * sizeof(T));
} }
@ -58,6 +59,7 @@ public:
num_entries = b.num_entries; num_entries = b.num_entries;
if ( max_entries ) if ( max_entries )
// NOLINTNEXTLINE(bugprone-sizeof-expression)
entries = (T*)util::safe_malloc(max_entries * sizeof(T)); entries = (T*)util::safe_malloc(max_entries * sizeof(T));
else else
entries = nullptr; entries = nullptr;
@ -77,8 +79,9 @@ public:
List(const T* arr, int n) { List(const T* arr, int n) {
num_entries = max_entries = n; num_entries = max_entries = n;
// NOLINTNEXTLINE(bugprone-sizeof-expression)
entries = (T*)util::safe_malloc(max_entries * sizeof(T)); entries = (T*)util::safe_malloc(max_entries * sizeof(T));
// NOLINTNEXTLINE(bugprone-bitwise-pointer-cast,bugprone-multi-level-implicit-pointer-conversion) // NOLINTNEXTLINE(bugprone-bitwise-pointer-cast,bugprone-multi-level-implicit-pointer-conversion,bugprone-sizeof-expression)
memcpy(entries, arr, n * sizeof(T)); memcpy(entries, arr, n * sizeof(T));
} }
@ -94,6 +97,7 @@ public:
num_entries = b.num_entries; num_entries = b.num_entries;
if ( max_entries ) if ( max_entries )
// NOLINTNEXTLINE(bugprone-sizeof-expression)
entries = (T*)util::safe_malloc(max_entries * sizeof(T)); entries = (T*)util::safe_malloc(max_entries * sizeof(T));
else else
entries = nullptr; entries = nullptr;
@ -139,6 +143,7 @@ public:
new_size = num_entries; // do not lose any entries new_size = num_entries; // do not lose any entries
if ( new_size != max_entries ) { if ( new_size != max_entries ) {
// NOLINTNEXTLINE(bugprone-sizeof-expression)
entries = (T*)util::safe_realloc((void*)entries, sizeof(T) * new_size); entries = (T*)util::safe_realloc((void*)entries, sizeof(T) * new_size);
if ( entries ) if ( entries )
max_entries = new_size; max_entries = new_size;