diff mbox series

manual: Fix backtraces code example [BZ #10441]

Message ID CALkY8p8uOzKkX80a-gw9eoHfTios2Q2fLu33po-NyFhTGDcUeQ@mail.gmail.com
State New
Headers show
Series manual: Fix backtraces code example [BZ #10441] | expand

Commit Message

Girish Joshi March 10, 2020, 4:10 p.m. UTC
>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(-)

Comments

Girish Joshi March 25, 2020, 5:59 p.m. UTC | #1
Ping.

Girish Joshi


On Tue, Mar 10, 2020 at 9:40 PM Girish Joshi <girish946@gmail.com> wrote:
>
> 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
Girish Joshi April 3, 2020, 12:06 p.m. UTC | #2
Thanks DJ.

Girish Joshi
Girish Joshi May 7, 2020, 7:56 p.m. UTC | #3
If this patch is okay, could someone please push it?
Thanks.

Girish Joshi
Girish Joshi May 23, 2020, 10:09 a.m. UTC | #4
ping.

Girish Joshi


On Fri, May 8, 2020 at 1:26 AM Girish Joshi <girish946@gmail.com> wrote:
>
> If this patch is okay, could someone please push it?
> Thanks.
>
> Girish Joshi
Adhemerval Zanella May 29, 2020, 1:08 p.m. UTC | #5
On 23/05/2020 07:09, Girish Joshi via Libc-alpha wrote:
> ping.
> 
> Girish Joshi
> 
> 
> On Fri, May 8, 2020 at 1:26 AM Girish Joshi <girish946@gmail.com> wrote:
>>
>> If this patch is okay, could someone please push it?
>> Thanks.
>>
>> Girish Joshi

I pushed upstream with DJ suggestion.
diff mbox series

Patch

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