From 6f07b96cf488db20a4de4f10cea0675743b2621c Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Sun, 1 Jan 2023 01:01:21 +0300 Subject: Fix 'unused crtn var' and 'possible null dereference' cppcheck warnings (fix of commits 7eb49a4e6, 128c0ec3) Issue #362 (bdwgc). * darwin_stop_world.c (GC_stack_range_for): Define crtn local variable only if DARWIN_DONT_PARSE_STACK. * darwin_stop_world.c [DARWIN_DONT_PARSE_STACK && CPPCHECK] (GC_stack_range_for): Call ABORT if p is NULL (before crtn = p->crtn). --- darwin_stop_world.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'darwin_stop_world.c') diff --git a/darwin_stop_world.c b/darwin_stop_world.c index 53824970..c64b4bfb 100644 --- a/darwin_stop_world.c +++ b/darwin_stop_world.c @@ -142,7 +142,9 @@ STATIC ptr_t GC_stack_range_for(ptr_t *phi, thread_act_t thread, GC_thread p, mach_port_t my_thread, ptr_t *paltstack_lo, ptr_t *paltstack_hi, GC_bool *pfound_me) { - GC_stack_context_t crtn; +# ifdef DARWIN_DONT_PARSE_STACK + GC_stack_context_t crtn; +# endif ptr_t lo; if (thread == my_thread) { @@ -327,6 +329,9 @@ STATIC ptr_t GC_stack_range_for(ptr_t *phi, thread_act_t thread, GC_thread p, UNUSED_ARG(paltstack_hi); # else /* p is guaranteed to be non-NULL regardless of GC_query_task_threads. */ +# ifdef CPPCHECK + if (NULL == p) ABORT("Bad GC_stack_range_for call"); +# endif crtn = p -> crtn; *phi = EXPECT((p -> flags & MAIN_THREAD) == 0, TRUE) ? crtn -> stack_end : GC_stackbottom; -- cgit v1.2.1