From d1cdea89a713b5c3da886911826a84ef3feb432f Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 30 Sep 2016 15:46:42 +0300 Subject: [PATCH] Fix GC_requested_heapsize increment in GC_init 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 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/misc.c b/misc.c index af3edcb..d0b3400 100644 --- 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 { -- 2.7.4