[1/3] Make variable printed bool in info_checkpoints_command

Message ID 20240108152553.4578-2-tdevries@suse.de
State Committed
Headers
Series Two checkpoint fixes |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Tom de Vries Jan. 8, 2024, 3:25 p.m. UTC
  While reading info_checkpoints_command, I noticed variable printed:
...
  const fork_info *printed = NULL;
  ...
  for (const fork_info &fi : fork_list)
    {
      if (requested > 0 && fi.num != requested)
	continue;

      printed = &fi;
      ...
    }
  if (printed == NULL)
...
has pointer type, but is just used as bool.

Make this explicit by changing the variable type to bool.

Tested on x86_64-linux.
---
 gdb/linux-fork.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
  

Comments

Kevin Buettner Jan. 9, 2024, 5:54 p.m. UTC | #1
On Mon,  8 Jan 2024 16:25:51 +0100
Tom de Vries <tdevries@suse.de> wrote:

> While reading info_checkpoints_command, I noticed variable printed:
> ...
>   const fork_info *printed = NULL;
>   ...
>   for (const fork_info &fi : fork_list)
>     {
>       if (requested > 0 && fi.num != requested)
> 	continue;
> 
>       printed = &fi;
>       ...
>     }
>   if (printed == NULL)
> ...
> has pointer type, but is just used as bool.
> 
> Make this explicit by changing the variable type to bool.
> 
> Tested on x86_64-linux.

LGTM.

Approved-By: Kevin Buettner <kevinb@redhat.com>
  

Patch

diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
index 1430ff89fa7..177a012ec08 100644
--- a/gdb/linux-fork.c
+++ b/gdb/linux-fork.c
@@ -583,7 +583,7 @@  info_checkpoints_command (const char *arg, int from_tty)
 {
   struct gdbarch *gdbarch = get_current_arch ();
   int requested = -1;
-  const fork_info *printed = NULL;
+  bool printed = false;
 
   if (arg && *arg)
     requested = (int) parse_and_eval_long (arg);
@@ -592,8 +592,8 @@  info_checkpoints_command (const char *arg, int from_tty)
     {
       if (requested > 0 && fi.num != requested)
 	continue;
+      printed = true;
 
-      printed = &fi;
       if (fi.ptid == inferior_ptid)
 	gdb_printf ("* ");
       else
@@ -623,7 +623,8 @@  info_checkpoints_command (const char *arg, int from_tty)
 
       gdb_putc ('\n');
     }
-  if (printed == NULL)
+
+  if (!printed)
     {
       if (requested > 0)
 	gdb_printf (_("No checkpoint number %d.\n"), requested);