diff mbox series

[v3,09/16] semihosting: Clean up global variable shadowing

Message ID 20231004120019.93101-10-philmd@linaro.org
State Superseded
Headers show
Series (few more) Steps towards enabling -Wshadow | expand

Commit Message

Philippe Mathieu-Daudé Oct. 4, 2023, noon UTC
Fix:

  semihosting/config.c:134:49: error: declaration shadows a variable in the global scope [-Werror,-Wshadow]
  int qemu_semihosting_config_options(const char *optarg)
                                                  ^
  /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/getopt.h:77:14: note: previous declaration is here
  extern char *optarg;                    /* getopt(3) external variables */
               ^

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/semihosting/semihost.h | 2 +-
 semihosting/config.c           | 8 ++++----
 stubs/semihost.c               | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

Comments

Alex Bennée Oct. 4, 2023, 12:16 p.m. UTC | #1
Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> Fix:
>
>   semihosting/config.c:134:49: error: declaration shadows a variable in the global scope [-Werror,-Wshadow]
>   int qemu_semihosting_config_options(const char *optarg)
>                                                   ^
>   /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/getopt.h:77:14: note: previous declaration is here
>   extern char *optarg;                    /* getopt(3) external
>   variables */

I'm going to assume the getopt.h is somehow swept up by osdep.h?

Anyway:

Acked-by: Alex Bennée <alex.bennee@linaro.org>
Thomas Huth Oct. 4, 2023, 12:33 p.m. UTC | #2
On 04/10/2023 14.16, Alex Bennée wrote:
> 
> Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> 
>> Fix:
>>
>>    semihosting/config.c:134:49: error: declaration shadows a variable in the global scope [-Werror,-Wshadow]
>>    int qemu_semihosting_config_options(const char *optarg)
>>                                                    ^
>>    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/getopt.h:77:14: note: previous declaration is here
>>    extern char *optarg;                    /* getopt(3) external
>>    variables */
> 
> I'm going to assume the getopt.h is somehow swept up by osdep.h?
> 
> Anyway:
> 
> Acked-by: Alex Bennée <alex.bennee@linaro.org>

Could we maybe rather remove getopt.h from osdep.h instead of renaming this 
everywhere? getopt.h should only be required by some few files, so including 
this in osdep.h seems exaggerated, IMHO.

  Thomas
Markus Armbruster Oct. 4, 2023, 12:34 p.m. UTC | #3
Alex Bennée <alex.bennee@linaro.org> writes:

> Philippe Mathieu-Daudé <philmd@linaro.org> writes:
>
>> Fix:
>>
>>   semihosting/config.c:134:49: error: declaration shadows a variable in the global scope [-Werror,-Wshadow]
>>   int qemu_semihosting_config_options(const char *optarg)
>>                                                   ^
>>   /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/getopt.h:77:14: note: previous declaration is here
>>   extern char *optarg;                    /* getopt(3) external
>>   variables */
>
> I'm going to assume the getopt.h is somehow swept up by osdep.h?

It comes from unitstd.h via osdep.h.  getopt.h provides getopt_long() &
friends.
>
> Anyway:
>
> Acked-by: Alex Bennée <alex.bennee@linaro.org>
diff mbox series

Patch

diff --git a/include/semihosting/semihost.h b/include/semihosting/semihost.h
index efd2efa25a..97d2a2ba99 100644
--- a/include/semihosting/semihost.h
+++ b/include/semihosting/semihost.h
@@ -66,7 +66,7 @@  const char *semihosting_get_cmdline(void);
 void semihosting_arg_fallback(const char *file, const char *cmd);
 /* for vl.c hooks */
 void qemu_semihosting_enable(void);
-int qemu_semihosting_config_options(const char *opt);
+int qemu_semihosting_config_options(const char *optstr);
 void qemu_semihosting_chardev_init(void);
 void qemu_semihosting_console_init(Chardev *);
 #endif /* CONFIG_USER_ONLY */
diff --git a/semihosting/config.c b/semihosting/config.c
index 8ca569735d..e826457733 100644
--- a/semihosting/config.c
+++ b/semihosting/config.c
@@ -131,10 +131,10 @@  void qemu_semihosting_enable(void)
     semihosting.target = SEMIHOSTING_TARGET_AUTO;
 }
 
-int qemu_semihosting_config_options(const char *optarg)
+int qemu_semihosting_config_options(const char *optstr)
 {
     QemuOptsList *opt_list = qemu_find_opts("semihosting-config");
-    QemuOpts *opts = qemu_opts_parse_noisily(opt_list, optarg, false);
+    QemuOpts *opts = qemu_opts_parse_noisily(opt_list, optstr, false);
 
     semihosting.enabled = true;
 
@@ -155,7 +155,7 @@  int qemu_semihosting_config_options(const char *optarg)
                 semihosting.target = SEMIHOSTING_TARGET_AUTO;
             } else {
                 error_report("unsupported semihosting-config %s",
-                             optarg);
+                             optstr);
                 return 1;
             }
         } else {
@@ -165,7 +165,7 @@  int qemu_semihosting_config_options(const char *optarg)
         qemu_opt_foreach(opts, add_semihosting_arg,
                          &semihosting, NULL);
     } else {
-        error_report("unsupported semihosting-config %s", optarg);
+        error_report("unsupported semihosting-config %s", optstr);
         return 1;
     }
 
diff --git a/stubs/semihost.c b/stubs/semihost.c
index aad7a70353..b3c61935b3 100644
--- a/stubs/semihost.c
+++ b/stubs/semihost.c
@@ -36,7 +36,7 @@  void qemu_semihosting_enable(void)
 {
 }
 
-int qemu_semihosting_config_options(const char *optarg)
+int qemu_semihosting_config_options(const char *optstr)
 {
     return 1;
 }