From bdd1909c619b92e04e4721c06e37972bfc9d7dc5 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Mon, 9 Jun 2025 13:34:09 -0700 Subject: [PATCH] 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. --- src/List.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/List.h b/src/List.h index 47a7bc9f5e..66039ec21e 100644 --- a/src/List.h +++ b/src/List.h @@ -50,6 +50,7 @@ public: max_entries = size; + // NOLINTNEXTLINE(bugprone-sizeof-expression) entries = (T*)util::safe_malloc(max_entries * sizeof(T)); } @@ -58,6 +59,7 @@ public: num_entries = b.num_entries; if ( max_entries ) + // NOLINTNEXTLINE(bugprone-sizeof-expression) entries = (T*)util::safe_malloc(max_entries * sizeof(T)); else entries = nullptr; @@ -77,8 +79,9 @@ public: List(const T* arr, int n) { num_entries = max_entries = n; + // NOLINTNEXTLINE(bugprone-sizeof-expression) 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)); } @@ -94,6 +97,7 @@ public: num_entries = b.num_entries; if ( max_entries ) + // NOLINTNEXTLINE(bugprone-sizeof-expression) entries = (T*)util::safe_malloc(max_entries * sizeof(T)); else entries = nullptr; @@ -139,6 +143,7 @@ public: new_size = num_entries; // do not lose any entries if ( new_size != max_entries ) { + // NOLINTNEXTLINE(bugprone-sizeof-expression) entries = (T*)util::safe_realloc((void*)entries, sizeof(T) * new_size); if ( entries ) max_entries = new_size;