[Libguestfs] [nbdkit PATCH 01/10] server: Avoid -Wshadow warnings

Eric Blake eblake at redhat.com
Sun Sep 1 02:29:38 UTC 2019


None of these shadowing instances appear to misbehave, but it's
confusing to tell if code intentionally meant for a tighter scope to
override a broader one.

Signed-off-by: Eric Blake <eblake at redhat.com>
---
 server/internal.h                    |  2 +-
 server/connections.c                 |  2 +-
 server/main.c                        | 23 +++++++++++------------
 server/protocol-handshake-newstyle.c |  7 +++----
 server/protocol.c                    |  4 ++--
 5 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/server/internal.h b/server/internal.h
index 72333599..fdafe22c 100644
--- a/server/internal.h
+++ b/server/internal.h
@@ -93,7 +93,7 @@ extern enum log_to log_to;
 extern bool newstyle;
 extern bool no_sr;
 extern const char *port;
-extern bool readonly;
+extern bool read_only;
 extern const char *run;
 extern bool listen_stdin;
 extern const char *selinux_label;
diff --git a/server/connections.c b/server/connections.c
index 8d5c81af..b5827648 100644
--- a/server/connections.c
+++ b/server/connections.c
@@ -149,7 +149,7 @@ _handle_single_connection (int sockin, int sockout)
     goto done;

   lock_request (conn);
-  r = backend_open (backend, conn, readonly);
+  r = backend_open (backend, conn, read_only);
   unlock_request (conn);
   if (r == -1)
     goto done;
diff --git a/server/main.c b/server/main.c
index 6999818c..22cf8d33 100644
--- a/server/main.c
+++ b/server/main.c
@@ -71,7 +71,7 @@ bool newstyle = true;           /* false = -o, true = -n */
 bool no_sr;                     /* --no-sr */
 char *pidfile;                  /* -P */
 const char *port;               /* -p */
-bool readonly;                  /* -r */
+bool read_only;                 /* -r */
 const char *run;                /* --run */
 bool listen_stdin;              /* -s */
 const char *selinux_label;      /* --selinux-label */
@@ -139,9 +139,9 @@ main (int argc, char *argv[])
   int c;
   bool help = false, version = false, dump_plugin = false;
   int tls_set_on_cli = false;
-  int short_name;
+  bool short_name;
   const char *filename;
-  char *p;
+  char *p, *q;
   static struct filter_filename {
     struct filter_filename *next;
     const char *filename;
@@ -182,7 +182,6 @@ main (int argc, char *argv[])
     switch (c) {
     case 'D':
       {
-        const char *p, *q;
         struct debug_flag *flag;

         /* Debug Flag must be "NAME.FLAG=N".
@@ -377,7 +376,7 @@ main (int argc, char *argv[])
       break;

     case 'r':
-      readonly = true;
+      read_only = true;
       break;

     case 's':
@@ -526,7 +525,6 @@ main (int argc, char *argv[])
    * If so we simply execute it with the current command line.
    */
   if (short_name) {
-    size_t i;
     struct stat statbuf;
     CLEANUP_FREE char *script;

@@ -560,8 +558,9 @@ main (int argc, char *argv[])
   i = 1;
   while (filter_filenames) {
     struct filter_filename *t = filter_filenames;
-    const char *filename = t->filename;
-    int short_name = is_short_name (filename);
+
+    filename = t->filename;
+    short_name = is_short_name (filename);

     backend = open_filter_so (backend, i++, filename, short_name);

@@ -687,7 +686,7 @@ static char *
 make_random_fifo (void)
 {
   char template[] = "/tmp/nbdkitXXXXXX";
-  char *unixsocket;
+  char *sock;

   if (mkdtemp (template) == NULL) {
     perror ("mkdtemp");
@@ -705,13 +704,13 @@ make_random_fifo (void)
     return NULL;
   }

-  unixsocket = strdup (random_fifo);
-  if (unixsocket == NULL) {
+  sock = strdup (random_fifo);
+  if (sock == NULL) {
     perror ("strdup");
     return NULL;
   }

-  return unixsocket;
+  return sock;
 }

 static struct backend *
diff --git a/server/protocol-handshake-newstyle.c b/server/protocol-handshake-newstyle.c
index 23579e5d..9ddc3198 100644
--- a/server/protocol-handshake-newstyle.c
+++ b/server/protocol-handshake-newstyle.c
@@ -80,8 +80,7 @@ send_newstyle_option_reply (struct connection *conn,

 static int
 send_newstyle_option_reply_exportname (struct connection *conn,
-                                       uint32_t option, uint32_t reply,
-                                       const char *exportname)
+                                       uint32_t option, uint32_t reply)
 {
   struct fixed_new_option_reply fixed_new_option_reply;
   size_t name_len = strlen (exportname);
@@ -320,8 +319,8 @@ negotiate_handshake_newstyle_options (struct connection *conn)
       /* Send back the exportname. */
       debug ("newstyle negotiation: %s: advertising export '%s'",
              name_of_nbd_opt (option), exportname);
-      if (send_newstyle_option_reply_exportname (conn, option, NBD_REP_SERVER,
-                                                 exportname) == -1)
+      if (send_newstyle_option_reply_exportname (conn, option,
+                                                 NBD_REP_SERVER) == -1)
         return -1;

       if (send_newstyle_option_reply (conn, option, NBD_REP_ACK) == -1)
diff --git a/server/protocol.c b/server/protocol.c
index 948b48ac..29cdcad3 100644
--- a/server/protocol.c
+++ b/server/protocol.c
@@ -263,12 +263,12 @@ handle_request (struct connection *conn,

   case NBD_CMD_CACHE:
     if (conn->emulate_cache) {
-      static char buf[MAX_REQUEST_SIZE]; /* data sink, never read */
+      static char zerobuf[MAX_REQUEST_SIZE]; /* data sink, never read */
       uint32_t limit;

       while (count) {
         limit = MIN (count, sizeof buf);
-        if (backend_pread (backend, conn, buf, limit, offset, flags,
+        if (backend_pread (backend, conn, zerobuf, limit, offset, flags,
                            &err) == -1)
           return err;
         count -= limit;
-- 
2.21.0




More information about the Libguestfs mailing list