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: v8.0.0~79 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c88c621500984442369e0ae4ceeec54cfb9a6ce4;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 3a531955..a4b5e86b 100644 --- a/os_dep.c +++ b/os_dep.c @@ -4801,14 +4801,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 */