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.
This commit is contained in:
Jilles Tjoelker 2013-04-01 17:18:22 +00:00
parent 4f2dc3d723
commit 46c6b52dfb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=248980
11 changed files with 36 additions and 32 deletions

View File

@ -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;

View File

@ -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';

View File

@ -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)

View File

@ -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 *);

View File

@ -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)
{
}

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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 *);

View File

@ -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;