]> granicus.if.org Git - gc/commitdiff
Workaround 'checking if unsigned expression < 0' cppcheck warnings
authorIvan Maidanski <ivmai@mail.ru>
Thu, 7 Feb 2019 17:43:13 +0000 (20:43 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 7 Feb 2019 17:43:13 +0000 (20:43 +0300)
* 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
os_dep.c

diff --git a/alloc.c b/alloc.c
index 840e1704617fb471c6cc762355323563c2dc1050..95a111419067ea67e9f90c1cccc5cbe0d551ce09 100644 (file)
--- 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));
 }
 
index 1f6a0b5dc6508f4d30340a6b7bc4669ea8965ac7..4fe414ba51441ce42a575c9ed1ee4021bf32df7b 100644 (file)
--- 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