]> granicus.if.org Git - gc/commitdiff
Eliminate 'checking unsigned variable < 0' cppcheck warning in gc_inline
authorIvan Maidanski <ivmai@mail.ru>
Tue, 28 Feb 2017 22:25:34 +0000 (01:25 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 6 Apr 2017 08:30:29 +0000 (11:30 +0300)
* 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

index c3f75ae9bafb877c4f98c02ae7898d38ab523faf..8f7c9674a87a077d72725818dd2f6e6f02dc624a 100644 (file)
@@ -112,7 +112,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); \