This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
getopt.c: optarg should not be initialized
- From: Christophe Lyon <christophe dot lyon at st dot com>
- To: <newlib at sourceware dot org>
- Date: Tue, 21 Sep 2010 17:53:25 +0200
- Subject: getopt.c: optarg should not be initialized
Hello,
I think that in newlib/libc/stdlib/getopt.c, optarg should not be
initialized (like in glibc).
Otherwise, if the user code contains a non-initialized "optarg" variable
the linker will "magically" pull the whole getopt.o from Newlib, which
is not desirable (especially if the user code actually contains a
redefinition of getopt & co, as it will result in "multiply defined"
errors).
Small patch as follows:
Index: newlib/libc/stdlib/getopt.c
===================================================================
--- newlib/libc/stdlib/getopt.c (revision 637)
+++ newlib/libc/stdlib/getopt.c (working copy)
@@ -103,7 +103,7 @@ typedef enum GETOPT_ORDERING_T
} GETOPT_ORDERING_T;
/* globally-defined variables */
-char *optarg = 0;
+char *optarg;
int optind = 0;
int opterr = 1;
int optopt = '?';
OK?
(There might be more implications I did not consider, so the real patch
may be more complex).
Christophe.