Browse Source

dtc: fix some more -Wshadow warnings

Building on a RHEL6 system produced the following -Wshadow warnings in
fstree.c, util.c and checks.c:

cc1: warnings being treated as errors
checks.c: In function 'parse_checks_option':
checks.c:709: error: declaration of 'optarg' shadows a global
declaration
/usr/include/getopt.h:59: error: shadowed declaration is here
make[1]: *** [checks.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: *** Waiting for unfinished jobs....
cc1: warnings being treated as errors
fstree.c: In function 'read_fstree':
fstree.c:40: error: declaration of 'tmpnam' shadows a global
declaration
/usr/include/stdio.h:208: error: shadowed declaration is here
make[1]: *** [fstree.o] Error 1
cc1: warnings being treated as errors
util.c: In function 'xstrdup':
util.c:42: error: declaration of 'dup' shadows a global declaration
/usr/include/unistd.h:528: error: shadowed declaration is here

Fix all of these -Wshadow warnings by using slightly different variable
names which won't collide with anything else.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
main
Florian Fainelli 11 years ago committed by David Gibson
parent
commit
24cb3d0681
  1. 10
      checks.c
  2. 2
      dtc.h
  3. 16
      fstree.c
  4. 6
      util.c

10
checks.c

@ -706,15 +706,15 @@ static void disable_warning_error(struct check *c, bool warn, bool error) @@ -706,15 +706,15 @@ static void disable_warning_error(struct check *c, bool warn, bool error)
c->error = c->error && !error;
}

void parse_checks_option(bool warn, bool error, const char *optarg)
void parse_checks_option(bool warn, bool error, const char *arg)
{
int i;
const char *name = optarg;
const char *name = arg;
bool enable = true;

if ((strncmp(optarg, "no-", 3) == 0)
|| (strncmp(optarg, "no_", 3) == 0)) {
name = optarg + 3;
if ((strncmp(arg, "no-", 3) == 0)
|| (strncmp(arg, "no_", 3) == 0)) {
name = arg + 3;
enable = false;
}


2
dtc.h

@ -247,7 +247,7 @@ void sort_tree(struct boot_info *bi); @@ -247,7 +247,7 @@ void sort_tree(struct boot_info *bi);

/* Checks */

void parse_checks_option(bool warn, bool error, const char *optarg);
void parse_checks_option(bool warn, bool error, const char *arg);
void process_checks(bool force, struct boot_info *bi);

/* Flattened trees */

16
fstree.c

@ -37,26 +37,26 @@ static struct node *read_fstree(const char *dirname) @@ -37,26 +37,26 @@ static struct node *read_fstree(const char *dirname)
tree = build_node(NULL, NULL);

while ((de = readdir(d)) != NULL) {
char *tmpnam;
char *tmpname;

if (streq(de->d_name, ".")
|| streq(de->d_name, ".."))
continue;

tmpnam = join_path(dirname, de->d_name);
tmpname = join_path(dirname, de->d_name);

if (lstat(tmpnam, &st) < 0)
die("stat(%s): %s\n", tmpnam, strerror(errno));
if (lstat(tmpname, &st) < 0)
die("stat(%s): %s\n", tmpname, strerror(errno));

if (S_ISREG(st.st_mode)) {
struct property *prop;
FILE *pfile;

pfile = fopen(tmpnam, "r");
pfile = fopen(tmpname, "r");
if (! pfile) {
fprintf(stderr,
"WARNING: Cannot open %s: %s\n",
tmpnam, strerror(errno));
tmpname, strerror(errno));
} else {
prop = build_property(xstrdup(de->d_name),
data_copy_file(pfile,
@ -67,12 +67,12 @@ static struct node *read_fstree(const char *dirname) @@ -67,12 +67,12 @@ static struct node *read_fstree(const char *dirname)
} else if (S_ISDIR(st.st_mode)) {
struct node *newchild;

newchild = read_fstree(tmpnam);
newchild = read_fstree(tmpname);
newchild = name_node(newchild, xstrdup(de->d_name));
add_child(tree, newchild);
}

free(tmpnam);
free(tmpname);
}

closedir(d);

6
util.c

@ -39,11 +39,11 @@ @@ -39,11 +39,11 @@
char *xstrdup(const char *s)
{
int len = strlen(s) + 1;
char *dup = xmalloc(len);
char *d = xmalloc(len);

memcpy(dup, s, len);
memcpy(d, s, len);

return dup;
return d;
}

char *join_path(const char *path, const char *name)

Loading…
Cancel
Save