From 22afca9b67e4e7d77b4f0a2a30f058fe3b5a2489 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Sun, 1 Mar 2015 22:32:23 +0000 Subject: [PATCH] sh: Fix more compiler warnings. --- bin/sh/eval.c | 2 +- bin/sh/eval.h | 2 +- bin/sh/histedit.c | 6 +++--- bin/sh/jobs.c | 2 +- bin/sh/options.c | 12 ++++++------ bin/sh/var.c | 9 ++++++++- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 347824a8e8e2..51206d931874 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -149,7 +149,7 @@ evalcmd(int argc, char **argv) */ void -evalstring(char *s, int flags) +evalstring(const char *s, int flags) { union node *n; struct stackmark smark; diff --git a/bin/sh/eval.h b/bin/sh/eval.h index 4129757e9f01..d4092be45137 100644 --- a/bin/sh/eval.h +++ b/bin/sh/eval.h @@ -53,7 +53,7 @@ void reseteval(void); #define EV_TESTED 02 /* exit status is checked; ignore -e flag */ #define EV_BACKCMD 04 /* command executing within back quotes */ -void evalstring(char *, int); +void evalstring(const char *, int); union node; /* BLETCH for ansi C */ void evaltree(union node *, int); void evalbackcmd(union node *, struct backcmd *); diff --git a/bin/sh/histedit.c b/bin/sh/histedit.c index c65d1c7134e5..7295c3f003c9 100644 --- a/bin/sh/histedit.c +++ b/bin/sh/histedit.c @@ -338,8 +338,8 @@ histcmd(int argc, char **argv __unused) out1fmt("%5d ", he.num); out1str(he.str); } else { - char *s = pat ? - fc_replace(he.str, pat, repl) : (char *)he.str; + const char *s = pat ? + fc_replace(he.str, pat, repl) : he.str; if (sflg) { if (displayhist) { @@ -477,7 +477,7 @@ bindcmd(int argc, char **argv) if (el == NULL) error("line editing is disabled"); - return (el_parse(el, argc, (const char **)argv)); + return (el_parse(el, argc, __DECONST(const char **, argv))); } #else diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c index b1bfa0944d71..753cf7bd931f 100644 --- a/bin/sh/jobs.c +++ b/bin/sh/jobs.c @@ -232,7 +232,7 @@ fgcmd(int argc __unused, char **argv __unused) int -bgcmd(int argc, char **argv) +bgcmd(int argc __unused, char **argv __unused) { struct job *jp; diff --git a/bin/sh/options.c b/bin/sh/options.c index 860cf6c645bb..2d0ddce5a3de 100644 --- a/bin/sh/options.c +++ b/bin/sh/options.c @@ -465,7 +465,7 @@ getopts(char *optstr, char *optvar, char **optfirst, char ***optnext, int ind = 0; int err = 0; char s[10]; - const char *optarg = NULL; + const char *newoptarg = NULL; if ((p = *optptr) == NULL || *p == '\0') { /* Current word is done, advance */ @@ -491,7 +491,7 @@ getopts(char *optstr, char *optvar, char **optfirst, char ***optnext, if (optstr[0] == ':') { s[0] = c; s[1] = '\0'; - optarg = s; + newoptarg = s; } else out2fmt_flush("Illegal option -%c\n", c); @@ -507,7 +507,7 @@ getopts(char *optstr, char *optvar, char **optfirst, char ***optnext, if (optstr[0] == ':') { s[0] = c; s[1] = '\0'; - optarg = s; + newoptarg = s; c = ':'; } else { @@ -519,7 +519,7 @@ getopts(char *optstr, char *optvar, char **optfirst, char ***optnext, if (p == **optnext) (*optnext)++; - optarg = p; + newoptarg = p; p = NULL; } @@ -527,8 +527,8 @@ getopts(char *optstr, char *optvar, char **optfirst, char ***optnext, if (*optnext != NULL) ind = *optnext - optfirst + 1; *optptr = p; - if (optarg != NULL) - err |= setvarsafe("OPTARG", optarg, 0); + if (newoptarg != NULL) + err |= setvarsafe("OPTARG", newoptarg, 0); else { INTOFF; err |= unsetvar("OPTARG"); diff --git a/bin/sh/var.c b/bin/sh/var.c index def1e0c69ff6..87d7b807727d 100644 --- a/bin/sh/var.c +++ b/bin/sh/var.c @@ -141,6 +141,7 @@ static const int locale_categories[7] = { static int varequal(const char *, const char *); static struct var *find_var(const char *, struct var ***, int *); static int localevar(const char *); +static void setvareq_const(const char *s, int flags); extern char **environ; @@ -183,7 +184,7 @@ initvar(void) setvareq(*envp, VEXPORT|VTEXTFIXED); } } - setvareq("OPTIND=1", VTEXTFIXED); + setvareq_const("OPTIND=1", 0); } /* @@ -389,6 +390,12 @@ setvareq(char *s, int flags) } +static void +setvareq_const(const char *s, int flags) +{ + setvareq(__DECONST(char *, s), flags | VTEXTFIXED); +} + /* * Process a linked list of variable assignments.