Ivan Maidanski [Thu, 17 Nov 2016 07:23:53 +0000 (10:23 +0300)]
Fix assertion violation in mark_local checking GC_mark_stack_top
* mark.c (GC_mark_local): Replace AO_load with AO_load_acquire in
the assertion comparing global_first_nonempty to GC_mark_stack_top.
Ivan Maidanski [Thu, 17 Nov 2016 07:13:12 +0000 (10:13 +0300)]
Workaround 'GC_DllMain is never used' cppcheck style warning
* win32_threads.c [GC_WIN32_THREADS] (GC_init_parallel): Call
GC_noop1(&GC_DllMain) if CPPCHECK (and not GC_NO_THREADS_DISCOVERY).
Ivan Maidanski [Thu, 17 Nov 2016 07:06:22 +0000 (10:06 +0300)]
Workaround 'WinMain() is never used' cppcheck false warning
* tests/test_cpp.cc [!NO_WINMAIN_ENTRY] (WinMain): Call
GC_noop1(&WinMain) if CPPCHECK.
Ivan Maidanski [Thu, 17 Nov 2016 07:02:15 +0000 (10:02 +0300)]
Workaround 'operator delete[]/new[] never used' cppcheck false warning
* gc_cpp.cc [!_MSC_VER && GC_OPERATOR_NEW_ARRAY] (operator new[],
operator delete[]): Do not define if CPPCHECK.
Ivan Maidanski [Thu, 17 Nov 2016 06:56:12 +0000 (09:56 +0300)]
Fix 'incompatible ptr-to-int conversion' compiler warning in push_all_stack
* mark_rts.c [TRACE_BUF] (GC_push_all_stack_partially_eager): Add
explicit cast to word for GC_add_trace_entry bottom/top arguments.
Ivan Maidanski [Thu, 17 Nov 2016 06:38:55 +0000 (09:38 +0300)]
Update README to use autogen.sh on build from the source repository
* README.md (Installation and Portability): Replace autoreconf (and
automake) invocation with autogen.sh one; pass -j option to make.
Ivan Maidanski [Thu, 17 Nov 2016 06:33:20 +0000 (09:33 +0300)]
Update AUTHORS file (add Joshua Richardson)
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 [Wed, 16 Nov 2016 07:34:08 +0000 (10:34 +0300)]
Eliminate 'function result not used' code defect in GC_mark_local
* mark.c (GC_mark_local): Explicitly cast AO_compare_and_swap result to
void (to outline that the result is unused intentionally).
Ivan Maidanski [Tue, 15 Nov 2016 22:13:30 +0000 (01:13 +0300)]
Add testing of new[]/delete[] (test_cpp)
* tests/test_cpp.cc (main): Add test case for new[] and delete[].
Ivan Maidanski [Tue, 15 Nov 2016 21:41:33 +0000 (00:41 +0300)]
Fix register_finalizer call in disclaim_bench for GC_DEBUG
* tests/disclaim_bench.c (testobj_new): Call
GC_REGISTER_FINALIZER_NO_ORDER instead of GC_register_finalizer_no_order.
Ivan Maidanski [Tue, 15 Nov 2016 14:35:40 +0000 (17:35 +0300)]
Support AddressSanitizer and MemorySanitizer (clang)
* include/private/gc_priv.h (GC_ATTR_NO_SANITIZE_ADDR,
GC_ATTR_NO_SANITIZE_MEMORY): New macro.
* include/private/gcconfig.h [__has_feature(address_sanitizer)]
(ADDRESS_SANITIZER): New macro.
* include/private/gcconfig.h [__has_feature(memory_sanitizer)]
(MEMORY_SANITIZER): Likewise.
* mach_dep.c (GC_with_callee_saves_pushed): Use
GC_ATTR_NO_SANITIZE_ADDR attribute.
* mark.c (GC_mark_from, GC_push_all_eager): Likewise.
* mark.c (GC_mark_from, GC_push_all_eager): Use
GC_ATTR_NO_SANITIZE_MEMORY attribute.
* os_dep.c [ADDRESS_SANITIZER && (UNIX_LIKE || NEED_FIND_LIMIT
|| MPROTECT_VDB)] (__asan_default_options): New function.
* os_dep.c [(NEED_FIND_LIMIT || UNIX_LIKE) && CPPCHECK
&& ADDRESS_SANITIZER] (GC_set_and_save_fault_handler):
Reference __asan_default_options.
* os_dep.c [MPROTECT_VDB && !DARWIN && CPPCHECK && ADDRESS_SANITIZER]
(GC_dirty_init): Likewise.
* tests/test.c [MEMORY_SANITIZER] (check_heap_stats): Increase
max_heap_sz by 25% (to avoid "Unexpected heap growth" error if MSan is
used).
* tests/test_cpp.cc [ADDRESS_SANITIZER || MEMORY_SANITIZER] (main):
Call GC_FREE(a) instead of delete a; add comment.
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 [Tue, 15 Nov 2016 08:35:28 +0000 (11:35 +0300)]
Fix GC_jmp_buf multiple definition
This error occurs only if "-fno-common" gcc option is specified.
* include/private/gc_priv.h [USE_PROC_FOR_LIBRARIES && THREADS
|| NEED_FIND_LIMIT] (GC_jmp_buf): Replace variable definition with
a declaration (as GC_EXTERN).
* os_dep.c [USE_PROC_FOR_LIBRARIES && THREADS || NEED_FIND_LIMIT]
(GC_jmp_buf): Define global variable (as GC_INNER).
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 16:52:35 +0000 (19:52 +0300)]
Do not define amiga_get_mem, MacTemporaryNewPtr unless really used (extra)
* extra/AmigaOS.c (GC_amiga_get_mem): Define only if GC_AMIGA_FASTALLOC.
* extra/MacOS.c (TemporaryMemoryBlock, TemporaryMemoryHandle,
struct TemporaryMemoryBlock, theTemporaryMemory,
GC_MacTemporaryNewPtr, perform_final_collection,
GC_MacFreeTemporaryMemory): Define only if USE_TEMPORARY_MEMORY.
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:39:54 +0000 (10:39 +0300)]
Change no-argument functions declaration style to ANSI C (extra files)
* extra/AmigaOS.c (GC_get_main_stack_base, GC_register_data_segments):
Replace "()" to "(void)" in the function prototype.
* extra/MacOS.c (GC_MacGetDataStart, perform_final_collection,
GC_MacFreeTemporaryMemory, GC_MacGetDataEnd): Likewise.
* extra/msvc_dbg.c (GetSymHandle): Likewise.
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, 11 Nov 2016 22:54:24 +0000 (01:54 +0300)]
Update ChangeLog file
Ivan Maidanski [Fri, 11 Nov 2016 22:23:43 +0000 (01:23 +0300)]
Update ChangeLog file (v7.6 changes only)
Ivan Maidanski [Fri, 11 Nov 2016 21:50:21 +0000 (00:50 +0300)]
Update ChangeLog file (v7.2 - v7.4 changes only)
(Cherry-pick commit 88c54c0 from 'release-7_4' branch.)
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 [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).
Ivan Maidanski [Sat, 29 Oct 2016 14:40:01 +0000 (17:40 +0300)]
Revert "Eliminate 'deref-of-null' static analyzer warning in register_finalizer"
This reverts commit
7547c377153ddd859bef6a2dd14c42e9f12aa0be.
Because it requires -D GC_ASSERTIONS.
Ivan Maidanski [Sat, 29 Oct 2016 14:31:41 +0000 (17:31 +0300)]
Fix 'replacement operator delete cannot be inline' GCC warning (Cygwin)
(fix commits 83e0a2c, 3379238)
This commit also eliminates
"operator delete is missing exception specification throw()" compiler
warning.
* gc_cpp.cc (operator delete): Define unconditionally (i.e. for Cygwin
too).
* include/gc_cpp.h [__CYGWIN__]: Do not include "new" header.
* include/gc_cpp.h [__CYGWIN__] (operator delete): Remove (as
replacement function 'operator delete' cannot be declared 'inline').
Ivan Maidanski [Sat, 29 Oct 2016 07:25:50 +0000 (10:25 +0300)]
Enable GC_is_tmp_root for all platforms
* mark_rts.c [!NO_DEBUGGING] (GC_is_tmp_root): Define for any platform
(not only for Win32); update comment.
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:48:53 +0000 (00:48 +0300)]
Allow custom TRACE_ENTRIES value
* mark.c [TRACE_BUF] (TRACE_ENTRIES): Do not define if already defined.
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 [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 [Fri, 28 Oct 2016 08:29:22 +0000 (11:29 +0300)]
Eliminate redundant local variable in register_finalizer
The variable caused a report about a code defect which is a false
positive.
* finalize.c (GC_register_finalizer_inner): Remove "base" local
variable (use "obj" argument instead).
Ivan Maidanski [Fri, 28 Oct 2016 07:57:20 +0000 (10:57 +0300)]
Workaround 'insecure libc pseudo-random number generator used' code defect
* dbg_mlc.c [LINT2] (GC_random): New function.
* dbg_mlc.c [KEEP_BACK_PTRS && LINT2] (RANDOM): Define to GC_random.
* dbg_mlc.c [KEEP_BACK_PTRS && LINT2]: Do not include stdlib.h.
* dbg_mlc.c [KEEP_BACK_PTRS && !LINT2] (GC_RAND_MAX): Define.
* dbg_mlc.c (GC_generate_random_heap_address): Replace RAND_MAX with
GC_RAND_MAX.
* include/private/gc_priv.h [LINT2] (GC_RAND_MAX): New macro.
* include/private/gc_priv.h [LINT2] (GC_random): Prototype (as
GC_API_PRIV).
* tests/disclaim_bench.c [LINT2] (rand): Redefine to GC_random.
* tests/disclaim_test.c [LINT2] (rand): Likewise.
* tests/disclaim_test.c [LINT2]: Include private/gc_priv.h instead of
config.h.
Ivan Maidanski [Fri, 28 Oct 2016 07:07:43 +0000 (10:07 +0300)]
Fix 'address of fudged_set is used out of scope' code defect (sigmask)
(fix commit 81d04a6)
* pthread_support.c [!GC_NO_PTHREAD_SIGMASK] (pthread_sigmask): Move
fudged_set to the outer scope where REAL_FUNC(pthread_sigmask) is
called (a pointer to fudged_set could be passed to the latter function).
Ivan Maidanski [Fri, 28 Oct 2016 06:35:33 +0000 (09:35 +0300)]
Eliminate 'unsafe vsprintf is deprecated' compiler warning
Replacement of vsprintf to vsnprintf (or similar) if available.
Note that no buffer overflow occurs in CORD_vsprintf as buf is
allocated dynamically based on format string.
* cord/cordprnt.c (GC_VSNPRINTF): New macro (the definition is copied
from misc.c).
* cord/cordprnt.c (CORD_vsprintf): Replace vsprintf(buf,...) call with
GC_VSNPRINTF(buf,max_size+1,...).
Ivan Maidanski [Thu, 27 Oct 2016 21:58:21 +0000 (00:58 +0300)]
Eliminate 'possible integer underflow' code defect (cord-de)
* cord/tests/de.c (generic_init): Replace initial==CORD_EMPTY check
with 0==len where len is CORD_len(initial) (to outline that len-1
cannot cause underflow).
Ivan Maidanski [Thu, 27 Oct 2016 21:43:35 +0000 (00:43 +0300)]
Eliminate 'comparison of signed and unsigned int' GCC warning (test_cpp)
(fix commit 1868a90)
* tests/test_cpp.cc [LINT2] (main): Cast unsigned immediate value to
int (before comparison to n local variable).
Ivan Maidanski [Thu, 27 Oct 2016 09:04:41 +0000 (12:04 +0300)]
Workaround 'pos_*, [r]iter, dump never used' cppcheck style warnings (cord)
* cord/tests/cordtest.c [CPPCHECK] (CORD_iter, CORD_next,
CORD_pos_fetch, CORD_pos_to_cord, CORD_pos_to_index, CORD_pos_valid,
CORD_prev): Undefine (at the beginning of the file).
* cord/tests/cordtest.c [CPPCHECK] (test_basics): Call CORD_pos_to_cord,
CORD_pos_to_index, CORD_iter, CORD_riter, CORD_dump; add TODO item.
Ivan Maidanski [Thu, 27 Oct 2016 08:24:26 +0000 (11:24 +0300)]
Eliminate 'CORD_*printf is never used' cppcheck style warnings (cordtest)
Minimal testing of CORD_[v][f]printf is added to cordtest.
* cord/tests/cordtest.c: Include stdarg.h.
* cord/tests/cordtest.c: Reformat the comment describing cordtest.
* cord/tests/cordtest.c (wrap_vprintf, wrap_vfprintf): New function
(calling CORD_v[f]printf).
* cord/tests/cordtest.c (test_printf): Call CORD_printf, wrap_vfprintf,
wrap_vprintf for CORD_EMPTY (with the output to stdout); add TODO item.
Ivan Maidanski [Wed, 26 Oct 2016 21:55:22 +0000 (00:55 +0300)]
Fix conditional expression in pos_fetch, next non-macro definitions (cord)
* cord/cordbscs.c (CORD_pos_fetch, CORD_next): Match the conditional
expression of the macro definition (of the same name) in cord_pos.h.
Ivan Maidanski [Wed, 26 Oct 2016 21:38:55 +0000 (00:38 +0300)]
Workaround 'possible null pointer dereference' cppcheck warning (Darwin)
* darwin_stop_world.c [CPPCHECK] (GC_stack_range_for): Call ABORT if
p is NULL and thread_blocked is true.
Ivan Maidanski [Wed, 26 Oct 2016 21:31:14 +0000 (00:31 +0300)]
Fix null dereference in GC_stack_range_for if not DARWIN_DONT_PARSE_STACK
(fix commit
4ceae609)
* darwin_stop_world.c (GC_stack_range_for): Use GC_ATTR_UNUSED for
paltstack_hi argument (because the latter is not used currently if
!DARWIN_DONT_PARSE_STACK); do not access p->altstack[_size] unless
DARWIN_DONT_PARSE_STACK; add TODO item.
* darwin_stop_world.c [!DARWIN_DONT_PARSE_STACK] (GC_push_all_stacks):
Do not use altstack_hi and altstack_lo; add TODO item.
Ivan Maidanski [Wed, 26 Oct 2016 08:44:37 +0000 (11:44 +0300)]
Eliminate unreachable PROC/DEFAULT_VDB GC_printf calls in gctest main()
* tests/test.c [!GC_WIN32_THREADS && !GC_PTHREADS && !NO_INCREMENTAL
&& (MPROTECT_VDB || PROC_VDB || GWW_VDB) && !MAKE_BACK_GRAPH &&] (main):
Remove unreachable GC_printf call about DEFAULT_VDB; remove extra check
of GWW_VDB case.
* tests/test.c [GC_PTHREADS && MPROTECT_VDB && !REDIRECT_MALLOC
&& !MAKE_BACK_GRAPH && !USE_PROC_FOR_LIBRARIES && !NO_INCREMENTAL]
(main): Remove extra check of MPROTECT_VDB case; remove unreachable
GC_printf calls about PROC_VDB and DEFAULT_VDB.
Ivan Maidanski [Wed, 26 Oct 2016 08:13:29 +0000 (11:13 +0300)]
Eliminate 'suspicious pointer subtraction' cppcheck warning (gc_cpp)
* 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 [Tue, 25 Oct 2016 22:07:33 +0000 (01:07 +0300)]
Revert "Workaround 'suspicious ptr subtraction' cppcheck warning in gc_cpp"
This reverts commit
363890b2ab8365dcc6b87a2a6c4752c1f710dcf2.
Because the warning is still reported by the recent versions of
cppcheck (as of Oct 2016).
Ivan Maidanski [Tue, 25 Oct 2016 21:56:02 +0000 (00:56 +0300)]
Eliminate 'dereference of null' CSA false warning in array_mark_proc
The exact warning message is: Access to field 'mse_start' results in a
dereference of a null pointer (loaded from variable 'new_mark_stack_ptr').
Note: the warning is eliminated regardless of assertion checking status.
* typd_mlc.c (GC_array_mark_proc): Call ABORT if mark_stack_ptr is NULL
(thus orig_mark_stack_ptr is ensured to be non-NULL after the check).
Ivan Maidanski [Tue, 25 Oct 2016 21:38:21 +0000 (00:38 +0300)]
Revert "Eliminate CSA false warning about null deref in array_mark_proc"
This reverts commit
fc339c65ad0fffc2e5bc8332bab9c1c70329c04e.
Because that commit does not eliminate CSA false warning
if GC_ASSERTIONS is off.
Ivan Maidanski [Tue, 25 Oct 2016 21:14:20 +0000 (00:14 +0300)]
Eliminate 'Condition 0==datastart always false' cppcheck warning (dyn_load)
* 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.
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).
Ivan Maidanski [Sat, 22 Oct 2016 15:21:33 +0000 (18:21 +0300)]
Workaround 'value of REDIRECT_MALLOC/FREE unknown' cppcheck info messages
* malloc.c [REDIRECT_MALLOC && !REDIRECT_MALLOC_IN_HEADER]
(REDIRECT_MALLOC_F): New macro (defined to REDIRECT_MALLOC unless
CPPCHECK).
* malloc.c [REDIRECT_MALLOC && !REDIRECT_MALLOC_IN_HEADER] (malloc,
calloc, strdup, strndup): Use REDIRECT_MALLOC_F instead of
REDIRECT_MALLOC.
* malloc.c [REDIRECT_FREE && !REDIRECT_MALLOC_IN_HEADER]
(REDIRECT_FREE_F): New macro (defined to REDIRECT_FREE unless
CPPCHECK).
* malloc.c [REDIRECT_FREE && !REDIRECT_MALLOC_IN_HEADER] (free): Use
REDIRECT_FREE_F instead of REDIRECT_FREE.
Ivan Maidanski [Sat, 22 Oct 2016 14:39:36 +0000 (17:39 +0300)]
Workaround 'value of WINAPI unknown' cppcheck info messages
* include/gc.h [GC_WIN32_THREADS && WINAPI && !CPPCHECK]
(GC_WINDOWS_H_INCLUDED): New macro.
* include/gc.h [GC_WIN32_THREADS] (GC_WINDOWS_H_INCLUDED): Define also
if windows.h included.
* include/gc.h [GC_WIN32_THREADS]: Replace "#ifdef WINAPI" with
"#ifdef GC_WINDOWS_H_INCLUDED".
Ivan Maidanski [Sat, 22 Oct 2016 07:11:46 +0000 (10:11 +0300)]
Workaround 'value of SIGBUS unknown' cppcheck info messages
* include/private/gcconfig.h [SIGBUS && !CPPCHECK] (HAVE_SIGBUS): New
macro.
* os_dep.c [NEED_FIND_LIMIT || UNIX_LIKE] (old_bus_handler,
GC_set_and_save_fault_handler, GC_reset_fault_handler): Replace
"ifdef SIGBUS" with "ifdef HAVE_SIGBUS".
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_remove_allowed_signals): Likewise.
Ivan Maidanski [Sat, 22 Oct 2016 06:48:29 +0000 (09:48 +0300)]
Eliminate 'value of DATASTART2 unknown' cppcheck info messages
* dyn_load.c [HAVE_DL_ITERATE_PHDR]
(GC_register_dynamic_libraries_dl_iterate_phdr): Replace
defined(DATASTART2) with defined(GC_HAVE_DATAREGION2).
* os_dep.c [!OS2 && !MSWIN32 && !OPENBSD] (GC_register_data_segments):
Likewise.
* include/private/gcconfig.h [DATASTART2] (GC_HAVE_DATAREGION2): New
macro.
Ivan Maidanski [Fri, 21 Oct 2016 22:31:44 +0000 (01:31 +0300)]
Eliminate 'value of GC_PTHREAD_EXIT_ATTRIBUTE unknown' cppcheck messages
* include/gc_config_macros.h [GC_PTHREAD_EXIT_ATTRIBUTE]
(GC_HAVE_PTHREAD_EXIT): New macro.
* include/gc_config_macros.h: Replace defined(GC_PTHREAD_EXIT_ATTRIBUTE)
with defined(GC_HAVE_PTHREAD_EXIT).
* include/gc_pthread_redirects.h: Likewise.
* pthread_support.c: Likewise.
Ivan Maidanski [Fri, 21 Oct 2016 22:11:30 +0000 (01:11 +0300)]
Eliminate 'value of GC_RETURN_ADDR_PARENT unknown' cppcheck info messages
* dbg_mlc.c [GC_ADD_CALLER]: Replace defined(GC_RETURN_ADDR_PARENT)
with defined(GC_HAVE_RETURN_ADDR_PARENT).
* include/private/gc_priv.h (GC_DBG_EXTRAS): Likewise.
* include/gc_config_macros.h [GC_RETURN_ADDR_PARENT]
(GC_HAVE_RETURN_ADDR_PARENT): New macro.
Ivan Maidanski [Fri, 21 Oct 2016 20:34:41 +0000 (23:34 +0300)]
Eliminate 'value of CLOCK_TYPE unknown' cppcheck info message
* tests/disclaim_bench.c (main): Replace #ifdef CLOCK_TYPE
with #ifndef NO_CLOCK.
Ivan Maidanski [Fri, 21 Oct 2016 19:11:09 +0000 (22:11 +0300)]
Fix 'ISO C90 does not support %lf, %lg gnu_printf formats' GCC warnings
* tests/disclaim_bench.c (main): Replace "%lf" printf format specifier
to "%f" one, and "%lg" one to "%g" one.
Ivan Maidanski [Fri, 21 Oct 2016 18:57:15 +0000 (21:57 +0300)]
Workaround 'tainted int used as loop bound' static analysis tool warning
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 local
variable (the check is actually dummy).
* tests/test_cpp.cc (main): Reformat code (which handles n variable).
Ivan Maidanski [Fri, 21 Oct 2016 17:27:51 +0000 (20:27 +0300)]
Eliminate 'value of NEED_FIXUP_POINTER unknown' cppcheck info messages
* include/private/gc_pmark.h: Replace #if NEED_FIXUP_POINTER
to #ifdef NEED_FIXUP_POINTER.
* include/private/gcconfig.h (NEED_FIXUP_POINTER): If FIXUP_POINTER
then define to empty else leave undefined.
* mark.c (GC_push_all_stack): Replace if(!NEED_FIXUP_POINTER)
to #ifndef NEED_FIXUP_POINTER.
* mark_rts.c (GC_push_all_stack_partially_eager): Likewise.
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.
Ivan Maidanski [Fri, 21 Oct 2016 08:18:22 +0000 (11:18 +0300)]
Eliminate 'ISO C forbids an empty translation unit' GCC pedantic warning
"extern int GC_quiet" is added to suppress compiler warning.
* extra/msvc_dbg.c [_M_AMD64 || !_MSC_VER] (GC_quiet): Declare external
variable.
Ivan Maidanski [Thu, 20 Oct 2016 22:54:17 +0000 (01:54 +0300)]
Eliminate 'printf format specifies type void*' GCC pedantic warnings
Explicitly cast pointer arguments (passed to printf and ABORT_ARGn) to
void* to match %p format specifier.
* allchblk.c [!NO_DEBUGGING] (GC_dump_regions): Cast arguments to
void* those printf format specifier is %p.
* alloc.c [!NO_DEBUGGING] (GC_print_heap_sects): Likewise.
* backgraph.c [MAKE_BACK_GRAPH] (backwards_height): Likewise.
* blacklst.c (GC_default_print_heap_obj_proc): Likewise.
* blacklst.c [PRINT_BLACK_LIST] (GC_print_blacklisted_ptr): Likewise.
* cord/cordbscs.c (CORD_dump_inner): Likewise.
* darwin_stop_world.c [DEBUG_THREADS_EXTRA] (GC_FindTopOfStack):
Likewise.
* darwin_stop_world.c [DEBUG_THREADS] (GC_stack_range_for): Likewise.
* dbg_mlc.c (GC_print_obj): Likewise.
* dbg_mlc.c [!SHORT_DBG_HDRS] (GC_print_smashed_obj): Likewise.
* dyn_load.c [HAVE_DL_ITERATE_PHDR]
(GC_register_dynamic_libraries_dl_iterate_phdr): Likewise.
* dyn_load.c [IRIX5] (GC_register_dynamic_libraries): Likewise.
* finalize.c [!NO_DEBUGGING] (GC_dump_finalization_links,
GC_dump_finalization): Likewise.
* include/private/gc_pmark.h [MARK_BIT_PER_GRANULE || MARK_BIT_PER_OBJ]
(PUSH_CONTENTS_HDR): Likewise.
* mark.c [ENABLE_TRACE] (GC_mark_from): Likewise.
* mark_rts.c [!NO_DEBUGGING] (GC_print_static_roots): Likewise.
* mark_rts.c [DEBUG_ADD_DEL_ROOTS] (GC_add_roots_inner,
GC_remove_root_at_pos): Likewise.
* misc.c [ENABLE_TRACE] (GC_init): Likewise.
* os_dep.c [LINUX || HURD] (GC_init_linux_data_start): Likewise.
* os_dep.c [!OS2 && !MSWIN32] (GC_register_data_segments): Likewise.
* os_dep.c [USE_MUNMAP && !USE_WINALLOC && !NACL] (GC_remap): Likewise.
* os_dep.c [!DARWIN && !MSWIN32 && !MSWINCE] (GC_write_fault_handler):
Likewise.
* os_dep.c [PROC_VDB && DEBUG_DIRTY_BITS] (GC_read_dirty): Likewise.
* os_dep.c [MPROTECT_VDB && DARWIN && BROKEN_EXCEPTION_HANDLING]
(catch_exception_raise): Likewise.
* pthread_stop_world.c [DEBUG_THREADS] (GC_push_all_stacks): Likewise.
* pthread_support.c [DEBUG_THREADS] (GC_unregister_my_thread_inner,
GC_unregister_my_thread, GC_start_rtn_prepare_thread): Likewise.
* reclaim.c [!NO_DEBUGGING] (GC_print_free_list): Likewise.
* specific.c [USE_CUSTOM_SPECIFIC && GC_ASSERTIONS]
(GC_check_tsd_marks): Likewise.
* win32_threads.c [DEBUG_THREADS] (GC_push_stack_for): Likewise.
* win32_threads.c [GC_PTHREADS && DEBUG_THREADS] (GC_pthread_join,
GC_pthread_create, GC_pthread_start_inner, GC_thread_exit_proc):
Likewise.
* dbg_mlc.c: Remove duplicate check of SHORT_DBG_HDRS.
* include/private/gc_pmark.h [MARK_BIT_PER_GRANULE || MARK_BIT_PER_OBJ]
(PUSH_CONTENTS_HDR): Add missing parentheses around "source" argument
when casting it to ptr_t.
Ivan Maidanski [Wed, 19 Oct 2016 08:42:24 +0000 (11:42 +0300)]
Eliminate 'scope of variable can be reduced' warning in write_fault_handler
* os_dep.c [!DARWIN] (GC_write_fault_handler): Move "i" local variable
declaration to the inner scope where the variable is actually used.
Ivan Maidanski [Wed, 19 Oct 2016 08:09:33 +0000 (11:09 +0300)]
Fix local variable declarations in disclaim_bench
* tests/disclaim_bench.c (main): Place (move) tI, tF local variable
declarations (in the block) before any statement.
Ivan Maidanski [Tue, 18 Oct 2016 22:02:25 +0000 (01:02 +0300)]
Fix 'variable unused' compiler warning in FirstDLOpenedLinkMap
* dyn_load.c [!USE_PROC_FOR_LIBRARIES] (GC_FirstDLOpenedLinkMap):
Declare dp local variable only if !NETBSD or !RTLD_DI_LINKMAP.
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 10:34:34 +0000 (13:34 +0300)]
Workaround 'same expression on both sides of ==' cppcheck style warning
* misc.c (GC_init): Do not check sizeof(signed_word) value if CPPCHECK.
Ivan Maidanski [Tue, 18 Oct 2016 10:26:34 +0000 (13:26 +0300)]
Workaround 'same expression on both sides of OR' cppcheck style warning
* os_dep.c [USE_WINALLOC || CYGWIN32] (GC_mem_top_down): Define to
non-zero value (MEM_TOP_DOWN) if CPPCHECK.
Ivan Maidanski [Tue, 18 Oct 2016 10:19:09 +0000 (13:19 +0300)]
Workaround 'variable hides enumerator with same name' cppcheck warnings
* include/new_gc_alloc.h (GC_bytes_per_word, GC_word_alignment): Define
as const unsigned (instead of single-item enum) if CPPCHECK.
Ivan Maidanski [Tue, 18 Oct 2016 10:05:02 +0000 (13:05 +0300)]
Workaround 'redundant assignment of *result to itself' cppcheck warning
* os_dep.c [DGUX || LINUX && SPARC] (GC_SysVGetDataStart): Call
GC_noop1(&v) if CPPCHECK where v = *result.
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 09:04:52 +0000 (12:04 +0300)]
Workaround 'possible null pointer dereference' cppcheck warnings
* 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 08:57:09 +0000 (11:57 +0300)]
Workaround 'Condition 0!=GETENV() is always false' cppcheck style warnings
* include/private/gc_priv.h [NO_GETENV] (GETENV): Do not define to NULL
if CPPCHECK.
Ivan Maidanski [Tue, 18 Oct 2016 08:50:14 +0000 (11:50 +0300)]
Eliminate 'constructor with 1 argument is not explicit' warnings in test_cpp
(fix commit 569fd66)
* tests/test_cpp.cc (GC_ATTR_EXPLICIT): Define macro in the same way as
in include/gc_allocator.h.
Ivan Maidanski [Tue, 18 Oct 2016 08:39:17 +0000 (11:39 +0300)]
Workaround 'Uninitialized variable' cppcheck errors
* extra/AmigaOS.c [GC_AMIGA_DS] (GC_register_data_segments): Initialize
myseglist outside conditional statement.
* mach_dep.c [GETCONTEXT_FPU_EXCMASK_BUG && X86_64]
(GC_with_callee_saves_pushed): Call GC_noop1(&old_fcw) (before asm
fstcw) if CPPCHECK.
* mach_dep.c [!HAVE_BUILTIN_UNWIND_INIT] (GC_with_callee_saves_pushed):
Replace regs with ®s.
* os_dep.c [!MSWIN32 && !GC_OPENBSD_THREADS && ...]
(GC_get_main_stack_base): Set result to NULL if CPPCHECK but none of
HEURISTIC* and *STACKBOTTOM defined.
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.
* include/private/gcconfig.h [SYMBIAN || __EMSCRIPTEN__] (DATASTART,
DATAEND): Explicitly cast NULL to ptr_t.
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).
Ivan Maidanski [Mon, 17 Oct 2016 22:42:22 +0000 (01:42 +0300)]
Fix 'variable assigned a value that is never used' cppcheck style warnings
* dyn_load.c [USE_PROC_FOR_LIBRARIES] (GC_register_map_entries): Remove
datastart local variable.
* extra/AmigaOS.c [GC_AMIGA_DS] (GC_register_data_segments): Remove
num local variable.
* extra/MacOS.c (firstTime): Remove.
* extra/MacOS.c (GC_MacTemporaryNewPtr): Do not define firstTime if
SHARED_LIBRARY_BUILD.
* extra/MacOS.c (GC_MacFreeTemporaryMemory): Do not define (and update)
totalMemoryUsed if SHARED_LIBRARY_BUILD.
* extra/msvc_dbg.c (GetDescriptionFromAddress): Do not assign size
variable when its value no longer used.
Ivan Maidanski [Mon, 17 Oct 2016 21:28:25 +0000 (00:28 +0300)]
Workaround 'checking if unsigned value is negative' cppcheck warning
* allchblk.c [GC_ASSERTIONS && !USE_MUNMAP] (GC_add_to_fl): Replace
(signed_word)GC_heapsize<0 with (GC_heapsize&SIGNB)!=0.
Ivan Maidanski [Mon, 17 Oct 2016 07:53:19 +0000 (10:53 +0300)]
Workaround more 'void pointers in calculations' cppcheck warnings
* include/new_gc_alloc.h (single_client_gc_alloc_template::allocate,
single_client_gc_alloc_template::ptr_free_allocate,
single_client_gc_alloc_template::deallocate,
single_client_gc_alloc_template::ptr_free_deallocate,
single_client_traceable_alloc_template::allocate,
single_client_traceable_alloc_template::ptr_free_allocate,
single_client_traceable_alloc_template::deallocate,
single_client_traceable_alloc_template::ptr_free_deallocate): Replace
GC_Xobjfreelist_ptr+nwords with &GC_Xobjfreelist_ptr[nwords].
* reclaim.c (GC_start_reclaim): Replace fop++ with (*(word**)&fop)++.
* thread_local_alloc.c (return_freelists): Replace gfl+i with &gfl[i].
Ivan Maidanski [Mon, 17 Oct 2016 07:01:16 +0000 (10:01 +0300)]
Workaround 'unused variable' cppcheck style warnings
* 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 [Fri, 14 Oct 2016 16:22:08 +0000 (19:22 +0300)]
Eliminate more 'scope of variable can be reduced' cppcheck style warnings
* allchblk.c [MARK_BIT_PER_GRANULE] (setup_header): Move local variable
declarations to the inner scope where the variables are actually used.
* alloc.c [!SMALL_CONFIG] (GC_try_to_collect_inner,
GC_finish_collection): Likewise.
* alloc.c (GC_stopped_mark): Likewise.
* backgraph.c [MAKE_BACK_GRAPH] (add_edge): Likewise.
* darwin_stop_world.c [GC_DARWIN_THREADS] (GC_push_all_stacks,
GC_stop_world, GC_thread_resume): Likewise.
* dyn_load.c [USE_PROC_FOR_LIBRARIES] (sort_heap_sects): Likewise.
* dyn_load.c [ALPHA && OSF1 || HPUX] (GC_register_dynamic_libraries):
Likewise.
* dyn_load.c [DARWIN] (GC_dyld_image_add, GC_dyld_image_remove):
Likewise.
* extra/AmigaOS.c (GC_amiga_free_all_mem, GC_amiga_allocwrapper_any):
Likewise.
* extra/msvc_dbg.c (GetDescriptionFromAddress): Likewise.
* gcj_mlc.c [GC_GCJ_SUPPORT] (GC_core_gcj_malloc,
GC_gcj_malloc_ignore_off_page): Likewise.
* include/new_gc_alloc.h (single_client_gc_alloc_template::deallocate,
single_client_gc_alloc_template::ptr_free_deallocate,
single_client_traceable_alloc_template::deallocate,
single_client_traceable_alloc_template::ptr_free_deallocate): Likewise.
* malloc.c [THREADS] (GC_free_inner): Likewise.
* mark_rts.c (GC_add_roots_inner): Likewise.
* misc.c (GC_clear_stack): Likewise.
* os_dep.c [GWW_VDB] (GC_gww_read_dirty): Likewise.
* os_dep.c [MPROTECT_VDB] (GC_protect_heap): Likewise.
* os_dep.c [PROC_VDB] (GC_read_dirty): Likewise.
* os_dep.c [MPROTECT_VDB && DARWIN] (catch_exception_raise): Likewise.
* pthread_stop_world.c [GC_NETBSD_THREADS_WORKAROUND] (GC_start_world):
Likewise.
* pthread_support.c [!GC_NO_PTHREAD_SIGMASK] (pthread_sigmask):
Likewise.
* reclaim.c [!SMALL_CONFIG] (GC_reclaim_all): Likewise.
* tests/test.c (run_one_test): Likewise.
* tests/test.c [MACOS] (SetMinimumStack): Likewise.
* thread_local_alloc.c [THREAD_LOCAL_ALLOC] (return_single_freelist):
Likewise.
* typd_mlc.c (GC_make_descriptor): Likewise.
* win32_threads.c (GC_start_world, GC_CreateThread): Likewise.
* win32_threads.c [!GC_PTHREADS_PARAMARK] (GC_start_mark_threads_inner):
Likewise.
* win32_threads.c [!MSWINCE && !CYGWIN32] (GC_beginthreadex): Likewise.
Ivan Maidanski [Thu, 13 Oct 2016 08:44:52 +0000 (11:44 +0300)]
Eliminate 'printf format specifier mismatch' compiler warning (tools)
* tools/setjmp_t.c (main): Use %lu (instead of %ld) printf format
specifier for unsigned long value.
Ivan Maidanski [Thu, 13 Oct 2016 08:37:21 +0000 (11:37 +0300)]
Fix typo in CHECK_GCLIB_VERSION name (test)
* tests/test.c (CHECK_GCLIB_VERSION): Fix typo in macro name.
Ivan Maidanski [Thu, 13 Oct 2016 08:33:17 +0000 (11:33 +0300)]
Workaround 'resource leak' error reported by cppcheck (tools, test)
* tests/test.c [GC_GCJ_SUPPORT && TEST_WITH_SYSTEM_MALLOC] (reverse):
Call GC_noop1 for malloc() result.
* tools/if_not_there.c (main): Move "f" local variable assignments
outside conditional expression.
Ivan Maidanski [Thu, 13 Oct 2016 08:16:23 +0000 (11:16 +0300)]
Eliminate 'unnecessary comparison of static strings' cppcheck warning
* tools/if_mach.c (main): Replace strcmp(x, "")!=0 with strlen(x)>0.
Ivan Maidanski [Thu, 13 Oct 2016 08:03:04 +0000 (11:03 +0300)]
Workaround more '#error' cppcheck error messages
* darwin_stop_world.c (GC_stack_range_for): Skip #error pragma if
CPPCHECK.
* dyn_load.c [DYNAMIC_LOADING && !PCR && !DARWIN]: Likewise.
* dyn_load.c [SOLARISDL && !PCR && !GC_SOLARIS_THREADS && THREADS]:
Likewise.
* include/private/gc_priv.h [!POWERPC && !I386 && !X86_64 && !ARM32
&& !AARCH64] (GC_THREAD_STATE_T): Likewise.
* include/private/gcconfig.h [GC_IRIX_THREADS && !IRIX5 || ...]:
Likewise.
* include/private/gcconfig.h [PARALLEL_MARK && !THREADS]: Likewise.
* include/private/gcconfig.h [MARK_BIT_PER_GRANULE && MARK_BIT_PER_OBJ
|| ...]: Likewise.
* pcr_interface.c [PCR] (GC_enumerate_block): Likewise.
* win32_threads.c [!I386 && !X86_64 && !ARM32 && !SHx && !MIPS && !PPC
&& !ALPHA] (GC_push_stack_for): Likewise.
* darwin_stop_world.c (GC_stack_range_for): Initialize "lo" local
variable even if platform unsupported.
Ivan Maidanski [Wed, 12 Oct 2016 19:59:22 +0000 (22:59 +0300)]
Fix 'syntax error' reported by cppcheck for mach_dep
The error is reported at line containing "asm".
* mach_dep.c [MACOS && M68K && THINK_C] (GC_push_regs): Do not define
if CPPCHECK.
Ivan Maidanski [Wed, 12 Oct 2016 19:42:41 +0000 (22:42 +0300)]
Fix missing #error pragma
* dyn_load.c [DYNAMIC_LOADING && !PCR && !DARWIN]: Replace "-->" with
* dyn_load.c [SOLARISDL && !PCR && !GC_SOLARIS_THREADS && THREADS]:
Likewise.
* include/private/gc_hdrs [CPP_WORDSZ!=32 && CPP_WORDSZ<36]: Likewise.
* include/private/gc_priv.h [!HBLKSIZE]: Likewise.
* pthread_stop_world.c [!NSIG]: Likewise.
Ivan Maidanski [Wed, 5 Oct 2016 22:12:55 +0000 (01:12 +0300)]
Workaround '#error' cppcheck error messages
* extra/msvc_dbg.c (GetStackFramesFromContext): Skip #error pragma
if CPPCHECK.
* include/private/gcconfig.h [sun && mc68000]: Likewise.
* include/private/gcconfig.h [hp9000s300 || ibm032 || _AUX_SOURCE
|| __pj__]: Likewise.
* include/private/gcconfig.h [!mach_type_known]: Likewise.
* include/private/gcconfig.h [HEXAGON && LINUX && !__ELF__]: Likewise.
* include/private/gcconfig.h [!ALIGNMENT || !STACKBOTTOM]: Likewise.
* os_dep.c [USE_MUNMAP && !USE_MMAP]: Likewise.
* os_dep.c [MPROTECT_VDB && DARWIN && !ARM32 && !AARCH64 && !POWERPC
&& !I386]: Likewise.
Ivan Maidanski [Wed, 5 Oct 2016 20:58:00 +0000 (23:58 +0300)]
Eliminate 'scope of variable can be reduced' cppcheck warning in allchblk
* allchblk.c [USE_MUNMAP] (GC_merge_unmapped): Move local variable
declarations to the inner scope where the variables are actually used.
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.
Ivan Maidanski [Tue, 4 Oct 2016 20:27:53 +0000 (23:27 +0300)]
Eliminate more 'scope of variable can be reduced' cppcheck style warnings
* allchblk.c (GC_compute_large_free_bytes, GC_print_hblkfreelist,
free_list_index_of, GC_dump_regions, GC_add_to_fl, GC_unmap_old,
GC_allochblk_nth): Move local variable declaration to the inner scope
where the variable is actually used.
* alloc.c (GC_maybe_gc, GC_collect_a_little_inner, GC_set_fl_marks,
GC_clear_fl_marks): Likewise.
* dyn_load.c (GC_register_dynamic_libraries): Likewise.
* finalize.c (GC_ignore_self_finalize_mark_proc,
GC_register_finalizer_inner, GC_dump_finalization_links,
GC_dump_finalization, GC_make_disappearing_links_disappear,
GC_remove_dangling_disappearing_links, GC_invoke_finalizers): Likewise.
* headers.c (GC_install_counts): Likewise.
* malloc.c (GC_malloc_kind_global, GC_generic_malloc_uncollectable,
GC_free): Likewise.
* mark.c (GC_push_all_eager, GC_push_marked1, GC_push_marked2,
GC_push_marked4): Likewise.
* mark_rts.c (GC_next_exclusion, GC_exclude_static_roots_inner,
GC_push_conditional_with_exclusions): Likewise.
* misc.c (GC_base, GC_parse_mem_size_arg, GC_write): Likewise.
* os_dep.c (GC_repeat_read, GC_get_maps, GC_least_described_address,
GC_register_root_section, GC_register_data_segments): Likewise.
* reclaim.c (GC_reclaim_block, GC_start_reclaim): Likewise.
* finalize.c (ITERATE_DL_HASHTBL_BEGIN): Declare prev_dl local variable.
Ivan Maidanski [Tue, 4 Oct 2016 07:28:18 +0000 (10:28 +0300)]
Eliminate 'potential overflow' static analyzer warning in test
* tests/subthread_create.c (entry): Replace (int)(int_v1 - uint_v2)
expression with int_v1 - (int)uint_v2.
Ivan Maidanski [Mon, 3 Oct 2016 20:34:56 +0000 (23:34 +0300)]
Workaround 'mmap() resource handle leak' static analyzer warning
* 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 [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).