add -Wundef, fix uncovered bugs

This commit is contained in:
Denis Vlasenko 2006-11-17 20:29:00 +00:00
parent 04c6386c45
commit a7189f01a4
19 changed files with 71 additions and 74 deletions

View File

@ -11,7 +11,7 @@ CPPFLAGS += \
-D_GNU_SOURCE -DNDEBUG \ -D_GNU_SOURCE -DNDEBUG \
$(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \ $(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \
-D"BB_VER=KBUILD_STR($(BB_VER))" -DBB_BT=AUTOCONF_TIMESTAMP \ -D"BB_VER=KBUILD_STR($(BB_VER))" -DBB_BT=AUTOCONF_TIMESTAMP \
-Wall -Wstrict-prototypes -Wshadow -Werror \ -Wall -Wstrict-prototypes -Wshadow -Werror -Wundef \
-funsigned-char -fno-builtin-strlen -finline-limit=0 -static-libgcc \ -funsigned-char -fno-builtin-strlen -finline-limit=0 -static-libgcc \
-Os -falign-functions=1 -falign-jumps=1 -falign-loops=1 \ -Os -falign-functions=1 -falign-jumps=1 -falign-loops=1 \
-fomit-frame-pointer -ffunction-sections -fdata-sections -fomit-frame-pointer -ffunction-sections -fdata-sections

View File

@ -15,7 +15,7 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#if HAVE_ERRNO_H #ifdef HAVE_ERRNO_H
#include <errno.h> #include <errno.h>
#endif #endif
#include <fcntl.h> #include <fcntl.h>

View File

@ -14,20 +14,20 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#if HAVE_SYS_TYPES_H #ifdef HAVE_SYS_TYPES_H
#include <sys/types.h> #include <sys/types.h>
#endif #endif
#include <sys/stat.h> #include <sys/stat.h>
#if HAVE_ERRNO_H #ifdef HAVE_ERRNO_H
#include <errno.h> #include <errno.h>
#endif #endif
#if HAVE_SYS_MKDEV_H #ifdef HAVE_SYS_MKDEV_H
#include <sys/mkdev.h> #include <sys/mkdev.h>
#endif #endif
#include <time.h> #include <time.h>

View File

@ -13,20 +13,20 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if HAVE_SYS_TYPES_H #ifdef HAVE_SYS_TYPES_H
#include <sys/types.h> #include <sys/types.h>
#endif #endif
#include <sys/stat.h> #include <sys/stat.h>
#include <dirent.h> #include <dirent.h>
#if HAVE_ERRNO_H #ifdef HAVE_ERRNO_H
#include <errno.h> #include <errno.h>
#endif #endif
#if HAVE_SYS_MKDEV_H #ifdef HAVE_SYS_MKDEV_H
#include <sys/mkdev.h> #include <sys/mkdev.h>
#endif #endif

View File

@ -12,7 +12,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#if HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <stdlib.h> #include <stdlib.h>

View File

@ -4309,7 +4309,7 @@ static int process_block(ext2_filsys fs,
* Should never happen, since only directories * Should never happen, since only directories
* get called with BLOCK_FLAG_HOLE * get called with BLOCK_FLAG_HOLE
*/ */
#if DEBUG_E2FSCK #ifdef DEBUG_E2FSCK
printf("process_block() called with blk == 0, " printf("process_block() called with blk == 0, "
"blockcnt=%d, inode %lu???\n", "blockcnt=%d, inode %lu???\n",
blockcnt, p->ino); blockcnt, p->ino);

View File

@ -16,15 +16,15 @@
* 93/10/30 - Creation * 93/10/30 - Creation
*/ */
#if HAVE_ERRNO_H #ifdef HAVE_ERRNO_H
#include <errno.h> #include <errno.h>
#endif #endif
#if HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#if HAVE_EXT2_IOCTLS #ifdef HAVE_EXT2_IOCTLS
#include <fcntl.h> #include <fcntl.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#endif #endif
@ -39,7 +39,7 @@
int fgetsetflags (const char * name, unsigned long * get_flags, unsigned long set_flags) int fgetsetflags (const char * name, unsigned long * get_flags, unsigned long set_flags)
{ {
#if HAVE_EXT2_IOCTLS #ifdef HAVE_EXT2_IOCTLS
struct stat buf; struct stat buf;
int fd, r, f, save_errno = 0; int fd, r, f, save_errno = 0;

View File

@ -17,10 +17,10 @@
* 93/10/30 - Creation * 93/10/30 - Creation
*/ */
#if HAVE_ERRNO_H #ifdef HAVE_ERRNO_H
#include <errno.h> #include <errno.h>
#endif #endif
#if HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <fcntl.h> #include <fcntl.h>
@ -44,7 +44,7 @@
int fgetsetversion (const char * name, unsigned long * get_version, unsigned long set_version) int fgetsetversion (const char * name, unsigned long * get_version, unsigned long set_version)
{ {
#if HAVE_EXT2_IOCTLS #ifdef HAVE_EXT2_IOCTLS
int fd, r, ver, save_errno = 0; int fd, r, ver, save_errno = 0;
fd = open (name, OPEN_FLAGS); fd = open (name, OPEN_FLAGS);

View File

@ -13,22 +13,22 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if HAVE_SYS_TYPES_H #ifdef HAVE_SYS_TYPES_H
#include <sys/types.h> #include <sys/types.h>
#endif #endif
#if HAVE_SYS_STAT_H #ifdef HAVE_SYS_STAT_H
#include <sys/stat.h> #include <sys/stat.h>
#endif #endif
#include <dirent.h> #include <dirent.h>
#if HAVE_ERRNO_H #ifdef HAVE_ERRNO_H
#include <errno.h> #include <errno.h>
#endif #endif
#if HAVE_SYS_MKDEV_H #ifdef HAVE_SYS_MKDEV_H
#include <sys/mkdev.h> #include <sys/mkdev.h>
#endif #endif

View File

@ -34,7 +34,7 @@
#endif #endif
#undef inline #undef inline
#if __STDC_VERSION__ > 199901L #if defined(__STDC_VERSION__) && __STDC_VERSION__ > 199901L
/* it's a keyword */ /* it's a keyword */
#else #else
# if __GNUC_PREREQ (2,7) # if __GNUC_PREREQ (2,7)

View File

@ -29,7 +29,7 @@
#include <net/if.h> #include <net/if.h>
#include <net/if_arp.h> #include <net/if_arp.h>
#include <netinet/in.h> #include <netinet/in.h>
#if __GLIBC__ >=2 && __GLIBC_MINOR >= 1 #if __GLIBC__ >=2 && __GLIBC_MINOR__ >= 1
#include <netpacket/packet.h> #include <netpacket/packet.h>
#include <net/ethernet.h> #include <net/ethernet.h>
#else #else

View File

@ -738,7 +738,7 @@ static const struct hwtype loop_hwtype = {
#include <net/if_arp.h> #include <net/if_arp.h>
#if (__GLIBC__ >=2 && __GLIBC_MINOR >= 1) || defined(_NEWLIB_VERSION) #if (__GLIBC__ >=2 && __GLIBC_MINOR__ >= 1) || defined(_NEWLIB_VERSION)
#include <net/ethernet.h> #include <net/ethernet.h>
#else #else
#include <linux/if_ether.h> #include <linux/if_ether.h>

View File

@ -16,7 +16,7 @@
#include "rt_names.h" #include "rt_names.h"
#include "utils.h" #include "utils.h"
#if __GLIBC__ >=2 && __GLIBC_MINOR >= 1 #if __GLIBC__ >=2 && __GLIBC_MINOR__ >= 1
#include <net/ethernet.h> #include <net/ethernet.h>
#else #else
#include <linux/if_ether.h> #include <linux/if_ether.h>

View File

@ -11,7 +11,7 @@
#include <string.h> #include <string.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <features.h> #include <features.h>
#if (__GLIBC__ >= 2 && __GLIBC_MINOR >= 1) || defined _NEWLIB_VERSION #if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined _NEWLIB_VERSION
#include <netpacket/packet.h> #include <netpacket/packet.h>
#include <net/ethernet.h> #include <net/ethernet.h>
#else #else

View File

@ -26,7 +26,7 @@
#include <unistd.h> #include <unistd.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <features.h> #include <features.h>
#if (__GLIBC__ >= 2 && __GLIBC_MINOR >= 1) || defined _NEWLIB_VERSION #if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined(_NEWLIB_VERSION)
#include <netpacket/packet.h> #include <netpacket/packet.h>
#include <net/ethernet.h> #include <net/ethernet.h>
#else #else

View File

@ -5,7 +5,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <features.h> #include <features.h>
#if (__GLIBC__ >= 2 && __GLIBC_MINOR >= 1) || defined _NEWLIB_VERSION #if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined _NEWLIB_VERSION
#include <netpacket/packet.h> #include <netpacket/packet.h>
#include <net/ethernet.h> #include <net/ethernet.h>
#else #else

View File

@ -33,7 +33,7 @@
#include <net/if.h> #include <net/if.h>
#include <errno.h> #include <errno.h>
#include <features.h> #include <features.h>
#if (__GLIBC__ >= 2 && __GLIBC_MINOR >= 1) || defined _NEWLIB_VERSION #if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined _NEWLIB_VERSION
#include <netpacket/packet.h> #include <netpacket/packet.h>
#include <net/ethernet.h> #include <net/ethernet.h>
#else #else

View File

@ -20,23 +20,11 @@
*/ */
#include "busybox.h" #include "busybox.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include <unistd.h>
#include <sys/resource.h> #include <sys/resource.h>
#if (PRIO_PROCESS < CHAR_MIN) || (PRIO_PROCESS > CHAR_MAX) void BUG_bad_PRIO_PROCESS(void);
#error Assumption violated : PRIO_PROCESS value void BUG_bad_PRIO_PGRP(void);
#endif void BUG_bad_PRIO_USER(void);
#if (PRIO_PGRP < CHAR_MIN) || (PRIO_PGRP > CHAR_MAX)
#error Assumption violated : PRIO_PGRP value
#endif
#if (PRIO_USER < CHAR_MIN) || (PRIO_USER > CHAR_MAX)
#error Assumption violated : PRIO_USER value
#endif
int renice_main(int argc, char **argv) int renice_main(int argc, char **argv)
{ {
@ -49,6 +37,14 @@ int renice_main(int argc, char **argv)
unsigned who; unsigned who;
char *arg; char *arg;
/* Yes, they are not #defines in glibc 2.4! #if won't work */
if (PRIO_PROCESS < CHAR_MIN || PRIO_PROCESS > CHAR_MAX)
BUG_bad_PRIO_PROCESS();
if (PRIO_PGRP < CHAR_MIN || PRIO_PGRP > CHAR_MAX)
BUG_bad_PRIO_PGRP();
if (PRIO_USER < CHAR_MIN || PRIO_USER > CHAR_MAX)
BUG_bad_PRIO_USER();
arg = *++argv; arg = *++argv;
/* Check if we are using a relative adjustment. */ /* Check if we are using a relative adjustment. */

View File

@ -42,6 +42,7 @@
* When debugging is on, debugging info will be written to ./trace and * When debugging is on, debugging info will be written to ./trace and
* a quit signal will generate a core dump. * a quit signal will generate a core dump.
*/ */
#define DEBUG 0
#define IFS_BROKEN #define IFS_BROKEN
@ -50,7 +51,7 @@
#include "busybox.h" #include "busybox.h"
#ifdef DEBUG #if DEBUG
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
@ -104,7 +105,7 @@ static int *dash_errno;
#error "Do not even bother, ash will not run on uClinux" #error "Do not even bother, ash will not run on uClinux"
#endif #endif
#ifdef DEBUG #if DEBUG
#define _DIAGASSERT(assert_expr) assert(assert_expr) #define _DIAGASSERT(assert_expr) assert(assert_expr)
#else #else
#define _DIAGASSERT(assert_expr) #define _DIAGASSERT(assert_expr)
@ -582,7 +583,7 @@ static const char dolatstr[] = { CTLVAR, VSNORMAL|VSQUOTE, '@', '=', '\0' };
static const char illnum[] = "Illegal number: %s"; static const char illnum[] = "Illegal number: %s";
static const char homestr[] = "HOME"; static const char homestr[] = "HOME";
#ifdef DEBUG #if DEBUG
#define TRACE(param) trace param #define TRACE(param) trace param
#define TRACEV(param) tracev param #define TRACEV(param) tracev param
#else #else
@ -1937,7 +1938,7 @@ struct shparam {
#define uflag optlist[12] #define uflag optlist[12]
#define viflag optlist[13] #define viflag optlist[13]
#ifdef DEBUG #if DEBUG
#define nolog optlist[14] #define nolog optlist[14]
#define debug optlist[15] #define debug optlist[15]
#endif #endif
@ -1964,7 +1965,7 @@ static const char *const optletters_optnames[] = {
"b" "notify", "b" "notify",
"u" "nounset", "u" "nounset",
"\0" "vi", "\0" "vi",
#ifdef DEBUG #if DEBUG
"\0" "nolog", "\0" "nolog",
"\0" "debug", "\0" "debug",
#endif #endif
@ -2011,7 +2012,7 @@ static int redirectsafe(union node *, int);
/* show.h */ /* show.h */
#ifdef DEBUG #if DEBUG
static void showtree(union node *); static void showtree(union node *);
static void trace(const char *, ...); static void trace(const char *, ...);
static void tracev(const char *, va_list); static void tracev(const char *, va_list);
@ -2536,7 +2537,7 @@ static void exverror(int, const char *, va_list)
static void static void
exraise(int e) exraise(int e)
{ {
#ifdef DEBUG #if DEBUG
if (handler == NULL) if (handler == NULL)
abort(); abort();
#endif #endif
@ -2596,7 +2597,7 @@ exvwarning(const char *msg, va_list ap)
static void static void
exverror(int cond, const char *msg, va_list ap) exverror(int cond, const char *msg, va_list ap)
{ {
#ifdef DEBUG #if DEBUG
if (msg) { if (msg) {
TRACE(("exverror(%d, \"", cond)); TRACE(("exverror(%d, \"", cond));
TRACEV((msg, ap)); TRACEV((msg, ap));
@ -2785,7 +2786,7 @@ evaltree(union node *n, int flags)
getpid(), n, n->type, flags)); getpid(), n, n->type, flags));
switch (n->type) { switch (n->type) {
default: default:
#ifdef DEBUG #if DEBUG
out1fmt("Node type = %d\n", n->type); out1fmt("Node type = %d\n", n->type);
fflush(stdout); fflush(stdout);
break; break;
@ -4481,7 +4482,7 @@ commandcmd(int argc, char **argv)
verify |= VERIFY_VERBOSE; verify |= VERIFY_VERBOSE;
else if (c == 'v') else if (c == 'v')
verify |= VERIFY_BRIEF; verify |= VERIFY_BRIEF;
#ifdef DEBUG #if DEBUG
else if (c != 'p') else if (c != 'p')
abort(); abort();
#endif #endif
@ -4907,7 +4908,7 @@ expari(int quotes)
while (*p != CTLARI) { while (*p != CTLARI) {
p--; p--;
#ifdef DEBUG #if DEBUG
if (p < start) { if (p < start) {
sh_error("missing CTLARI (shouldn't happen)"); sh_error("missing CTLARI (shouldn't happen)");
} }
@ -5100,7 +5101,7 @@ subevalvar(char *p, char *str, int strloc, int subtype, int startloc, int varfla
} }
subtype -= VSTRIMRIGHT; subtype -= VSTRIMRIGHT;
#ifdef DEBUG #if DEBUG
if (subtype < 0 || subtype > 3) if (subtype < 0 || subtype > 3)
abort(); abort();
#endif #endif
@ -5223,7 +5224,7 @@ record:
goto end; goto end;
} }
#ifdef DEBUG #if DEBUG
switch (subtype) { switch (subtype) {
case VSTRIMLEFT: case VSTRIMLEFT:
case VSTRIMLEFTMAX: case VSTRIMLEFTMAX:
@ -6460,7 +6461,7 @@ set_curjob(struct job *jp, unsigned mode)
jpp = curp; jpp = curp;
switch (mode) { switch (mode) {
default: default:
#ifdef DEBUG #if DEBUG
abort(); abort();
#endif #endif
case CUR_DELETE: case CUR_DELETE:
@ -6581,7 +6582,7 @@ usage:
while ((c = nextopt("ls:")) != '\0') while ((c = nextopt("ls:")) != '\0')
switch (c) { switch (c) {
default: default:
#ifdef DEBUG #if DEBUG
abort(); abort();
#endif #endif
case 'l': case 'l':
@ -6647,7 +6648,7 @@ usage:
} }
#endif /* JOBS */ #endif /* JOBS */
#if defined(JOBS) || defined(DEBUG) #if defined(JOBS) || DEBUG
static int static int
jobno(const struct job *jp) jobno(const struct job *jp)
{ {
@ -7827,7 +7828,7 @@ chkmail(void)
if (*p == '\0') if (*p == '\0')
continue; continue;
for (q = p ; *q ; q++); for (q = p ; *q ; q++);
#ifdef DEBUG #if DEBUG
if (q[-1] != '/') if (q[-1] != '/')
abort(); abort();
#endif #endif
@ -7921,7 +7922,7 @@ ash_main(int argc, char **argv)
goto state4; goto state4;
} }
handler = &jmploc; handler = &jmploc;
#ifdef DEBUG #if DEBUG
opentrace(); opentrace();
trputs("Shell args: "); trargs(argv); trputs("Shell args: "); trargs(argv);
#endif #endif
@ -7988,7 +7989,7 @@ state4: /* XXX ??? - why isn't this before the "if" statement */
#if PROFILE #if PROFILE
monitor(0); monitor(0);
#endif #endif
#if GPROF #ifdef GPROF
{ {
extern void _mcleanup(void); extern void _mcleanup(void);
_mcleanup(); _mcleanup();
@ -8266,7 +8267,7 @@ stalloc(size_t nbytes)
void void
stunalloc(pointer p) stunalloc(pointer p)
{ {
#ifdef DEBUG #if DEBUG
if (!p || (stacknxt < (char *)p) || ((char *)p < stackp->space)) { if (!p || (stacknxt < (char *)p) || ((char *)p < stackp->space)) {
write(2, "stunalloc\n", 10); write(2, "stunalloc\n", 10);
abort(); abort();
@ -8844,7 +8845,7 @@ setarg0:
void void
optschanged(void) optschanged(void)
{ {
#ifdef DEBUG #if DEBUG
opentrace(); opentrace();
#endif #endif
setinteractive(iflag); setinteractive(iflag);
@ -9913,7 +9914,7 @@ static int
readtoken(void) readtoken(void)
{ {
int t; int t;
#ifdef DEBUG #if DEBUG
int alreadyseen = tokpushback; int alreadyseen = tokpushback;
#endif #endif
@ -9963,7 +9964,7 @@ top:
} }
out: out:
checkkwd = 0; checkkwd = 0;
#ifdef DEBUG #if DEBUG
if (!alreadyseen) if (!alreadyseen)
TRACE(("token %s %s\n", tokname(t), t == TWORD ? wordtext : "")); TRACE(("token %s %s\n", tokname(t), t == TWORD ? wordtext : ""));
else else
@ -11053,7 +11054,7 @@ openredirect(union node *redir)
goto ecreate; goto ecreate;
break; break;
default: default:
#ifdef DEBUG #if DEBUG
abort(); abort();
#endif #endif
/* Fall through to eliminate warning. */ /* Fall through to eliminate warning. */
@ -11255,7 +11256,7 @@ redirectsafe(union node *redir, int flags)
/* show.c */ /* show.c */
#ifdef DEBUG #if DEBUG
static void shtree(union node *, int, char *, FILE*); static void shtree(union node *, int, char *, FILE*);
static void shcmd(union node *, FILE *); static void shcmd(union node *, FILE *);
static void sharg(union node *, FILE *); static void sharg(union node *, FILE *);
@ -11714,7 +11715,7 @@ setsignal(int signo)
action = S_CATCH; action = S_CATCH;
break; break;
case SIGQUIT: case SIGQUIT:
#ifdef DEBUG #if DEBUG
if (debug) if (debug)
break; break;
#endif #endif
@ -13659,7 +13660,7 @@ static arith_t arith (const char *expr, int *perrcode)
#endif /* CONFIG_ASH_MATH_SUPPORT */ #endif /* CONFIG_ASH_MATH_SUPPORT */
#ifdef DEBUG #if DEBUG
const char *applet_name = "debug stuff usage"; const char *applet_name = "debug stuff usage";
int main(int argc, char **argv) int main(int argc, char **argv)
{ {