[PATCH 05/10] tests/hd-geo-test: Clean up global variable shadowing

Philippe Mathieu-Daudé posted 10 patches 1 year, 1 month ago
Maintainers: John Snow <jsnow@redhat.com>, Thomas Huth <thuth@redhat.com>, Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Tyrone Ting <kfting@nuvoton.com>, Hao Wu <wuhaotsh@google.com>, Fam Zheng <fam@euphon.net>, Stefan Hajnoczi <stefanha@redhat.com>, Kevin Wolf <kwolf@redhat.com>, Alberto Garcia <berto@igalia.com>
[PATCH 05/10] tests/hd-geo-test: Clean up global variable shadowing
Posted by Philippe Mathieu-Daudé 1 year, 1 month ago
Rename the variable to fix:

  tests/qtest/hd-geo-test.c:610:11: error: declaration shadows a variable in the global scope [-Werror,-Wshadow]
      char *img_file_name;
            ^
  tests/qtest/hd-geo-test.c:80:14: note: previous declaration is here
  static char *img_file_name[backend_last];
               ^

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 tests/qtest/hd-geo-test.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
index d08bffad91..e5e28c412d 100644
--- a/tests/qtest/hd-geo-test.c
+++ b/tests/qtest/hd-geo-test.c
@@ -78,6 +78,7 @@ static const CHST hd_chst[backend_last][mbr_last] = {
 };
 
 static char *img_file_name[backend_last];
+static char *qcow2_imgpath;
 
 static const CHST *cur_ide[4];
 
@@ -607,18 +608,17 @@ static TestArgs *create_args(void)
 static void add_drive_with_mbr(TestArgs *args,
                                MBRpartitions mbr, uint64_t sectors)
 {
-    char *img_file_name;
     char part[300];
     int ret;
 
     g_assert(args->n_drives < MAX_DRIVES);
 
-    img_file_name = create_qcow2_with_mbr(mbr, sectors);
+    qcow2_imgpath = create_qcow2_with_mbr(mbr, sectors);
 
-    args->drives[args->n_drives] = img_file_name;
+    args->drives[args->n_drives] = qcow2_imgpath;
     ret = snprintf(part, sizeof(part),
                    "-drive file=%s,if=none,format=qcow2,id=disk%d",
-                   img_file_name, args->n_drives);
+                   qcow2_imgpath, args->n_drives);
     g_assert((0 < ret) && (ret <= sizeof(part)));
     args->argc = append_arg(args->argc, args->argv, ARGV_SIZE, g_strdup(part));
     args->n_drives++;
@@ -1139,6 +1139,10 @@ test_add_done:
             g_free(img_file_name[i]);
         }
     }
+    if (qcow2_imgpath) {
+        unlink(qcow2_imgpath);
+        g_free(qcow2_imgpath);
+    }
 
     return ret;
 }
-- 
2.41.0


Re: [PATCH 05/10] tests/hd-geo-test: Clean up global variable shadowing
Posted by Philippe Mathieu-Daudé 1 year, 1 month ago
On 9/10/23 12:02, Philippe Mathieu-Daudé wrote:
> Rename the variable to fix:
> 
>    tests/qtest/hd-geo-test.c:610:11: error: declaration shadows a variable in the global scope [-Werror,-Wshadow]
>        char *img_file_name;
>              ^
>    tests/qtest/hd-geo-test.c:80:14: note: previous declaration is here
>    static char *img_file_name[backend_last];
>                 ^
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   tests/qtest/hd-geo-test.c | 12 ++++++++----
>   1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
> index d08bffad91..e5e28c412d 100644
> --- a/tests/qtest/hd-geo-test.c
> +++ b/tests/qtest/hd-geo-test.c
> @@ -78,6 +78,7 @@ static const CHST hd_chst[backend_last][mbr_last] = {
>   };
>   
>   static char *img_file_name[backend_last];
> +static char *qcow2_imgpath;
>   
>   static const CHST *cur_ide[4];
>   
> @@ -607,18 +608,17 @@ static TestArgs *create_args(void)
>   static void add_drive_with_mbr(TestArgs *args,
>                                  MBRpartitions mbr, uint64_t sectors)
>   {
> -    char *img_file_name;
>       char part[300];
>       int ret;
>   
>       g_assert(args->n_drives < MAX_DRIVES);
>   
> -    img_file_name = create_qcow2_with_mbr(mbr, sectors);
> +    qcow2_imgpath = create_qcow2_with_mbr(mbr, sectors);
>   
> -    args->drives[args->n_drives] = img_file_name;
> +    args->drives[args->n_drives] = qcow2_imgpath;
>       ret = snprintf(part, sizeof(part),
>                      "-drive file=%s,if=none,format=qcow2,id=disk%d",
> -                   img_file_name, args->n_drives);
> +                   qcow2_imgpath, args->n_drives);
>       g_assert((0 < ret) && (ret <= sizeof(part)));
>       args->argc = append_arg(args->argc, args->argv, ARGV_SIZE, g_strdup(part));
>       args->n_drives++;
> @@ -1139,6 +1139,10 @@ test_add_done:
>               g_free(img_file_name[i]);
>           }
>       }
> +    if (qcow2_imgpath) {
> +        unlink(qcow2_imgpath);
> +        g_free(qcow2_imgpath);

Oops I squashed this part while rebasing, this was supposed to
be a different patch.

> +    }
>   
>       return ret;
>   }