From: Ivan Maidanski Date: Wed, 11 Jul 2018 06:07:30 +0000 (+0300) Subject: Fix 'pointer arithmetic with NULL' code defect in print_callers X-Git-Tag: v7.6.8~30 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5aea4756c97ac2aea1d231c417387503b853d68c;p=gc Fix 'pointer arithmetic with NULL' code defect in print_callers * os_dep.c [NEED_CALLINFO && LINUX && !SMALL_CONFIG] (GC_print_callers): If nl is null then pass result_len (instead of nl-result_buf) to strncmp; adjust code indentation. --- diff --git a/os_dep.c b/os_dep.c index 57a6b2e4..1be3009a 100644 --- a/os_dep.c +++ b/os_dep.c @@ -4721,14 +4721,16 @@ GC_INNER void GC_print_callers(struct callinfo info[NFRAMES]) } /* Get rid of embedded newline, if any. Test for "main" */ { - char * nl = strchr(result_buf, '\n'); - if (nl != NULL - && (word)nl < (word)(result_buf + result_len)) { - *nl = ':'; - } - if (strncmp(result_buf, "main", nl - result_buf) == 0) { - stop = TRUE; - } + char * nl = strchr(result_buf, '\n'); + if (nl != NULL + && (word)nl < (word)(result_buf + result_len)) { + *nl = ':'; + } + if (strncmp(result_buf, "main", + nl != NULL ? (size_t)(nl - result_buf) + : result_len) == 0) { + stop = TRUE; + } } if (result_len < RESULT_SZ - 25) { /* Add in hex address */