Ivan Maidanski [Tue, 15 Nov 2016 07:48:31 +0000 (10:48 +0300)]
Suppress 'tainted string passed to vulnerable operation' false defects
* include/private/gc_priv.h (TRUSTED_STRING): New tagging macro; add
comment.
* misc.c (GC_init): Process the result of GETENV("GC_LOG_FILE") by
TRUSTED_STRING.
* tools/if_mach.c (main): Process argv[3] by TRUSTED_STRING (before
passing the string to execvp).
* tools/if_not_there.c (main): Declare "fname" local variable;
process argv[1] and argv[2] by TRUSTED_STRING (before passing the
strings to fopen/opendir and execvp, respectively).
Ivan Maidanski [Mon, 14 Nov 2016 07:58:26 +0000 (10:58 +0300)]
Eliminate 'GC_record_fault is never used' cppcheck style warning
* checksums.c [CHECKSUMS] (GC_record_fault): Do not define unless
MPROTECT_VDB and not DARWIN.
* os_dep.c [MPROTECT_VDB && CHECKSUMS] (GC_record_fault): Do not
declare if DARWIN.
Ivan Maidanski [Mon, 14 Nov 2016 07:12:32 +0000 (10:12 +0300)]
Replace C++ style comments to C ones, remove commented out code (extra)
* extra/AmigaOS.c (GC_amiga_get_mem, GC_amiga_allocwrapper_any,
GC_amiga_allocwrapper_fast): Replace the style of comments from C++
to C.
* extra/MacOS.c (CodeZeroPtr, GC_MacTemporaryNewPtr): Likewise.
* extra/Mac_files/MacOS_config.h: Likewise.
* extra/AmigaOS.c (GC_amiga_get_mem, GC_amiga_rec_alloc,
GC_amiga_allocwrapper_any, GC_amiga_allocwrapper_fast): Remove
commented out code.
* extra/Mac_files/MacOS_config.h: Likewise.
Ivan Maidanski [Fri, 18 Nov 2016 14:16:32 +0000 (17:16 +0300)]
Ensure oom_fn callback executed on out-of-memory in calloc
(fix commits e10c1eb, 4e1a6f9)
* malloc.c [REDIRECT_MALLOC && !REDIRECT_MALLOC_IN_HEADER] (calloc):
Call oom_fn(SIZE_MAX) (instead of returning NULL) if n*lb overflows.
* typd_mlc.c (GC_calloc_explicitly_typed): Likewise.
* typd_mlc.c (GC_calloc_explicitly_typed): If register_disappearing_link
failed due to lack of memory then call oom_fn(lb) instead of
GC_malloc(lb); update comment.
Ivan Maidanski [Sat, 19 Nov 2016 17:37:04 +0000 (20:37 +0300)]
Fix assertion violation in GC_repeat_read if --enable-redirect-malloc
* malloc.c [REDIRECT_MALLOC && GC_LINUX_THREADS] (GC_init_lib_bounds):
Declare cancel_state local variable; DISABLE_CANCEL for GC_text_mapping
(because GC_repeat_read expects the cancellation state off); call
RESTORE_CANCEL on return.
Ivan Maidanski [Wed, 16 Nov 2016 09:05:43 +0000 (12:05 +0300)]
Document configure 'syntax error' issue in README
* README.md (Installation and Portability): Add information how to
avoid "syntax error near unexpected token ATOMIC_OPS" configure failure
(caused by lack of pkg.m4).
Ivan Maidanski [Tue, 15 Nov 2016 12:25:54 +0000 (15:25 +0300)]
Fix potential integer overflow in GC_find_limit_* functions
* os_dep.c [OPENBSD] (GC_find_limit_openbsd, GC_skip_hole_openbsd): Add
assertion for the minimum value of bound; increment result by pgsz only
if no overflow is guaranteed.
* os_dep.c [USE_PROC_FOR_LIBRARIES && THREADS || NEED_FIND_LIMIT]
(GC_find_limit_with_bound): Add assertion for the minimum/maximum value
of bound; increment/decrement result by MIN_PAGE_SIZE only if no
overflow/underflow is guaranteed.
Ivan Maidanski [Mon, 31 Oct 2016 07:09:10 +0000 (10:09 +0300)]
Export GC_print_free_list()
Note: this function is not used by GC itself.
* include/gc_inline.h (GC_print_free_list): New public API prototype.
* reclaim.c [!NO_DEBUGGING]: Include gc_inline.h (to check that
GC_print_free_list prototype matches the definition).
* reclaim.c [!NO_DEBUGGING] (GC_print_free_list): Define as public
(GC_API+GC_CALL); remove "ok" local variable; add assertions about kind
and sz_in_granules maximum values.
Ivan Maidanski [Fri, 28 Oct 2016 08:45:48 +0000 (11:45 +0300)]
Eliminate duplicate log messages in GC_mark_from
This change also eliminates 'bad copy-paste' code defect in GC_mark_from.
* mark.c [ENABLE_TRACE] (GC_mark_from): Combine 2 logged messages
about "large section" and "splitting" into a single one;
replace "Tracing from" logged message with "small object" message
(which is not logged for large objects).
Ivan Maidanski [Tue, 4 Oct 2016 20:27:53 +0000 (23:27 +0300)]
Eliminate all 'scope of variable can be reduced' cppcheck style warnings
(Cherry-pick commits 03bb5fb, b3692f9, 81d04a6, 65347c0, a117f6c from 'master'.)
Ivan Maidanski [Mon, 24 Oct 2016 08:06:33 +0000 (11:06 +0300)]
Workaround 'value of macro unknown' cppcheck info messages
The messages are eliminated for the macros: __int64, _SIGRTMIN,
ARM_THREAD_STATE32, ARM_UNIFIED_THREAD_STATE, FIXUP_POINTER,
GC_COLLECT_AT_MALLOC, GC_FREE_SPACE_DIVISOR, GC_FULL_FREQ,
GC_INITIAL_HEAP_SIZE, GC_MAX_RETRIES, GC_MAXIMUM_HEAP_SIZE,
GC_MIN_MARKERS, GC_SIG_SUSPEND, GC_SIG_THR_RESTART, GC_TIME_LIMIT,
HEURISTIC2_LIMIT, MAP_ANONYMOUS, RTLD_DI_LINKMAP, SAVE_CALL_COUNT,
SIZE_MAX.
* alloc.c (GC_full_freq, GC_free_space_divisor, GC_time_limit): Define
to default immediate value if CPPCHECK.
* darwin_stop_world.c [ARM32 && ARM_THREAD_STATE32]
(GC_ARM_UNIFIED_THREAD_STATE): New macro (defined to
ARM_UNIFIED_THREAD_STATE unless CPPCHECK).
* darwin_stop_world.c [ARM32 && ARM_THREAD_STATE32]
(GC_stack_range_for): Use GC_ARM_UNIFIED_THREAD_STATE; do not use value
of ARM_THREAD_STATE32 if CPPCHECK.
* dyn_load.c [!USE_PROC_FOR_LIBRARIES] (GC_RTLD_DI_LINKMAP): New macro
(defined to RTLD_DI_LINKMAP unless CPPCHECK).
* dyn_load.c [!USE_PROC_FOR_LIBRARIES] (GC_FirstDLOpenedLinkMap): Use
GC_RTLD_DI_LINKMAP.
* include/gc.h (GC_word, GC_signed_word): Do not define to __int64 if
CPPCHECK.
* include/gc.h (GC_INIT_CONF_MAX_RETRIES,
GC_INIT_CONF_FREE_SPACE_DIVISOR, GC_INIT_CONF_FULL_FREQ,
GC_INIT_CONF_TIME_LIMIT, GC_INIT_CONF_SUSPEND_SIGNAL,
GC_INIT_CONF_THR_RESTART_SIGNAL, GC_MAXIMUM_HEAP_SIZE,
GC_INITIAL_HEAP_SIZE): Define to empty if CPPCHECK.
* include/private/gc_priv.h [SIZE_MAX] (GC_SIZE_MAX): Do not define to
SIZE_MAX if CPPCHECK.
* include/private/gc_priv.h [DARWIN && ARM32
&& ARM_UNIFIED_THREAD_STATE] (GC_MACH_THREAD_STATE): Do not define to
ARM_UNIFIED_THREAD_STATE if CPPCHECK.
* include/private/gc_priv.h [GC_PTHREADS && _SIGRTMIN] (SIG_SUSPEND):
Do not define to _SIGRTMIN if CPPCHECK.
* pthread_stop_world.c [!SIG_THR_RESTART && _SIGRTMIN]
(SIG_THR_RESTART): Likewise.
* include/private/gcconfig.h [SAVE_CALL_CHAIN && SAVE_CALL_COUNT]
(NFRAMES): Define to immediate value (do not use value of
SAVE_CALL_COUNT) if CPPCHECK.
* include/private/gcconfig.h [!FIXUP_POINTER && POINTER_MASK]
(FIXUP_POINTER): Define to a sample expression (not using values of
POINTER_MASK and POINTER_SHIFT) if CPPCHECK.
* malloc.c [GC_COLLECT_AT_MALLOC] (GC_dbg_collect_at_malloc_min_lb):
Define to sample value (not using value of GC_COLLECT_AT_MALLOC) if
CPPCHECK.
* misc.c [GC_INITIAL_HEAP_SIZE] (GC_init): Define to default immediate
value if CPPCHECK.
* os_dep.c [!BEOS && !OS2 && !SWIN32 && !GC_OPENBSD_THREADS
&& !STACKBOTTOM && HEURISTIC2_LIMIT] (GC_get_main_stack_base): Do not
use value of HEURISTIC2_LIMIT if CPPCHECK.
* os_dep.c [USE_MMAP_ANON && MAP_ANONYMOUS] (OPT_MAP_ANON): Do not use
value of MAP_ANONYMOUS if CPPCHECK.
* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD && !GC_TIME_LIMIT]
(GC_TIME_LIMIT): Do not define.
* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD]
(GC_brief_async_signal_safe_sleep): Do not use value of GC_TIME_LIMIT
if CPPCHECK.
* pthread_support.c [PARALLEL_MARK && GC_MIN_MARKERS] (GC_thr_init):
Do not use value of GC_MIN_MARKERS if CPPCHECK.
* win32_threads.c [PARALLEL_MARK && GC_MIN_MARKERS] (GC_thr_init):
Likewise.
* tests/test.c [GC_DEBUG && SAVE_CALL_CHAIN && SAVE_CALL_COUNT]
(check_heap_stats): Use NFRAMES instead of SAVE_CALL_COUNT (i.e. do not
use value of SAVE_CALL_COUNT).
* dyn_load.c [HAVE_DL_ITERATE_PHDR]
(GC_register_dynamic_libraries_dl_iterate_phdr): Cast datastart to
char*volatile* before dereferencing and checking against NULL.
Ivan Maidanski [Tue, 25 Oct 2016 08:37:40 +0000 (11:37 +0300)]
Workaround 'condition is always false' cppcheck warning in get_next_stack
* win32_threads.c [CPPCHECK] (GC_get_next_stack): Set thread a non-null
value (near current_min assignment) even if GC_win32_dll_threads (to
avoid cppcheck complain that if(thread!=0) is always false (thus
UNPROTECT_THREAD(thread) is never reached) if GC_DISCOVER_TASK_THREADS.
* include/private/gc_priv.h (GC_on_abort): Move definition upper (to be
before ABORT definition); define it to empty if PCR (this is needed for
CPPCHECK).
* include/private/gc_priv.h (ABORT): Specially define to
{GC_on_abort(msg);abort();} block statement if CPPCHECK.
* tests/test.c (chktree): Check for n is zero only once; add comment.
Ivan Maidanski [Tue, 18 Oct 2016 21:42:29 +0000 (00:42 +0300)]
Workaround 'variable reassigned before old value used' cppcheck warnings
* misc.c (GC_call_with_gc_active): Call GC_noop1 for
GC_traced_stack_sect and GC_blocked_sp (before restoring their original
values) if CPPCHECK.
* win32_threads.c (GC_do_blocking_inner): Call GC_noop1 for
thread_blocked_sp field (before restoring its original value)
if CPPCHECK.
* win32_threads.c (GC_call_with_gc_active): Call GC_noop1 for
traced_stack_sect field (before restoring its original value)
if CPPCHECK.
Ivan Maidanski [Tue, 18 Oct 2016 09:24:34 +0000 (12:24 +0300)]
Workaround 'obsolete function alloca() called' cppcheck warnings
* dyn_load.c [AIX] (GC_register_dynamic_libraries): Code refactoring
to have alloca() call only once (at the beginning of a block); use
variable-length array instead of alloca() if CPPCHECK.
Ivan Maidanski [Tue, 18 Oct 2016 07:59:20 +0000 (10:59 +0300)]
Workaround 'struct member is never used' cppcheck style warnings
* os_dep.c [OS2] (GC_register_data_segments): Assign 0 to
hdrdos.padding, hdr386.exe_format_level/os/padding1/padding2,
seg.pagemap/mapsize/reserved fields if CPPCHECK; add comment.
* os_dep.c [MPROTECT_VDB && DARWIN] (GC_mprotect_thread): Assign 0 to
the first element of reply.data, msg.data fields if CPPCHECK; add
comment.
* typd_mlc.c (TAG): Define to ad.ad_tag (instead of ld.ld_tag).
* include/private/gc_locks.h [PCR && THREADS] (DCL_LOCK_STATE): Define
to empty if CPPCHECK.
* mach_dep.c [MACOS && __MWERKS__ && POWERPC] (getRegisters): Declare
as external of CPPCHECK (as cppcheck does not recognize "asm" in
function declaration).
Ivan Maidanski [Wed, 14 Sep 2016 22:03:15 +0000 (01:03 +0300)]
Eliminate 'constructor with 1 argument is not explicit' cppcheck warning
(Cherry-pick commits 569fd66 and 7811301 from 'master' branch.)
Note that -D CPPCHECK should be passed to cppcheck to activate
this workaround.
* include/gc_allocator.h (GC_ATTR_EXPLICIT): New macro (defined to
"explicit" keyword if at least C++11 or CPPCHECK, otherwise to empty).
* include/gc_allocator.h (gc_allocator::gc_allocator,
gc_allocator_ignore_off_page::gc_allocator_ignore_off_page,
traceable_allocator::traceable_allocator): Use GC_ATTR_EXPLICIT.
* tests/test_cpp.cc (A::A, B::B, C::C, D::D): Likewise.
* tests/test_cpp.cc (GC_ATTR_EXPLICIT): Define macro in the same way as
in include/gc_allocator.h
Ivan Maidanski [Fri, 21 Oct 2016 18:57:15 +0000 (21:57 +0300)]
Workaround 'tainted int used as loop bound' static analysis tool warning
(Cherry-pick commits 1868a90 and 0f23ec4 from 'master' branch.)
No need to check upper bound of n here, so a dummy check is added.
* tests/test_cpp.cc (main) [LINT2]: Check upper bound of n signed local
variable (the check is actually dummy).
* tests/test_cpp.cc (main): Reformat code (which handles n variable).
Ivan Maidanski [Sat, 29 Oct 2016 14:49:37 +0000 (17:49 +0300)]
Eliminate 'null dereference' code defect warning in register_finalizer
* finalize.c (GC_register_finalizer_inner): Add GC_ASSERT that fn is
non-zero (instead of specifying this in a comment) for the case when
new_fo is non-NULL (new_fo is returned by GC_oom_fn).
* finalize.c [LINT2] (GC_register_finalizer_inner): Call ABORT if hhdr
is NULL (for the case when new_fo is non-NULL).
* os_dep.c [USE_MUNMAP && LINT2] (GC_unmap, GC_remap, GC_unmap_gap):
Call GC_noop1(result) where result is returned by mmap or VirtualAlloc.
* os_dep.c [USE_MUNMAP && NACL] (GC_remap): Rename mmap_result local
variable to result.
* os_dep.c [USE_MUNMAP && !USE_WINALLOC] (GC_unmap_gap): Update
GC_unmapped_bytes (by len) only if len is non-zero.
Ivan Maidanski [Mon, 3 Oct 2016 07:22:59 +0000 (10:22 +0300)]
Workaround 'local variable size too big' static analyzer warning
* mark.c [PARALLEL_MARK] (LOCAL_MARK_STACK_SIZE): Define to smaller
value if LINT2 (to avoid static analysis tool warning that
local_mark_stack local variable size is very big).
Ivan Maidanski [Wed, 28 Sep 2016 07:04:39 +0000 (10:04 +0300)]
Eliminate 'comparison is always false' static analyzer warning in finalize
GC_enqueue_all_finalizers code refactoring is done (removal of the
unreachable statement) to eliminate the warning.
* finalize.c (GC_enqueue_all_finalizers): Remove "prev_fo" local
variable; remove "register" keyword for local variables;
remove the pointer to the chain of hash table entries from the roots
(i.e. setting the roots pointer to null) at the beginning of processing
the chain (instead of updating the roots pointer on deletion of each
entry and finally setting it to null); remove fo_set_next(prev_fo) as
it is never called (because prev_fo was always null); update
GC_fo_entries only when the whole table processed (i.e. all items
removed).
Ivan Maidanski [Sat, 29 Oct 2016 07:14:42 +0000 (10:14 +0300)]
Export GC_is_tmp_root() and GC_print_trace[_inner]()
Note: these 3 functions are not used by GC itself.
* include/gc_mark.h (GC_is_tmp_root, GC_print_trace,
GC_print_trace_inner): New public API prototype.
* mark.c [TRACE_BUF] (GC_print_trace_inner, GC_print_trace): Define as
public (GC_API+GC_CALL).
* mark_rts.c [MSWIN32 && !NO_DEBUGGING] (GC_is_tmp_root): Likewise.
* mark_rts.c [MSWIN32 && !NO_DEBUGGING] (GC_is_tmp_root): Replace
GC_bool return type with int, replace ptr_t argument type to void*
(because GC_bool and ptr_t are not exported from GC).
Ivan Maidanski [Fri, 28 Oct 2016 21:23:02 +0000 (00:23 +0300)]
Export GC_dump_finalization/regions()
Note: these 2 functions are not used by GC itself.
* allchblk.c [!NO_DEBUGGING] (GC_dump_regions): Turn into a public
definition (add GC_API+GC_CALL).
* finalize.c [!NO_DEBUGGING] (GC_dump_finalization): Likewise.
* include/gc.h (GC_dump_regions, GC_dump_finalization): New public API
prototype.
Ivan Maidanski [Mon, 19 Sep 2016 21:07:47 +0000 (00:07 +0300)]
Fix malloc routines to prevent size value wrap-around
See issue #135 on Github.
* allchblk.c (GC_allochblk, GC_allochblk_nth): Use
OBJ_SZ_TO_BLOCKS_CHECKED instead of OBJ_SZ_TO_BLOCKS.
* malloc.c (GC_alloc_large): Likewise.
* alloc.c (GC_expand_hp_inner): Type of "bytes" local variable changed
from word to size_t; cast ROUNDUP_PAGESIZE argument to size_t; prevent
overflow when computing GC_heapsize+bytes > GC_max_heapsize.
* dbg_mlc.c (GC_debug_malloc, GC_debug_malloc_ignore_off_page,
GC_debug_malloc_atomic_ignore_off_page, GC_debug_generic_malloc,
GC_debug_generic_malloc_inner,
GC_debug_generic_malloc_inner_ignore_off_page,
GC_debug_malloc_stubborn, GC_debug_malloc_atomic,
GC_debug_malloc_uncollectable, GC_debug_malloc_atomic_uncollectable):
Use SIZET_SAT_ADD (instead of "+" operator) to add extra bytes to lb
value.
* fnlz_mlc.c (GC_finalized_malloc): Likewise.
* gcj_mlc.c (GC_debug_gcj_malloc): Likewise.
* include/private/gc_priv.h (ROUNDUP_GRANULE_SIZE, ROUNDED_UP_GRANULES,
ADD_SLOP, ROUNDUP_PAGESIZE): Likewise.
* include/private/gcconfig.h (GET_MEM): Likewise.
* mallocx.c (GC_malloc_many, GC_memalign): Likewise.
* os_dep.c (GC_wince_get_mem, GC_win32_get_mem): Likewise.
* typd_mlc.c (GC_malloc_explicitly_typed,
GC_malloc_explicitly_typed_ignore_off_page,
GC_calloc_explicitly_typed): Likewise.
* headers.c (GC_scratch_alloc): Change type of bytes_to_get from word
to size_t (because ROUNDUP_PAGESIZE_IF_MMAP result type changed).
* include/private/gc_priv.h: Include limits.h (unless SIZE_MAX already
defined).
* include/private/gc_priv.h (GC_SIZE_MAX, GC_SQRT_SIZE_MAX): Move from
malloc.c file.
* include/private/gc_priv.h (SIZET_SAT_ADD): New macro (defined before
include gcconfig.h).
* include/private/gc_priv.h (EXTRA_BYTES, GC_page_size): Change type
to size_t.
* os_dep.c (GC_page_size): Likewise.
* include/private/gc_priv.h (ROUNDUP_GRANULE_SIZE, ROUNDED_UP_GRANULES,
ADD_SLOP, ROUNDUP_PAGESIZE): Add comment about the argument.
* include/private/gcconfig.h (GET_MEM): Likewise.
* include/private/gc_priv.h (ROUNDUP_GRANULE_SIZE, ROUNDED_UP_GRANULES,
ADD_SLOP, OBJ_SZ_TO_BLOCKS, ROUNDUP_PAGESIZE,
ROUNDUP_PAGESIZE_IF_MMAP): Rename argument to "lb".
* include/private/gc_priv.h (OBJ_SZ_TO_BLOCKS_CHECKED): New macro.
* include/private/gcconfig.h (GC_win32_get_mem, GC_wince_get_mem,
GC_unix_get_mem): Change argument type from word to int.
* os_dep.c (GC_unix_mmap_get_mem, GC_unix_get_mem,
GC_unix_sbrk_get_mem, GC_wince_get_mem, GC_win32_get_mem): Likewise.
* malloc.c (GC_alloc_large_and_clear): Call OBJ_SZ_TO_BLOCKS only
if no value wrap around is guaranteed.
* malloc.c (GC_generic_malloc): Do not check for lb_rounded < lb case
(because ROUNDED_UP_GRANULES and GRANULES_TO_BYTES guarantees no value
wrap around).
* mallocx.c (GC_generic_malloc_ignore_off_page): Likewise.
* misc.c (GC_init_size_map): Change "i" local variable type from int
to size_t.
* os_dep.c (GC_write_fault_handler, catch_exception_raise): Likewise.
* misc.c (GC_envfile_init): Cast len to size_t when passed to
ROUNDUP_PAGESIZE_IF_MMAP.
* os_dep.c (GC_setpagesize): Cast GC_sysinfo.dwPageSize and
GETPAGESIZE() to size_t (when setting GC_page_size).
* os_dep.c (GC_unix_mmap_get_mem, GC_unmap_start, GC_remove_protection):
Expand ROUNDUP_PAGESIZE macro but without value wrap-around checking
(the argument is of word type).
* os_dep.c (GC_unix_mmap_get_mem): Replace -GC_page_size with
~GC_page_size+1 (because GC_page_size is unsigned); remove redundant
cast to size_t.
* os_dep.c (GC_unix_sbrk_get_mem): Add explicit cast of GC_page_size
to SBRK_ARG_T.
* os_dep.c (GC_wince_get_mem): Change type of res_bytes local variable
to size_t.
* typd_mlc.c: Do not include limits.h.
* typd_mlc.c (GC_SIZE_MAX, GC_SQRT_SIZE_MAX): Remove (as defined in
gc_priv.h now).
Ivan Maidanski [Wed, 21 Sep 2016 18:25:35 +0000 (21:25 +0300)]
Fix 'shift count >= width of type' compiler warning in GC_SQRT_SIZE_MAX
(fix commit 83231d0)
(Cherry-pick part of commit b4eb5c1 from 'master' branch.)
* malloc.c (GC_SQRT_SIZE_MAX): Change type from unsigned to size_t.
Ivan Maidanski [Thu, 15 Sep 2016 15:40:21 +0000 (18:40 +0300)]
Fix calloc_explicitly_typed in case of lb*n overflow
(Cherry-pick commits 4e1a6f9 and part of b4eb5c1 from 'master' branch.)
* typd_mlc.c: Include limits.h (for SIZE_MAX).
* typd_mlc.c (GC_SIZE_MAX, GC_SQRT_SIZE_MAX): New macro (same as in
malloc.c).
* typd_mlc.c (GC_calloc_explicitly_typed): Return NULL if lb * n
overflows (same algorithm as in calloc defined in malloc.c); eliminate
lb *= n code duplication.
Ivan Maidanski [Fri, 30 Sep 2016 14:12:24 +0000 (17:12 +0300)]
Fix potential overflow in decrement when computing GC_markers_m1
Also, call WARN if a non-positive value is specified in GC_MARKERS.
* pthread_support.c [PARALLEL_MARK] (GC_thr_init): Replace markers_m1
local variable with markers one; keep real number of markers in
"markers" variable (not a decremented one); treat invalid (i.e.
non-positive) markers value (obtained from GC_MARKERS environment
variable) the same way as too big ones (i.e. set to maximum number of
markers in this case); adjust WARN message accordingly; report invalid
or too big markers value in WARN.
* win32_threads.c [PARALLEL_MARK] (GC_thr_init): Likewise.
* pthread_support.c [PARALLEL_MARK] (GC_thr_init): Adjust code
indentation.
Ivan Maidanski [Fri, 30 Sep 2016 12:46:42 +0000 (15:46 +0300)]
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).
Ivan Maidanski [Tue, 18 Oct 2016 08:14:22 +0000 (11:14 +0300)]
Workaround 'passing untyped NULL to variadic function' cppcheck warning
The portability warning "Passing NULL after the last typed argument to
a variadic function leads to undefined behavior" was reported for
ABORT_ARG2(..., DATASTART, DATAEND) call in GC_register_data_segments.
Ivan Maidanski [Wed, 5 Oct 2016 08:32:00 +0000 (11:32 +0300)]
Eliminate 'address of local variable returned' static analyzer warning
* mark_rts.c [__GNUC__ >= 4] (GC_approx_sp): Use
__builtin_frame_address(0) instead of &sp (but still write the value to
the volatile local variable to force stack to grow if necessary).
* tools/setjmp_t.c [__GNUC__ >= 4] (nested_sp): Return
__builtin_frame_address(0) instead of sp.
Ivan Maidanski [Wed, 5 Oct 2016 08:04:25 +0000 (11:04 +0300)]
Fix tools/setjmp_t to prevent nested_sp inlining
Inlined nested_sp might cause incorrect result of nested_sp()<sp.
* tools/setjmp_t.c (nested_sp): Change return from int* to word.
* tools/setjmp_t.c (nested_sp_fn): New global volatile variable
initialized to nested_sp.
* tools/setjmp_t.c (main): Use nested_sp_fn instead of nested_sp;
remove redundant cast.
* include/gc_cpp.h (gc_cleanup::gc_cleanup): Define this_ptr void
pointer; use this_ptr instead of this keyword to outline that the
pointer subtraction is intentional (i.e., "this->" was not intended).
Ivan Maidanski [Fri, 21 Oct 2016 08:42:26 +0000 (11:42 +0300)]
Fix 'ISO C90 forbids mixed declarations and code' compiler warning
* pthread_support.c [GC_PTHREADS && !GC_WIN32_THREADS]
(GC_thread_exit_proc): Move GC_log_printf() call down to be after local
variables declarations.
* thread_local_alloc.c [THREAD_LOCAL_ALLOC && USE_PTHREAD_SPECIFIC
&& !USE_WIN32_SPECIFIC]: Add {} to have "k" local variable declaration
before any statement in a block.