Skip to contentSkip to conversation

Fix two shadow compiler warnings

PATCH In review Brian Haley 2 participants 3 messages Aug 15, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix two shadow compiler warnings

CC fd-files.o
fd-files.c: In function ‘list_to_index’:
fd-files.c:216:15: warning: declaration of ‘index’ shadows a global declaration [-Wshadow]
CC fds.o
fds.c: In function ‘process_disable_fds_param’:
fds.c:164:38: warning: declaration of ‘optarg’ shadows a global declaration [-Wshadow]

---
 fd-files.c |    8 ++++----
 fds.c      |   14 +++++++-------
 2 files changed, 11 insertions(+), 11 deletions(-)
fd-files.c +4 -4
index 6e0e37d..59dce01 100644
@@ -213,14 +213,14 @@ static const char ** list_to_index(struct namelist *namelist)
 {
 	struct list_head *node, *tmp;
 	struct namelist *nl;
-	const char **index;
+	const char **findex;
 	unsigned int i = 0;
 
-	index = zmalloc(sizeof(char *) * files_in_index);
+	findex = zmalloc(sizeof(char *) * files_in_index);
 
 	list_for_each_safe(node, tmp, &namelist->list) {
 		nl = (struct namelist *) node;
-		index[i++] = nl->name;
+		findex[i++] = nl->name;
 
 		/* Destroy the list head, but keep the ->name alloc because
 		 * now the index points to it.
@@ -232,7 +232,7 @@ static const char ** list_to_index(struct namelist *namelist)
 	free(names);
 	names = NULL;
 
-	return index;
+	return findex;
 }
 
 static void generate_filelist(void)
fds.c +7 -7
index ad963f9..79febcd 100644
@@ -161,23 +161,23 @@ static void disable_fds_param(char *str)
 	exit(EXIT_FAILURE);
 }
 
-void process_disable_fds_param(char *optarg)
+void process_disable_fds_param(char *param)
 {
 	unsigned int len, i;
-	char *str = optarg;
+	char *str = param;
 
-	len = strlen(optarg);
+	len = strlen(param);
 
 	/* Check if there are any commas. If so, split them into multiple params,
 	 * validating them as we go.
 	 */
 	for (i = 0; i < len; i++) {
-		if (optarg[i] == ',') {
-			optarg[i] = 0;
+		if (param[i] == ',') {
+			param[i] = 0;
 			disable_fds_param(str);
-			str = optarg + i + 1;
+			str = param + i + 1;
 		}
 	}
-	if (str < optarg + len)
+	if (str < param + len)
 		disable_fds_param(str);
 }
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 6 lines · Brian Haley

CC fd-files.o
fd-files.c: In function ‘list_to_index’:
fd-files.c:216:15: warning: declaration of ‘index’ shadows a global declaration [-Wshadow]
CC fds.o
fds.c: In function ‘process_disable_fds_param’:
fds.c:164:38: warning: declaration of ‘optarg’ shadows a global declaration [-Wshadow]

ugh, what gcc is that with ?
It seems 4.9.1 is smart enough to figure out that isn't a problem.

I'll apply the patch though.

Dave

#2 lore raw
Quoted 10 lines · Dave Jones
Quoted 6 lines · Brian Haley

CC fd-files.o
fd-files.c: In function ‘list_to_index’:
fd-files.c:216:15: warning: declaration of ‘index’ shadows a global declaration [-Wshadow]
CC fds.o
fds.c: In function ‘process_disable_fds_param’:
fds.c:164:38: warning: declaration of ‘optarg’ shadows a global declaration [-Wshadow]

ugh, what gcc is that with ?
It seems 4.9.1 is smart enough to figure out that isn't a problem.

My old 12.04.5 LTS system:

gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

-Brian