To prevent the future recurrence of some rather serious libc build bugs, such as a macro like strong_alias suddenly turning into an implicit function prototype, I think we should add some warnings and use as much -Werror as possible. (I'm not entirely sure this would have caught the missing strong_alias macro, but it seems like a good idea anyway.)
This adds a (very) few warnings and fixes some of the fallout. The diff is a bit of a mix of things, since I initially tried -Wall before I ran away screaming. Over time, maybe some brave pioneers can expand the frontier. Index: Makefile.inc =================================================================== RCS file: /cvs/src/lib/libc/Makefile.inc,v retrieving revision 1.18 diff -u -p -r1.18 Makefile.inc --- Makefile.inc 28 Mar 2013 16:43:08 -0000 1.18 +++ Makefile.inc 5 Apr 2013 01:22:39 -0000 @@ -13,6 +13,8 @@ CFLAGS+= -I${LIBCSRCDIR}/include # Include link-time warnings about unsafe API uses (ie. strcpy) CFLAGS+=-DAPIWARN +CFLAGS+=-Wimplicit -Wparentheses -Wbounded -Werror + .if (${YP:L} == "yes") CFLAGS+=-DYP -I${LIBCSRCDIR}/yp .endif Index: crypt/crypt2.c =================================================================== RCS file: /cvs/src/lib/libc/crypt/crypt2.c,v retrieving revision 1.3 diff -u -p -r1.3 crypt2.c --- crypt/crypt2.c 8 Aug 2005 08:05:33 -0000 1.3 +++ crypt/crypt2.c 5 Apr 2013 01:22:39 -0000 @@ -59,6 +59,9 @@ extern const u_char _des_bits8[8]; extern const u_int32_t _des_bits32[32]; extern int _des_initialised; +void _des_init(void); +void _des_setup_salt(int32_t salt); +int _des_do_des(u_int32_t , u_int32_t , u_int32_t *, u_int32_t *, int); int setkey(const char *key) Index: gen/getcwd.c =================================================================== RCS file: /cvs/src/lib/libc/gen/getcwd.c,v retrieving revision 1.17 diff -u -p -r1.17 getcwd.c --- gen/getcwd.c 27 May 2006 18:06:29 -0000 1.17 +++ gen/getcwd.c 5 Apr 2013 01:22:39 -0000 @@ -19,6 +19,7 @@ #include <sys/param.h> #include <errno.h> #include <stdlib.h> +#include <unistd.h> int __getcwd(char *buf, size_t len); Index: gen/getgrent.c =================================================================== RCS file: /cvs/src/lib/libc/gen/getgrent.c,v retrieving revision 1.37 diff -u -p -r1.37 getgrent.c --- gen/getgrent.c 25 Apr 2011 20:10:10 -0000 1.37 +++ gen/getgrent.c 5 Apr 2013 01:22:39 -0000 @@ -392,7 +392,7 @@ grscan(int search, gid_t gid, const char goto found_it; default: bp = strsep(&bp, ":\n") + 1; - if (search && name && strcmp(bp, name) || + if ((search && name && strcmp(bp, name)) || __ypexclude_is(&__ypexhead, bp)) continue; r = yp_match(__ypdomain, "group.byname", Index: gen/getgrouplist.c =================================================================== RCS file: /cvs/src/lib/libc/gen/getgrouplist.c,v retrieving revision 1.21 diff -u -p -r1.21 getgrouplist.c --- gen/getgrouplist.c 9 Nov 2009 00:18:27 -0000 1.21 +++ gen/getgrouplist.c 5 Apr 2013 01:22:39 -0000 @@ -202,7 +202,7 @@ getgrouplist(const char *uname, gid_t ag /* Construct the netid key to look up. */ if (getpwnam_r(uname, &pwstore, buf, sizeof buf, NULL) || - !__ypdomain && yp_get_default_domain(&__ypdomain)) + (!__ypdomain && yp_get_default_domain(&__ypdomain))) goto out; asprintf(&key, "unix.%u@%s", pwstore.pw_uid, __ypdomain); if (key == NULL) Index: gen/isatty.c =================================================================== RCS file: /cvs/src/lib/libc/gen/isatty.c,v retrieving revision 1.7 diff -u -p -r1.7 isatty.c --- gen/isatty.c 23 May 2007 18:30:07 -0000 1.7 +++ gen/isatty.c 5 Apr 2013 01:22:39 -0000 @@ -29,6 +29,7 @@ */ #include <termios.h> +#include <unistd.h> int isatty(int fd) Index: gen/readdir_r.c =================================================================== RCS file: /cvs/src/lib/libc/gen/readdir_r.c,v retrieving revision 1.2 diff -u -p -r1.2 readdir_r.c --- gen/readdir_r.c 22 Mar 2012 04:11:53 -0000 1.2 +++ gen/readdir_r.c 5 Apr 2013 01:22:39 -0000 @@ -35,6 +35,8 @@ #include "telldir.h" #include "thread_private.h" +int _readdir_unlocked(DIR *, struct dirent **, int); + int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) { Index: gen/scandir.c =================================================================== RCS file: /cvs/src/lib/libc/gen/scandir.c,v retrieving revision 1.15 diff -u -p -r1.15 scandir.c --- gen/scandir.c 29 Nov 2012 02:15:44 -0000 1.15 +++ gen/scandir.c 5 Apr 2013 01:22:39 -0000 @@ -125,7 +125,8 @@ scandir(const char *dirname, struct dire } closedir(dirp); if (nitems && dcomp != NULL) - qsort(names, nitems, sizeof(struct dirent *), dcomp); + qsort(names, nitems, sizeof(struct dirent *), + (int(*)(const void *, const void *))dcomp); *namelist = names; return (nitems); Index: regex/engine.c =================================================================== RCS file: /cvs/src/lib/libc/regex/engine.c,v retrieving revision 1.15 diff -u -p -r1.15 engine.c --- regex/engine.c 5 Aug 2005 13:03:00 -0000 1.15 +++ regex/engine.c 5 Apr 2013 01:22:39 -0000 @@ -662,6 +662,7 @@ backref(struct match *m, char *start, ch /* "can't happen" */ assert(nope); /* NOTREACHED */ + return NULL; } /* Index: regex/regcomp.c =================================================================== RCS file: /cvs/src/lib/libc/regex/regcomp.c,v retrieving revision 1.21 diff -u -p -r1.21 regcomp.c --- regex/regcomp.c 7 Nov 2011 09:58:27 -0000 1.21 +++ regex/regcomp.c 5 Apr 2013 01:22:39 -0000 @@ -171,8 +171,7 @@ regcomp(regex_t *preg, const char *patte len = strlen((char *)pattern); /* do the mallocs early so failure handling is easy */ - g = (struct re_guts *)malloc(sizeof(struct re_guts) + - (NC-1)*sizeof(cat_t)); + g = (struct re_guts *)malloc(sizeof(struct re_guts)); if (g == NULL) return(REG_ESPACE); p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */ @@ -206,7 +205,7 @@ regcomp(regex_t *preg, const char *patte g->nsub = 0; g->ncategories = 1; /* category 0 is "everything else" */ g->categories = &g->catspace[-(CHAR_MIN)]; - (void) memset((char *)g->catspace, 0, NC*sizeof(cat_t)); + memset(g->catspace, 0, sizeof(g->catspace)); g->backrefs = 0; /* do it */ Index: regex/regex2.h =================================================================== RCS file: /cvs/src/lib/libc/regex/regex2.h,v retrieving revision 1.7 diff -u -p -r1.7 regex2.h --- regex/regex2.h 30 Nov 2004 17:04:23 -0000 1.7 +++ regex/regex2.h 5 Apr 2013 01:22:39 -0000 @@ -149,7 +149,7 @@ struct re_guts { int backrefs; /* does it use back references? */ sopno nplus; /* how deep does it nest +s? */ /* catspace must be last */ - cat_t catspace[1]; /* actually [NC] */ + cat_t catspace[NC]; /* actually [NC] */ }; /* misc utilities */ Index: regex/regexec.c =================================================================== RCS file: /cvs/src/lib/libc/regex/regexec.c,v retrieving revision 1.11 diff -u -p -r1.11 regexec.c --- regex/regexec.c 5 Aug 2005 13:03:00 -0000 1.11 +++ regex/regexec.c 5 Apr 2013 01:22:39 -0000 @@ -140,6 +140,8 @@ regexec(const regex_t *preg, const char regmatch_t pmatch[], int eflags) { struct re_guts *g = preg->re_g; + char *s = (char *)string; /* XXX fucking gcc XXX */ + #ifdef REDEBUG # define GOODFLAGS(f) (f) #else @@ -154,7 +156,7 @@ regexec(const regex_t *preg, const char eflags = GOODFLAGS(eflags); if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags®_LARGE)) - return(smatcher(g, (char *)string, nmatch, pmatch, eflags)); + return(smatcher(g, s, nmatch, pmatch, eflags)); else - return(lmatcher(g, (char *)string, nmatch, pmatch, eflags)); + return(lmatcher(g, s, nmatch, pmatch, eflags)); } Index: regex/regfree.c =================================================================== RCS file: /cvs/src/lib/libc/regex/regfree.c,v retrieving revision 1.7 diff -u -p -r1.7 regfree.c --- regex/regfree.c 5 Aug 2005 13:03:00 -0000 1.7 +++ regex/regfree.c 5 Apr 2013 01:22:39 -0000 @@ -38,6 +38,7 @@ #include <stdio.h> #include <stdlib.h> #include <regex.h> +#include <limits.h> #include "utils.h" #include "regex2.h" Index: rpc/xdr_rec.c =================================================================== RCS file: /cvs/src/lib/libc/rpc/xdr_rec.c,v retrieving revision 1.15 diff -u -p -r1.15 xdr_rec.c --- rpc/xdr_rec.c 1 Sep 2010 14:43:34 -0000 1.15 +++ rpc/xdr_rec.c 5 Apr 2013 01:22:39 -0000 @@ -409,6 +409,7 @@ xdrrec_destroy(XDR *xdrs) mem_free(rstrm, sizeof(RECSTREAM)); } +bool_t __xdrrec_getrec(XDR *xdrs, enum xprt_stat *statp, bool_t expectdata); /* * Exported routines to manage xdr records Index: stdio/fputws.c =================================================================== RCS file: /cvs/src/lib/libc/stdio/fputws.c,v retrieving revision 1.5 diff -u -p -r1.5 fputws.c --- stdio/fputws.c 9 Nov 2009 00:18:27 -0000 1.5 +++ stdio/fputws.c 5 Apr 2013 01:22:39 -0000 @@ -35,6 +35,8 @@ #include <wchar.h> #include "local.h" +wint_t __fputwc_unlock(wchar_t wc, FILE *fp); + int fputws(ws, fp) const wchar_t * __restrict ws; Index: stdio/vfscanf.c =================================================================== RCS file: /cvs/src/lib/libc/stdio/vfscanf.c,v retrieving revision 1.29 diff -u -p -r1.29 vfscanf.c --- stdio/vfscanf.c 18 Jan 2012 14:01:38 -0000 1.29 +++ stdio/vfscanf.c 5 Apr 2013 01:22:39 -0000 @@ -32,6 +32,7 @@ */ #include <ctype.h> +#include <wctype.h> #include <inttypes.h> #include <stdarg.h> #include <stddef.h> Index: stdio/vfwprintf.c =================================================================== RCS file: /cvs/src/lib/libc/stdio/vfwprintf.c,v retrieving revision 1.5 diff -u -p -r1.5 vfwprintf.c --- stdio/vfwprintf.c 26 Jun 2012 14:53:23 -0000 1.5 +++ stdio/vfwprintf.c 5 Apr 2013 01:22:39 -0000 @@ -54,6 +54,8 @@ #include "local.h" #include "fvwrite.h" +wint_t __fputwc_unlock(wchar_t wc, FILE *fp); + union arg { int intarg; unsigned int uintarg; Index: stdio/wcio.h =================================================================== RCS file: /cvs/src/lib/libc/stdio/wcio.h,v retrieving revision 1.1 diff -u -p -r1.1 wcio.h --- stdio/wcio.h 17 Jun 2005 20:40:32 -0000 1.1 +++ stdio/wcio.h 5 Apr 2013 01:22:39 -0000 @@ -76,6 +76,6 @@ do {\ } while (0) #define WCIO_INIT(fp) \ - memset(WCIO_GET(fp), 0, sizeof(struct wchar_io_data)) + memset(&(_EXT(fp)->_wcio), 0, sizeof(struct wchar_io_data)) #endif /*_WCIO_H_*/ Index: stdlib/strtol.c =================================================================== RCS file: /cvs/src/lib/libc/stdlib/strtol.c,v retrieving revision 1.8 diff -u -p -r1.8 strtol.c --- stdlib/strtol.c 18 Nov 2012 04:13:39 -0000 1.8 +++ stdlib/strtol.c 5 Apr 2013 01:22:39 -0000 @@ -54,7 +54,7 @@ strtol(const char *nptr, char **endptr, */ if (base != 0 && (base < 2 || base > 36)) { if (endptr != 0) - *endptr = nptr; + *endptr = (char *)nptr; errno = EINVAL; return 0; } @@ -124,7 +124,7 @@ strtol(const char *nptr, char **endptr, if (any < 0) continue; if (neg) { - if (acc < cutoff || acc == cutoff && c > cutlim) { + if (acc < cutoff || (acc == cutoff && c > cutlim)) { any = -1; acc = LONG_MIN; errno = ERANGE; @@ -134,7 +134,7 @@ strtol(const char *nptr, char **endptr, acc -= c; } } else { - if (acc > cutoff || acc == cutoff && c > cutlim) { + if (acc > cutoff || (acc == cutoff && c > cutlim)) { any = -1; acc = LONG_MAX; errno = ERANGE; Index: stdlib/strtoul.c =================================================================== RCS file: /cvs/src/lib/libc/stdlib/strtoul.c,v retrieving revision 1.7 diff -u -p -r1.7 strtoul.c --- stdlib/strtoul.c 8 Aug 2005 08:05:37 -0000 1.7 +++ stdlib/strtoul.c 5 Apr 2013 01:22:39 -0000 @@ -84,7 +84,7 @@ strtoul(const char *nptr, char **endptr, break; if (any < 0) continue; - if (acc > cutoff || acc == cutoff && c > cutlim) { + if (acc > cutoff || (acc == cutoff && c > cutlim)) { any = -1; acc = ULONG_MAX; errno = ERANGE; Index: termios/tcgetpgrp.c =================================================================== RCS file: /cvs/src/lib/libc/termios/tcgetpgrp.c,v retrieving revision 1.5 diff -u -p -r1.5 tcgetpgrp.c --- termios/tcgetpgrp.c 5 Aug 2005 13:03:00 -0000 1.5 +++ termios/tcgetpgrp.c 5 Apr 2013 01:22:39 -0000 @@ -31,6 +31,7 @@ #include <sys/types.h> #include <sys/ioctl.h> #include <termios.h> +#include <unistd.h> pid_t tcgetpgrp(int fd) Index: termios/tcsetpgrp.c =================================================================== RCS file: /cvs/src/lib/libc/termios/tcsetpgrp.c,v retrieving revision 1.6 diff -u -p -r1.6 tcsetpgrp.c --- termios/tcsetpgrp.c 5 Aug 2005 13:03:00 -0000 1.6 +++ termios/tcsetpgrp.c 5 Apr 2013 01:22:39 -0000 @@ -31,6 +31,7 @@ #include <sys/types.h> #include <sys/ioctl.h> #include <termios.h> +#include <unistd.h> int tcsetpgrp(int fd, pid_t pgrp) Index: time/localtime.c =================================================================== RCS file: /cvs/src/lib/libc/time/localtime.c,v retrieving revision 1.37 diff -u -p -r1.37 localtime.c --- time/localtime.c 25 Apr 2011 13:27:27 -0000 1.37 +++ time/localtime.c 5 Apr 2013 01:22:39 -0000 @@ -268,7 +268,7 @@ settzname(void) #endif /* defined ALTZONE */ #ifdef ALL_STATE if (sp == NULL) { - tzname[0] = tzname[1] = gmt; + tzname[0] = tzname[1] = (char *)gmt; return; } #endif /* defined ALL_STATE */ @@ -321,7 +321,7 @@ const time_t t0; if (TYPE_INTEGRAL(time_t) && TYPE_BIT(time_t) - TYPE_SIGNED(time_t) < SECSPERREPEAT_BITS) return 0; - return t1 - t0 == SECSPERREPEAT; + return (int64_t)t1 - t0 == SECSPERREPEAT; } static int @@ -1414,7 +1414,7 @@ struct tm * const tmp; else { #ifdef ALL_STATE if (gmtptr == NULL) - tmp->TM_ZONE = gmt; + tmp->TM_ZONE = (char *)gmt; else tmp->TM_ZONE = gmtptr->chars; #endif /* defined ALL_STATE */ #ifndef ALL_STATE