From: Ivan Maidanski Date: Tue, 18 Oct 2016 09:04:52 +0000 (+0300) Subject: Workaround 'possible null pointer dereference' cppcheck warnings X-Git-Tag: v8.0.0~1100 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dd13a1fc1ef0c374134824dfff8dcf05cdc2069c;p=gc 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. --- diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index e4c4cc45..a23a3e8d 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -482,7 +482,14 @@ typedef char * ptr_t; /* A generic pointer to which we can add */ #endif /* Abandon ship */ -# ifdef PCR +# if defined(SMALL_CONFIG) || defined(PCR) +# define GC_on_abort(msg) (void)0 /* be silent on abort */ +# else + GC_API_PRIV GC_abort_func GC_on_abort; +# endif +# if defined(CPPCHECK) +# define ABORT(msg) { GC_on_abort(msg); abort(); } +# elif defined(PCR) # define ABORT(s) PCR_Base_Panic(s) # else # if defined(MSWINCE) && !defined(DebugBreak) \ @@ -494,11 +501,6 @@ typedef char * ptr_t; /* A generic pointer to which we can add */ /* instead of defining it as a macro). */ # define DebugBreak() _exit(-1) /* there is no abort() in WinCE */ # endif -# ifdef SMALL_CONFIG -# define GC_on_abort(msg) (void)0 /* be silent on abort */ -# else - GC_API_PRIV GC_abort_func GC_on_abort; -# endif /* !SMALL_CONFIG */ # if defined(MSWIN32) && (defined(NO_DEBUGGING) || defined(LINT2)) /* A more user-friendly abort after showing fatal message. */ # define ABORT(msg) (GC_on_abort(msg), _exit(-1)) diff --git a/tests/test.c b/tests/test.c index d9c89973..6c9bef41 100644 --- a/tests/test.c +++ b/tests/test.c @@ -942,11 +942,12 @@ tn * mktree(int n) void chktree(tn *t, int n) { - if (n == 0 && t != 0) { + if (0 == n) { + if (NULL == t) /* is a leaf? */ + return; GC_printf("Clobbered a leaf - collector is broken\n"); FAIL; } - if (n == 0) return; if (t -> level != n) { GC_printf("Lost a node at level %d - collector is broken\n", n); FAIL;