This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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]

Fix warning in posix/tst-getopt_long1.c


This patch fixes a "discards qualifiers" warning in
posix/tst-getopt_long1.c.  glibc is built with -Wwrite-strings,
meaning a char * cannot be initialized with a string constant; because
the array of char * gets passed to getopt_long, expecting char *const
*, the array can't be changed to one of const char *, hence the use of
compound literals to provide non-const character arrays initialized
with the strings, as explained in the comment added.

Tested for x86_64.

2014-11-25  Joseph Myers  <joseph@codesourcery.com>

	* posix/tst-getopt_long1.c (do_test): Use compound literals in
	argv array instead of directly using string constants.

diff --git a/posix/tst-getopt_long1.c b/posix/tst-getopt_long1.c
index e0ecd12..daabcc6 100644
--- a/posix/tst-getopt_long1.c
+++ b/posix/tst-getopt_long1.c
@@ -39,7 +39,11 @@ do_test (void)
       return 1;
     }
 
-  char *argv[] = { "program", "--on" };
+  /* Because getopt_long takes a char *const * argument, this array
+     cannot be const char *[]; because glibc uses -Wwrite-strings, the
+     compound literals are needed to provide pointers non-const
+     character arrays, instead of using string literals directly.  */
+  char *argv[] = { (char []) { "program" }, (char []) { "--on" } };
   int argc = 2;
 
   int c = getopt_long (argc, argv, "12345", opts, NULL);

-- 
Joseph S. Myers
joseph@codesourcery.com


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