From 46c6b52dfb4b0396494b08f60c80e32236df1aaf Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Mon, 1 Apr 2013 17:18:22 +0000 Subject: [PATCH] sh: Fix various compiler warnings. It now passes WARNS=7 with clang on i386. GCC 4.2.1 does not understand setjmp() properly so will always trigger -Wuninitialized. I will not add the volatile keywords to suppress this. --- bin/sh/exec.c | 4 ++-- bin/sh/expand.c | 13 +++++++------ bin/sh/input.c | 14 +++++++------- bin/sh/input.h | 4 ++-- bin/sh/jobs.c | 5 +++-- bin/sh/main.c | 4 ++-- bin/sh/memalloc.c | 5 +++-- bin/sh/memalloc.h | 4 ++-- bin/sh/parser.c | 11 ++++++----- bin/sh/parser.h | 2 +- bin/sh/trap.c | 2 +- 11 files changed, 36 insertions(+), 32 deletions(-) diff --git a/bin/sh/exec.c b/bin/sh/exec.c index 7a6dbae4172e..6c3a6ddbf783 100644 --- a/bin/sh/exec.c +++ b/bin/sh/exec.c @@ -165,7 +165,7 @@ tryexec(char *cmd, char **argv, char **envp) } } *argv = cmd; - *--argv = _PATH_BSHELL; + *--argv = __DECONST(char *, _PATH_BSHELL); execve(_PATH_BSHELL, argv, envp); } errno = e; @@ -188,7 +188,7 @@ padvance(const char **path, const char *name) { const char *p, *start; char *q; - int len; + size_t len; if (*path == NULL) return NULL; diff --git a/bin/sh/expand.c b/bin/sh/expand.c index 107f798d09f4..414bfa7a1988 100644 --- a/bin/sh/expand.c +++ b/bin/sh/expand.c @@ -460,7 +460,7 @@ expbackq(union node *cmd, int quoted, int flag) int startloc = dest - stackblock(); char const *syntax = quoted? DQSYNTAX : BASESYNTAX; int quotes = flag & (EXP_FULL | EXP_CASE | EXP_REDIR); - int nnl; + size_t nnl; INTOFF; saveifs = ifsfirst; @@ -1163,9 +1163,9 @@ expandmeta(struct strlist *str, int flag __unused) static void expmeta(char *enddir, char *name) { - char *p; - char *q; - char *start; + const char *p; + const char *q; + const char *start; char *endname; int metaflag; struct stat statb; @@ -1229,7 +1229,7 @@ expmeta(char *enddir, char *name) addfname(expdir); return; } - endname = p; + endname = name + (p - name); if (start != name) { p = name; while (p < start) { @@ -1412,7 +1412,8 @@ match_charclass(const char *p, wchar_t chr, const char **end) *end = NULL; p++; nameend = strstr(p, ":]"); - if (nameend == NULL || nameend - p >= sizeof(name) || nameend == p) + if (nameend == NULL || (size_t)(nameend - p) >= sizeof(name) || + nameend == p) return 0; memcpy(name, p, nameend - p); name[nameend - p] = '\0'; diff --git a/bin/sh/input.c b/bin/sh/input.c index 84580ad36cf0..62e82a0dbda6 100644 --- a/bin/sh/input.c +++ b/bin/sh/input.c @@ -66,7 +66,7 @@ __FBSDID("$FreeBSD$"); struct strpush { struct strpush *prev; /* preceding string on stack */ - char *prevstring; + const char *prevstring; int prevnleft; int prevlleft; struct alias *ap; /* if push was associated with an alias */ @@ -83,7 +83,7 @@ struct parsefile { int fd; /* file descriptor (or -1 if string) */ int nleft; /* number of chars left in this line */ int lleft; /* number of lines left in this buffer */ - char *nextc; /* next char in buffer */ + const char *nextc; /* next char in buffer */ char *buf; /* input buffer */ struct strpush *strpush; /* for pushing strings at this level */ struct strpush basestrpush; /* so pushing one is fast */ @@ -93,7 +93,7 @@ struct parsefile { int plinno = 1; /* input line number */ int parsenleft; /* copy of parsefile->nleft */ MKINIT int parselleft; /* copy of parsefile->lleft */ -char *parsenextc; /* copy of parsefile->nextc */ +const char *parsenextc; /* copy of parsefile->nextc */ static char basebuf[BUFSIZ + 1];/* buffer for top level input file */ static struct parsefile basepf = { /* top level input file */ .nextc = basebuf, @@ -185,7 +185,7 @@ preadfd(void) nr = el_len; if (nr > BUFSIZ) nr = BUFSIZ; - memcpy(parsenextc, rl_cp, nr); + memcpy(parsefile->buf, rl_cp, nr); if (nr != el_len) { el_len -= nr; rl_cp += nr; @@ -194,7 +194,7 @@ preadfd(void) } } else #endif - nr = read(parsefile->fd, parsenextc, BUFSIZ); + nr = read(parsefile->fd, parsefile->buf, BUFSIZ); if (nr <= 0) { if (nr < 0) { @@ -252,7 +252,7 @@ preadbuffer(void) } } - q = p = parsenextc; + q = p = parsefile->buf + (parsenextc - parsefile->buf); /* delete nul characters */ something = 0; @@ -439,7 +439,7 @@ setinputfd(int fd, int push) */ void -setinputstring(char *string, int push) +setinputstring(const char *string, int push) { INTOFF; if (push) diff --git a/bin/sh/input.h b/bin/sh/input.h index c8802f9783c2..70f675e5cbfb 100644 --- a/bin/sh/input.h +++ b/bin/sh/input.h @@ -42,7 +42,7 @@ */ extern int plinno; extern int parsenleft; /* number of characters left in input buffer */ -extern char *parsenextc; /* next character in input buffer */ +extern const char *parsenextc; /* next character in input buffer */ struct alias; struct parsefile; @@ -55,7 +55,7 @@ void pungetc(void); void pushstring(char *, int, struct alias *); void setinputfile(const char *, int); void setinputfd(int, int); -void setinputstring(char *, int); +void setinputstring(const char *, int); void popfile(void); struct parsefile *getcurrentfile(void); void popfilesupto(struct parsefile *); diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c index a092884f2302..c978e3d643a0 100644 --- a/bin/sh/jobs.c +++ b/bin/sh/jobs.c @@ -668,7 +668,8 @@ makejob(union node *node __unused, int nprocs) jobtab = jp; } jp = jobtab + njobs; - for (i = 4 ; --i >= 0 ; jobtab[njobs++].used = 0); + for (i = 4 ; --i >= 0 ; jobtab[njobs++].used = 0) + ; INTON; break; } @@ -1005,7 +1006,7 @@ waitforjob(struct job *jp, int *origstatus) static void -dummy_handler(int sig) +dummy_handler(int sig __unused) { } diff --git a/bin/sh/main.c b/bin/sh/main.c index 5dc050ffb701..84a1ef2d0fbb 100644 --- a/bin/sh/main.c +++ b/bin/sh/main.c @@ -80,7 +80,7 @@ struct jmploc main_handler; int localeisutf8, initial_localeisutf8; static void cmdloop(int); -static void read_profile(char *); +static void read_profile(const char *); static char *find_dot_file(char *); /* @@ -239,7 +239,7 @@ cmdloop(int top) */ static void -read_profile(char *name) +read_profile(const char *name) { int fd; const char *expandedname; diff --git a/bin/sh/memalloc.c b/bin/sh/memalloc.c index bc567d08450e..f33a15ced528 100644 --- a/bin/sh/memalloc.c +++ b/bin/sh/memalloc.c @@ -233,7 +233,8 @@ growstackblock(int min) if (min < stacknleft) min = stacknleft; - if (min >= INT_MAX / 2 - ALIGN(sizeof(struct stack_block))) + if ((unsigned int)min >= + INT_MAX / 2 - ALIGN(sizeof(struct stack_block))) error("Out of space"); min += stacknleft; min += ALIGN(sizeof(struct stack_block)); @@ -327,7 +328,7 @@ makestrspace(int min, char *p) char * -stputbin(const char *data, int len, char *p) +stputbin(const char *data, size_t len, char *p) { CHECKSTRSPACE(len, p); memcpy(p, data, len); diff --git a/bin/sh/memalloc.h b/bin/sh/memalloc.h index 425004ed3f72..95a659437e66 100644 --- a/bin/sh/memalloc.h +++ b/bin/sh/memalloc.h @@ -57,7 +57,7 @@ void setstackmark(struct stackmark *); void popstackmark(struct stackmark *); char *growstackstr(void); char *makestrspace(int, char *); -char *stputbin(const char *data, int len, char *p); +char *stputbin(const char *data, size_t len, char *p); char *stputs(const char *data, char *p); @@ -67,7 +67,7 @@ char *stputs(const char *data, char *p); #define grabstackblock(n) stalloc(n) #define STARTSTACKSTR(p) p = stackblock() #define STPUTC(c, p) do { if (p == sstrend) p = growstackstr(); *p++ = (c); } while(0) -#define CHECKSTRSPACE(n, p) { if (sstrend - p < n) p = makestrspace(n, p); } +#define CHECKSTRSPACE(n, p) { if ((size_t)(sstrend - p) < n) p = makestrspace(n, p); } #define USTPUTC(c, p) (*p++ = (c)) /* * STACKSTRNUL's use is where we want to be able to turn a stack diff --git a/bin/sh/parser.c b/bin/sh/parser.c index 665b53ff5aae..073c2b69308f 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -119,7 +119,7 @@ static void parseheredoc(void); static int peektoken(void); static int readtoken(void); static int xxreadtoken(void); -static int readtoken1(int, char const *, char *, int); +static int readtoken1(int, const char *, const char *, int); static int noexpand(char *); static void synexpect(int) __dead2; static void synerror(const char *) __dead2; @@ -983,7 +983,7 @@ parsebackq(char *out, struct nodelist **pbqlist, char *volatile str; struct jmploc jmploc; struct jmploc *const savehandler = handler; - int savelen; + size_t savelen; int saveprompt; const int bq_startlinno = plinno; char *volatile ostr = NULL; @@ -1300,7 +1300,8 @@ readcstyleesc(char *out) #define PARSEARITH() {goto parsearith; parsearith_return:;} static int -readtoken1(int firstc, char const *initialsyntax, char *eofmark, int striptabs) +readtoken1(int firstc, char const *initialsyntax, const char *eofmark, + int striptabs) { int c = firstc; char *out; @@ -1521,7 +1522,7 @@ checkend: { } if (c == *eofmark) { if (pfgets(line, sizeof line) != NULL) { - char *p, *q; + const char *p, *q; p = line; for (q = eofmark + 1 ; *q && *p == *q ; p++, q++); @@ -2038,7 +2039,7 @@ getprompt(void *unused __unused) const char * -expandstr(char *ps) +expandstr(const char *ps) { union node n; struct jmploc jmploc; diff --git a/bin/sh/parser.h b/bin/sh/parser.h index f80d91778787..b803f76dbe64 100644 --- a/bin/sh/parser.h +++ b/bin/sh/parser.h @@ -82,4 +82,4 @@ void fixredir(union node *, const char *, int); int goodname(const char *); int isassignment(const char *); char *getprompt(void *); -const char *expandstr(char *); +const char *expandstr(const char *); diff --git a/bin/sh/trap.c b/bin/sh/trap.c index 6c4cbbeec8e3..313802925592 100644 --- a/bin/sh/trap.c +++ b/bin/sh/trap.c @@ -150,7 +150,7 @@ printsignals(void) * The trap builtin. */ int -trapcmd(int argc, char **argv) +trapcmd(int argc __unused, char **argv) { char *action; int signo;