From: Girish Joshi Date: Fri, 29 May 2020 13:06:53 +0000 (-0300) Subject: manual: Fix backtraces code example [BZ #10441] X-Git-Tag: glibc-2.32~281 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5d5b3bd94ceebe13d54a6e0cc9e2a899adbbc56f;p=thirdparty%2Fglibc.git manual: Fix backtraces code example [BZ #10441] Validation for pointer returned by backtrace_symbols () added. Type of variables size and i is changed from size_t to int. Variable size is used to collect the result from backtrace () that is an int. i is the loop counter variable so it can be an int. Since, size_t size is changed to int size, in printf %zd is changed to %d. Reviewed-by: DJ Delorie --- diff --git a/manual/examples/execinfo.c b/manual/examples/execinfo.c index a789b6b5a77..3cedf7f35f3 100644 --- a/manual/examples/execinfo.c +++ b/manual/examples/execinfo.c @@ -24,17 +24,18 @@ void print_trace (void) { void *array[10]; - size_t size; char **strings; - size_t i; + int size, i; size = backtrace (array, 10); strings = backtrace_symbols (array, size); + if (strings != NULL) + { - printf ("Obtained %zd stack frames.\n", size); - - for (i = 0; i < size; i++) - printf ("%s\n", strings[i]); + printf ("Obtained %d stack frames.\n", size); + for (i = 0; i < size; i++) + printf ("%s\n", strings[i]); + } free (strings); }