Fix GC_requested_heapsize increment in GC_init
authorIvan Maidanski <ivmai@mail.ru>
Fri, 30 Sep 2016 12:46:42 +0000 (15:46 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 30 Sep 2016 12:46:42 +0000 (15:46 +0300)
Also eliminate static analyzer warning about potential overflow in
initial_heap_sz * HBLKSIZE.

* misc.c (GC_init): Change initial_heap_sz to keep size value in bytes
instead of HBLKSIZE units (thus, GC_requested_heapsize is incremented
by a number of bytes not HBLKSIZE units).

misc.c

diff --git a/misc.c b/misc.c
index af3edcb..d0b3400 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -871,9 +871,9 @@ GC_API void GC_CALL GC_init(void)
 #   endif
 
 #   ifdef GC_INITIAL_HEAP_SIZE
-      initial_heap_sz = divHBLKSZ(GC_INITIAL_HEAP_SIZE);
+      initial_heap_sz = GC_INITIAL_HEAP_SIZE;
 #   else
-      initial_heap_sz = (word)MINHINCR;
+      initial_heap_sz = MINHINCR * HBLKSIZE;
 #   endif
 
 #   if defined(MSWIN32) && !defined(_WIN64) && defined(GC_WIN32_THREADS) \
@@ -1216,21 +1216,20 @@ GC_API void GC_CALL GC_init(void)
           if (initial_heap_sz <= MINHINCR * HBLKSIZE) {
             WARN("Bad initial heap size %s - ignoring it.\n", sz_str);
           }
-          initial_heap_sz = divHBLKSZ(initial_heap_sz);
         }
     }
     {
         char * sz_str = GETENV("GC_MAXIMUM_HEAP_SIZE");
         if (sz_str != NULL) {
           word max_heap_sz = GC_parse_mem_size_arg(sz_str);
-          if (max_heap_sz < initial_heap_sz * HBLKSIZE) {
+          if (max_heap_sz < initial_heap_sz) {
             WARN("Bad maximum heap size %s - ignoring it.\n", sz_str);
           }
           if (0 == GC_max_retries) GC_max_retries = 2;
           GC_set_max_heap_size(max_heap_sz);
         }
     }
-    if (!GC_expand_hp_inner(initial_heap_sz)) {
+    if (!GC_expand_hp_inner(divHBLKSZ(initial_heap_sz))) {
         GC_err_printf("Can't start up: not enough memory\n");
         EXIT();
     } else {