bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

relocatable: avoid compiler warnings (-Wshadow)


From: Akim Demaille
Subject: relocatable: avoid compiler warnings (-Wshadow)
Date: Wed, 23 Jan 2019 22:33:20 +0100

Hi,

This is to avoid warnings such as:

bison/lib/relocatable.c: In function 'compute_curr_prefix':
bison/lib/relocatable.c:285:14: warning: declaration of 'curr_prefix_len' 
shadows a global declaration [-Wshadow]
       size_t curr_prefix_len = cp - curr_installdir;
              ^~~~~~~~~~~~~~~
bison/lib/relocatable.c:114:15: note: shadowed declaration is here
 static size_t curr_prefix_len;
               ^~~~~~~~~~~~~~~
bison/lib/relocatable.c:286:13: warning: declaration of 'curr_prefix' shadows a 
global declaration [-Wshadow]
       char *curr_prefix;
             ^~~~~~~~~~~
bison/lib/relocatable.c:113:14: note: shadowed declaration is here
 static char *curr_prefix;
              ^~~~~~~~~~~

Cheers!

commit d581caa884552a2f14ed17e96649336a4f6ca59e
Author: Akim Demaille <address@hidden>
Date:   Wed Jan 23 22:29:44 2019 +0100

    relocatable: avoid compiler warnings (-Wshadow)
    
    * lib/relocatable.c (compute_curr_prefix): Rename local variables
    to avoid name collisions with global variables.

diff --git a/ChangeLog b/ChangeLog
index f3972fd08..2fccadb5e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-01-23  Akim Demaille  <address@hidden>
+
+       relocatable: avoid compiler warnings (-Wshadow).
+       * lib/relocatable.c (compute_curr_prefix): Rename local variables
+       to avoid name collisions with global variables.
+
 2019-01-22  Bruno Haible  <address@hidden>
 
        vasnprintf: Don't use %n on Android.
diff --git a/lib/relocatable.c b/lib/relocatable.c
index 17cdb6590..033c44139 100644
--- a/lib/relocatable.c
+++ b/lib/relocatable.c
@@ -282,23 +282,21 @@ compute_curr_prefix (const char *orig_installprefix,
       }
 
     {
-      size_t curr_prefix_len = cp - curr_installdir;
-      char *curr_prefix;
-
-      curr_prefix = (char *) xmalloc (curr_prefix_len + 1);
+      size_t prefix_len = cp - curr_installdir;
+      char *prefix = (char *) xmalloc (prefix_len + 1);
 #ifdef NO_XMALLOC
-      if (curr_prefix == NULL)
+      if (prefix == NULL)
         {
           free (curr_installdir);
           return NULL;
         }
 #endif
-      memcpy (curr_prefix, curr_installdir, curr_prefix_len);
-      curr_prefix[curr_prefix_len] = '\0';
+      memcpy (prefix, curr_installdir, prefix_len);
+      prefix[prefix_len] = '\0';
 
       free (curr_installdir);
 
-      return curr_prefix;
+      return prefix;
     }
   }
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]