This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[LIBIBERTY]: Add -Wwrite-strings -Wstrict-prototypes and fix warnings


This patch adds -Wwrite-strings -Wstrict-prototypes to the libiberty
flags when using GCC.  These flags have long been hardcoded into
stage1 for the gcc directory, so we would have heard by now if some
old version of GCC didn't support them.  Therefore I also hardcoded
them into libiberty.

I also cleaned up a few warnings, some of which were exposed by the
new flags.

Finally I noticed that unrelated to my patch, config.in was out of
date.  I regenerated that also.

Tested by C-only bootstrap on x86_64-unknown-linux-gnu.  Since glibc
has all these functions, none of these files were included.  So I also
did a "make -k testlib.a" to get all the files.  Unrelated to my
patch, I found that gettimeofday.c and the non-unix pex-*.c files
didn't build, but it looks like there's not much we can do about that.
The files I patched compile cleanly.

Okay for mainline?

		Thanks,
		--Kaveh


2005-04-02  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* configure.ac (ac_libiberty_warn_cflags): Add -Wwrite-strings
	-Wstrict-prototypes.
	* configure, config.in: Regenerate.

	* bsearch.c, index.c, rindex.c, strstr.c, strtol.c, waitpid.c: Fix
	warnings and reconcile interfaces with relevant standards.

diff -rup orig/egcc-CVS20050401/libiberty/configure.ac egcc-CVS20050401/libiberty/configure.ac
--- orig/egcc-CVS20050401/libiberty/configure.ac	2005-03-28 21:11:52.000000000 -0500
+++ egcc-CVS20050401/libiberty/configure.ac	2005-04-02 11:47:00.545877440 -0500
@@ -114,7 +114,7 @@ AC_PROG_CC
 AC_PROG_CPP_WERROR
 
 if test x$GCC = xyes; then
-  ac_libiberty_warn_cflags='-W -Wall -pedantic'
+  ac_libiberty_warn_cflags='-W -Wall -pedantic -Wwrite-strings -Wstrict-prototypes'
 fi
 AC_SUBST(ac_libiberty_warn_cflags)
 
diff -rup orig/egcc-CVS20050401/libiberty/bsearch.c egcc-CVS20050401/libiberty/bsearch.c
--- orig/egcc-CVS20050401/libiberty/bsearch.c	2005-03-27 01:10:51.000000000 -0500
+++ egcc-CVS20050401/libiberty/bsearch.c	2005-04-02 11:46:25.982131928 -0500
@@ -79,7 +79,7 @@ bsearch (register const void *key, const
 		p = base + (lim >> 1) * size;
 		cmp = (*compar)(key, p);
 		if (cmp == 0)
-			return (p);
+			return (void *)p;
 		if (cmp > 0) {	/* key > p: move right */
 			base = (const char *)p + size;
 			lim--;
diff -rup orig/egcc-CVS20050401/libiberty/index.c egcc-CVS20050401/libiberty/index.c
--- orig/egcc-CVS20050401/libiberty/index.c	2005-03-27 19:35:00.000000000 -0500
+++ egcc-CVS20050401/libiberty/index.c	2005-04-02 11:46:25.983131776 -0500
@@ -15,7 +15,7 @@ deprecated in new programs in favor of @
 extern char * strchr(const char *, int);
 
 char *
-index (char *s, int c)
+index (const char *s, int c)
 {
   return strchr (s, c);
 }
diff -rup orig/egcc-CVS20050401/libiberty/rindex.c egcc-CVS20050401/libiberty/rindex.c
--- orig/egcc-CVS20050401/libiberty/rindex.c	2005-03-28 08:04:00.000000000 -0500
+++ egcc-CVS20050401/libiberty/rindex.c	2005-04-02 11:46:25.984131624 -0500
@@ -12,10 +12,10 @@ deprecated in new programs in favor of @
 
 */
 
-extern char *strrchr ();
+extern char *strrchr (const char *, int);
 
 char *
-rindex (char *s, int c)
+rindex (const char *s, int c)
 {
   return strrchr (s, c);
 }
diff -rup orig/egcc-CVS20050401/libiberty/strstr.c egcc-CVS20050401/libiberty/strstr.c
--- orig/egcc-CVS20050401/libiberty/strstr.c	2005-03-28 08:04:01.000000000 -0500
+++ egcc-CVS20050401/libiberty/strstr.c	2005-04-02 11:46:25.984131624 -0500
@@ -20,23 +20,22 @@ length, the function returns @var{string
 /* FIXME:  The above description is ANSI compiliant.  This routine has not
    been validated to comply with it.  -fnf */
 
+#include <stddef.h>
+
+extern char *strchr (const char *, int);
+extern int strncmp (const void *, const void *, size_t);
+extern size_t strlen (const char *);
+
 char *
-strstr (char *s1, char *s2)
+strstr (const char *s1, const char *s2)
 {
-  register char *p = s1;
-  extern char *strchr ();
-  extern int strncmp ();
-#if __GNUC__ >= 2
-  extern __SIZE_TYPE__ strlen (const char *);
-#endif
-  register int len = strlen (s2);
+  const char *p = s1;
+  const size_t len = strlen (s2);
 
   for (; (p = strchr (p, *s2)) != 0; p++)
     {
       if (strncmp (p, s2, len) == 0)
-	{
-	  return (p);
-	}
+	return (char *)p;
     }
   return (0);
 }
diff -rup orig/egcc-CVS20050401/libiberty/strtol.c egcc-CVS20050401/libiberty/strtol.c
--- orig/egcc-CVS20050401/libiberty/strtol.c	2005-03-28 08:04:01.000000000 -0500
+++ egcc-CVS20050401/libiberty/strtol.c	2005-04-02 11:46:25.985131472 -0500
@@ -144,7 +144,7 @@ strtol(const char *nptr, char **endptr, 
 			break;
 		if (c >= base)
 			break;
-		if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
 			any = -1;
 		else {
 			any = 1;
diff -rup orig/egcc-CVS20050401/libiberty/waitpid.c egcc-CVS20050401/libiberty/waitpid.c
--- orig/egcc-CVS20050401/libiberty/waitpid.c	2005-03-28 08:04:01.000000000 -0500
+++ egcc-CVS20050401/libiberty/waitpid.c	2005-04-02 11:46:25.985131472 -0500
@@ -13,6 +13,7 @@ does the return value.  The third argume
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
+#include "ansidecl.h"
 
 /* On some systems (such as WindISS), you must include <sys/types.h>
    to get the definition of "pid_t" before you include <sys/wait.h>.  */
@@ -23,7 +24,7 @@ does the return value.  The third argume
 #endif
 
 pid_t
-waitpid (pid_t pid, int *stat_loc, int options)
+waitpid (pid_t pid, int *stat_loc, int options ATTRIBUTE_UNUSED)
 {
   for (;;)
     {
diff -rup orig/egcc-CVS20050401/libiberty/config.in egcc-CVS20050401/libiberty/config.in
--- orig/egcc-CVS20050401/libiberty/config.in	2005-03-25 21:27:35.000000000 -0500
+++ egcc-CVS20050401/libiberty/config.in	2005-04-02 11:54:39.465111112 -0500
@@ -301,6 +301,12 @@
 /* Define to 1 if you have the `vsprintf' function. */
 #undef HAVE_VSPRINTF
 
+/* Define to 1 if you have the `wait3' function. */
+#undef HAVE_WAIT3
+
+/* Define to 1 if you have the `wait4' function. */
+#undef HAVE_WAIT4
+
 /* Define to 1 if you have the `waitpid' function. */
 #undef HAVE_WAITPID
 
diff -rup orig/egcc-CVS20050401/libiberty/configure egcc-CVS20050401/libiberty/configure
--- orig/egcc-CVS20050401/libiberty/configure	2005-03-28 21:11:52.000000000 -0500
+++ egcc-CVS20050401/libiberty/configure	2005-04-02 11:54:36.925497192 -0500
@@ -2930,7 +2930,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 ac_c_preproc_warn_flag=yes
 
 if test x$GCC = xyes; then
-  ac_libiberty_warn_cflags='-W -Wall -pedantic'
+  ac_libiberty_warn_cflags='-W -Wall -pedantic -Wwrite-strings -Wstrict-prototypes'
 fi
 
 
@@ -4888,6 +4888,8 @@ if test "x" = "y"; then
 
 
 
+
+
 for ac_func in asprintf atexit basename bcmp bcopy bsearch bzero calloc clock \
   getcwd getpagesize gettimeofday index insque mkstemps memchr memcmp memcpy \
   memmove mempcpy memset putenv random rename rindex sigsetmask \


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