Skip to contentSkip to conversation

qemu-nbd: changes towards enabling -Wshadow=local

PATCH Applied Eric Blake 3 participants 3 messages Sep 22, 2023 – Sep 29, 2023

lore
Share & tools
lore

Eric Blake

author
#0 lore raw

PATCH 1/1 qemu-nbd: changes towards enabling -Wshadow=local

Address all compiler complaints from -Wshadow in qemu-nbd. Several instances of 'int ret' became shadows when commit 4fbec260 added 'ret' at a higher scope in main. More interesting was the 'void *ret' capturing the result of a pthread; where we were conceptually doing '(void*)(intptr_t)EXIT_FAILURE != NULL' which just feels wrong (even though it happens to compile correctly), so it was worth a better cleanup.

---

I'm happy to let Markus collect this with the growing pile on shadow-next, instead of going through my NBD tree.

 qemu-nbd.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
qemu-nbd.c +4 -5
index 30eeb6f3c75..9bc410c6c56 100644
@@ -937,7 +937,6 @@ int main(int argc, char **argv)
         g_autoptr(GError) err = NULL;
         int stderr_fd[2];
         pid_t pid;
-        int ret;
 
         if (!g_unix_open_pipe(stderr_fd, FD_CLOEXEC, &err)) {
             error_report("Error setting up communication pipe: %s",
@@ -1170,7 +1169,6 @@ int main(int argc, char **argv)
 
     if (opts.device) {
 #if HAVE_NBD_DEVICE
-        int ret;
         ret = pthread_create(&client_thread, NULL, nbd_client_thread, &opts);
         if (ret != 0) {
             error_report("Failed to create client thread: %s", strerror(ret));
@@ -1217,9 +1215,10 @@ int main(int argc, char **argv)
     qemu_opts_del(sn_opts);
 
     if (opts.device) {
-        void *ret;
-        pthread_join(client_thread, &ret);
-        exit(ret != NULL);
+        void *result;
+        pthread_join(client_thread, &result);
+        ret = (intptr_t)result;
+        exit(ret);
     } else {
         exit(EXIT_SUCCESS);
     }
Signature · 1 line
2.41.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Eric Blake

Address all compiler complaints from -Wshadow in qemu-nbd. Several instances of 'int ret' became shadows when commit 4fbec260 added 'ret' at a higher scope in main. More interesting was the 'void *ret' capturing the result of a pthread; where we were conceptually doing '(void*)(intptr_t)EXIT_FAILURE != NULL' which just feels wrong (even though it happens to compile correctly), so it was worth a better cleanup.

Quoted 8 lines

---

I'm happy to let Markus collect this with the growing pile on shadow-next, instead of going through my NBD tree.

 qemu-nbd.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#2 lore raw
In reply to Eric Blake
Quoted 8 lines · Eric Blake

Address all compiler complaints from -Wshadow in qemu-nbd. Several instances of 'int ret' became shadows when commit 4fbec260 added 'ret' at a higher scope in main. More interesting was the 'void *ret' capturing the result of a pthread; where we were conceptually doing '(void*)(intptr_t)EXIT_FAILURE != NULL' which just feels wrong (even though it happens to compile correctly), so it was worth a better cleanup.

Quoted 5 lines

---

I'm happy to let Markus collect this with the growing pile on shadow-next, instead of going through my NBD tree.

Queued, thanks!