On Mon, Sep 19, 2022 at 03:35:04PM +0200, Laszlo Ersek wrote:
> The statement
> 
>   if (!test_disk) { /* block A */ } else { /* block B */ }
> 
> is needlessly complex; drop the logical negation in exchange for
> reordering the branches:
> 
>   if (test_disk) { /* block B */ } else { /* block A */ }
> 
> While at it, fix a typo in an error message in the same context.
> 
> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2124538
> Signed-off-by: Laszlo Ersek <ler...@redhat.com>
> ---
>  main.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/main.c b/main.c
> index a83de71b7c73..48603e5c54b1 100644
> --- a/main.c
> +++ b/main.c
> @@ -327,20 +327,20 @@ set_config_defaults (struct config *config)
>    get_rtc_config (&config->rtc);
>  
>    /* Find all block devices in the system. */
> -  if (!test_disk)
> -    find_all_disks ();
> -  else {
> +  if (test_disk) {
>      /* For testing and debugging purposes, you can use
>       * --test-disk=/path/to/disk.img
>       */
>      all_disks = malloc (2 * sizeof (char *));
>      if (all_disks == NULL)
> -      error (EXIT_FAILURE, errno, "realloc");
> +      error (EXIT_FAILURE, errno, "malloc");
>      all_disks[0] = strdup (test_disk);
>      if (all_disks[0] == NULL)
>        error (EXIT_FAILURE, errno, "strdup");
>      all_disks[1] = NULL;
> -  }
> +  } else
> +    find_all_disks ();
> +
>    if (all_disks)
>      config->disks = guestfs_int_copy_string_list (all_disks);

This is not wrong, but I'll note why it was done this way originally.
It's to keep the ordinary path first and the test path (only used by a
make check-* rule) second.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top
_______________________________________________
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs

Reply via email to