[PATCH 2/2] Fix `-Werror, -Wtautological-constant-out-of-range-compare` build error

lockalsash@gmail.com lockalsash@gmail.com
Thu Jun 4 03:49:13 GMT 2026


From: "Sv. Lockal" <lockalsash@gmail.com>

Clang-22 fails to build with the following error:
```
stapbpf.cxx:2033:21: error: result of comparison of constant 2305843009213693951 with expression of
      type 'unsigned int' is always false [-Werror,-Wtautological-constant-out-of-range-compare]
 2033 |   if (n_active_cpus > (size_t)-1 / sizeof(struct pollfd))
      |       ~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
as `n_active_cpus` is of type `unsigned` (32-bit), so it should be
compared against another `unsigned`.

Signed-off-by: Sv. Lockal <lockalsash@gmail.com>
---
 stapbpf/stapbpf.cxx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/stapbpf/stapbpf.cxx b/stapbpf/stapbpf.cxx
index 0fca30f2b..ed6d67da4 100644
--- a/stapbpf/stapbpf.cxx
+++ b/stapbpf/stapbpf.cxx
@@ -2030,7 +2030,7 @@ perf_event_loop(pthread_t main_thread)
     = map_attrs[bpf::globals::perf_event_map_idx].max_entries;
   unsigned n_active_cpus
     = count_active_cpus();
-  if (n_active_cpus > (size_t)-1 / sizeof(struct pollfd))
+  if (n_active_cpus > (unsigned)-1 / sizeof(struct pollfd))
     fatal("Too many active CPUs for pollfd allocation\n");
   struct pollfd *pmu_fds
     = (struct pollfd *)malloc(n_active_cpus * sizeof(struct pollfd));
-- 
2.54.0



More information about the Systemtap mailing list