unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] manual: Fix backtraces code example [BZ #10441]
@ 2020-03-10 16:10 Girish Joshi
  2020-03-25 17:59 ` Girish Joshi via Libc-alpha
  2020-04-01 20:34 ` DJ Delorie via Libc-alpha
  0 siblings, 2 replies; 7+ messages in thread
From: Girish Joshi @ 2020-03-10 16:10 UTC (permalink / raw)
  To: libc-alpha

From bd99113d312012bde774a66c36b4894355175661 Mon Sep 17 00:00:00 2001
From: Girish Joshi <girish946@gmail.com>
Date: Tue, 10 Mar 2020 17:15:08 +0530
Subject: [PATCH] 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.
---
 manual/examples/execinfo.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/manual/examples/execinfo.c b/manual/examples/execinfo.c
index a789b6b5a7..01fd2d2dc2 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)
+  {

-  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);
 }
-- 
2.21.1


Girish Joshi

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-05-29 13:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-10 16:10 [PATCH] manual: Fix backtraces code example [BZ #10441] Girish Joshi
2020-03-25 17:59 ` Girish Joshi via Libc-alpha
2020-04-01 20:34 ` DJ Delorie via Libc-alpha
2020-04-03 12:06   ` Girish Joshi via Libc-alpha
2020-05-07 19:56     ` Girish Joshi via Libc-alpha
2020-05-23 10:09       ` Girish Joshi via Libc-alpha
2020-05-29 13:08         ` Adhemerval Zanella via Libc-alpha

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).