]> granicus.if.org Git - gc/commitdiff
Fix 'pointer arithmetic with NULL' code defect in print_callers
authorIvan Maidanski <ivmai@mail.ru>
Wed, 11 Jul 2018 06:07:30 +0000 (09:07 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 11 Jul 2018 06:07:30 +0000 (09:07 +0300)
* 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.

os_dep.c

index 3a53195596ba42b282464e41e542bd9df9f15e7b..a4b5e86bdc56128e61b779b128b4e633d21ccecc 100644 (file)
--- 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 */