This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]