From a29e39d93ce6379bdfc85b3b95c7b1fb396f1f93 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Thu, 7 Feb 2019 20:43:13 +0300 Subject: [PATCH] Workaround 'checking if unsigned expression < 0' cppcheck warnings * alloc.c [CPPCHECK] (GC_compute_heap_usage_percent): Replace GC_WORD_MAX/100 with (GC_WORD_MAX>>1)/50; add comment. * os_dep.c [!AMIGA && !HAIKU && !OPENBSD && !OS2 && !MSWIN32] (GC_get_main_stack_base): Skip assertion on result if CPPCHECK. --- alloc.c | 8 +++++++- os_dep.c | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/alloc.c b/alloc.c index 840e1704..95a11141 100644 --- a/alloc.c +++ b/alloc.c @@ -1011,7 +1011,13 @@ GC_INLINE int GC_compute_heap_usage_percent(void) { word used = GC_composite_in_use + GC_atomic_in_use; word heap_sz = GC_heapsize - GC_unmapped_bytes; - return used >= heap_sz ? 0 : used < GC_WORD_MAX / 100 ? +# if defined(CPPCHECK) + word limit = (GC_WORD_MAX >> 1) / 50; /* to avoid a false positive */ +# else + const word limit = GC_WORD_MAX / 100; +# endif + + return used >= heap_sz ? 0 : used < limit ? (int)((used * 100) / heap_sz) : (int)(used / (heap_sz / 100)); } diff --git a/os_dep.c b/os_dep.c index 1f6a0b5d..4fe414ba 100644 --- a/os_dep.c +++ b/os_dep.c @@ -1307,7 +1307,9 @@ GC_INNER size_t GC_page_size = 0; result = (ptr_t)(signed_word)(-sizeof(ptr_t)); # endif # endif - GC_ASSERT((word)GC_approx_sp() HOTTER_THAN (word)result); +# if !defined(CPPCHECK) + GC_ASSERT((word)GC_approx_sp() HOTTER_THAN (word)result); +# endif return(result); } # define GET_MAIN_STACKBASE_SPECIAL -- 2.40.0