This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Variable scope issue in confstr
- From: Allan McRae <allan at archlinux dot org>
- To: libc-alpha at sourceware dot org
- Date: Sun, 25 Mar 2012 13:00:10 +1000
- Subject: Variable scope issue in confstr
In confstr (posix/confstr.c), the variable restenvs is defined within a
swtich case block and then used outside the switch statement (via
assignment to the variable string). Issues with this are exposed with
gcc-4.7 and -O2.
2012-03-25 Allan McRae <allan@archlinux.org>
* posix/confstr.c: fix variable scope issue.
diff --git a/posix/confstr.c b/posix/confstr.c
index 3c9566d..3ba9e5a 100644
--- a/posix/confstr.c
+++ b/posix/confstr.c
@@ -104,7 +104,7 @@ confstr (name, buf, len)
}
#endif
restenvs[string_len++] = '\0';
- string = restenvs;
+ string = strdup(restenvs);
}
break;
@@ -167,7 +167,7 @@ confstr (name, buf, len)
}
#endif
restenvs[string_len++] = '\0';
- string = restenvs;
+ string = strdup(restenvs);
}
break;
@@ -230,7 +230,7 @@ confstr (name, buf, len)
}
#endif
restenvs[string_len++] = '\0';
- string = restenvs;
+ string = strdup(restenvs);
}
break;