From 64bed186fc1ca9a654c9bca063089f5b7ead87be Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 1 Mar 2017 01:25:34 +0300 Subject: [PATCH] Eliminate 'checking unsigned variable < 0' cppcheck warning in gc_inline * include/gc_inline.h (GC_FAST_MALLOC_GRANS): Replace (word)my_entry<=num_direct with (signed_word)my_entry-num_direct<=0 to avoid "checking unsigned var < 0" warning if num_direct==0 (no overflow is expected in (signed_word)my_entry-num_direct as it is guaranteed that (word)my_entry<=num_direct+GC_TINY_FREELISTS+1). --- include/gc_inline.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/gc_inline.h b/include/gc_inline.h index 4934aee..f0d8189 100644 --- a/include/gc_inline.h +++ b/include/gc_inline.h @@ -121,7 +121,9 @@ GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void * GC_CALL break; \ } \ /* Entry contains counter or NULL */ \ - if ((GC_word)my_entry <= (num_direct) && my_entry != 0) { \ + if ((GC_signed_word)my_entry - (GC_signed_word)(num_direct) <= 0 \ + /* (GC_word)my_entry <= (num_direct) */ \ + && my_entry != NULL) { \ /* Small counter value, not NULL */ \ *my_fl = (char *)my_entry + (granules) + 1; \ result = (default_expr); \ -- 2.7.4