From: millert Date: Sat, 6 Jan 2018 16:28:58 +0000 (+0000) Subject: Bring back the sign compare changes, this time with a fix from otto@ X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=4c503bcd167b6729aad0119682ffe516cb53bade;p=openbsd Bring back the sign compare changes, this time with a fix from otto@ that fixes the issues seen on hppa. OK deraadt@ otto@ --- diff --git a/bin/ksh/Makefile b/bin/ksh/Makefile index dca3c76b315..66419f2311d 100644 --- a/bin/ksh/Makefile +++ b/bin/ksh/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.37 2018/01/04 19:06:16 millert Exp $ +# $OpenBSD: Makefile,v 1.38 2018/01/06 16:28:58 millert Exp $ PROG= ksh SRCS= alloc.c c_ksh.c c_sh.c c_test.c c_ulimit.c edit.c emacs.c eval.c \ @@ -6,7 +6,8 @@ SRCS= alloc.c c_ksh.c c_sh.c c_test.c c_ulimit.c edit.c emacs.c eval.c \ misc.c path.c shf.c syn.c table.c trap.c tree.c tty.c var.c \ version.c vi.c -DEFS= -Wall -Wshadow -DEMACS -DVI +WARNINGS=yes +DEFS= -DEMACS -DVI CFLAGS+=${DEFS} -I. -I${.CURDIR} -I${.CURDIR}/../../lib/libc/gen MAN= ksh.1 sh.1 diff --git a/bin/ksh/c_ksh.c b/bin/ksh/c_ksh.c index 3dae72e6383..0e071809d55 100644 --- a/bin/ksh/c_ksh.c +++ b/bin/ksh/c_ksh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: c_ksh.c,v 1.55 2018/01/05 15:44:31 jca Exp $ */ +/* $OpenBSD: c_ksh.c,v 1.56 2018/01/06 16:28:58 millert Exp $ */ /* * built-in Korn commands: c_* @@ -1192,7 +1192,8 @@ c_kill(char **wp) ki.num_width++; for (i = 0; i < NSIG; i++) { - w = sigtraps[i].name ? strlen(sigtraps[i].name) : + w = sigtraps[i].name ? + (int)strlen(sigtraps[i].name) : ki.num_width; if (w > ki.name_width) ki.name_width = w; diff --git a/bin/ksh/edit.c b/bin/ksh/edit.c index 0df2c421885..ffff9845eca 100644 --- a/bin/ksh/edit.c +++ b/bin/ksh/edit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: edit.c,v 1.60 2018/01/04 19:06:16 millert Exp $ */ +/* $OpenBSD: edit.c,v 1.61 2018/01/06 16:28:58 millert Exp $ */ /* * Command line editing - common code @@ -224,13 +224,13 @@ set_editmode(const char *ed) #endif }; char *rcp; - int i; + unsigned int ele; if ((rcp = strrchr(ed, '/'))) ed = ++rcp; - for (i = 0; i < NELEM(edit_flags); i++) - if (strstr(ed, sh_options[(int) edit_flags[i]].name)) { - change_flag(edit_flags[i], OF_SPECIAL, 1); + for (ele = 0; ele < NELEM(edit_flags); ele++) + if (strstr(ed, sh_options[(int) edit_flags[ele]].name)) { + change_flag(edit_flags[ele], OF_SPECIAL, 1); return; } } diff --git a/bin/ksh/emacs.c b/bin/ksh/emacs.c index 87027c30932..f7d2d59ae5c 100644 --- a/bin/ksh/emacs.c +++ b/bin/ksh/emacs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: emacs.c,v 1.79 2018/01/04 19:06:16 millert Exp $ */ +/* $OpenBSD: emacs.c,v 1.80 2018/01/06 16:28:58 millert Exp $ */ /* * Emacs-like command line editing and history @@ -1249,7 +1249,7 @@ static char * kb_decode(const char *s) { static char l[LINE + 1]; - int i, at = 0; + unsigned int i, at = 0; l[0] = '\0'; for (i = 0; i < strlen(s); i++) { @@ -1292,13 +1292,13 @@ kb_del(struct kb_entry *k) static struct kb_entry * kb_add_string(void *func, void *args, char *str) { - int i, count; + unsigned int ele, count; struct kb_entry *k; struct x_ftab *xf = NULL; - for (i = 0; i < NELEM(x_ftab); i++) - if (x_ftab[i].xf_func == func) { - xf = (struct x_ftab *)&x_ftab[i]; + for (ele = 0; ele < NELEM(x_ftab); ele++) + if (x_ftab[ele].xf_func == func) { + xf = (struct x_ftab *)&x_ftab[ele]; break; } if (xf == NULL) @@ -1328,11 +1328,10 @@ static struct kb_entry * kb_add(void *func, void *args, ...) { va_list ap; - int i, count; + unsigned int i, count = 0; char l[LINE + 1]; va_start(ap, args); - count = 0; while (va_arg(ap, unsigned int) != 0) count++; va_end(ap); @@ -1362,7 +1361,7 @@ x_bind(const char *a1, const char *a2, int macro, /* bind -m */ int list) /* bind -l */ { - int i; + unsigned int i; struct kb_entry *k, *kb; char in[LINE + 1]; diff --git a/bin/ksh/eval.c b/bin/ksh/eval.c index fddbc082ae8..d47e057d7f4 100644 --- a/bin/ksh/eval.c +++ b/bin/ksh/eval.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eval.c,v 1.56 2018/01/04 19:06:16 millert Exp $ */ +/* $OpenBSD: eval.c,v 1.57 2018/01/06 16:28:58 millert Exp $ */ /* * Expansion - quoting, separation, substitution, globbing @@ -1114,10 +1114,11 @@ debunk(char *dp, const char *sp, size_t dlen) char *d, *s; if ((s = strchr(sp, MAGIC))) { - if (s - sp >= dlen) + size_t slen = s - sp; + if (slen >= dlen) return dp; - memcpy(dp, sp, s - sp); - for (d = dp + (s - sp); *s && (d - dp < dlen); s++) + memcpy(dp, sp, slen); + for (d = dp + slen; *s && (d < dp + dlen); s++) if (!ISMAGIC(*s) || !(*++s & 0x80) || !strchr("*+?@! ", *s & 0x7f)) *d++ = *s; @@ -1125,7 +1126,7 @@ debunk(char *dp, const char *sp, size_t dlen) /* extended pattern operators: *+?@! */ if ((*s & 0x7f) != ' ') *d++ = *s & 0x7f; - if (d - dp < dlen) + if (d < dp + dlen) *d++ = '('; } *d = '\0'; diff --git a/bin/ksh/expand.h b/bin/ksh/expand.h index 59f5303a49f..21d8cddee1d 100644 --- a/bin/ksh/expand.h +++ b/bin/ksh/expand.h @@ -1,4 +1,4 @@ -/* $OpenBSD: expand.h,v 1.14 2018/01/04 19:06:16 millert Exp $ */ +/* $OpenBSD: expand.h,v 1.15 2018/01/06 16:28:58 millert Exp $ */ /* * Expanding strings @@ -46,7 +46,7 @@ typedef char * XStringP; /* check if there are at least n bytes left */ #define XcheckN(xs, xp, n) do { \ - int more = ((xp) + (n)) - (xs).end; \ + ptrdiff_t more = ((xp) + (n)) - (xs).end; \ if (more > 0) \ xp = Xcheck_grow_(&xs, xp, more); \ } while (0) @@ -68,7 +68,7 @@ typedef char * XStringP; #define Xsavepos(xs, xp) ((xp) - (xs).beg) #define Xrestpos(xs, xp, n) ((xs).beg + (n)) -char * Xcheck_grow_(XString *xsp, char *xp, int more); +char * Xcheck_grow_(XString *xsp, char *xp, size_t more); /* * expandable vector of generic pointers diff --git a/bin/ksh/history.c b/bin/ksh/history.c index 80b1042ebb5..3812e92f895 100644 --- a/bin/ksh/history.c +++ b/bin/ksh/history.c @@ -1,4 +1,4 @@ -/* $OpenBSD: history.c,v 1.77 2018/01/04 19:06:16 millert Exp $ */ +/* $OpenBSD: history.c,v 1.78 2018/01/06 16:28:58 millert Exp $ */ /* * command history @@ -545,7 +545,7 @@ sethistcontrol(const char *str) void sethistsize(int n) { - if (n > 0 && n != histsize) { + if (n > 0 && (uint32_t)n != histsize) { int offset = histptr - history; /* save most recent history */ diff --git a/bin/ksh/lex.c b/bin/ksh/lex.c index 540bedd65fa..4ed8557d016 100644 --- a/bin/ksh/lex.c +++ b/bin/ksh/lex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.76 2018/01/04 19:06:16 millert Exp $ */ +/* $OpenBSD: lex.c,v 1.77 2018/01/06 16:28:58 millert Exp $ */ /* * lexical analysis and source input @@ -98,9 +98,9 @@ YYSTYPE yylval; /* result from yylex */ struct ioword *heres[HERES], **herep; char ident[IDENT+1]; -char **history; /* saved commands */ -char **histptr; /* last history item */ -int histsize; /* history size */ +char **history; /* saved commands */ +char **histptr; /* last history item */ +uint32_t histsize; /* history size */ /* optimized getsc_bn() */ #define getsc() (*source->str != '\0' && *source->str != '\\' \ diff --git a/bin/ksh/lex.h b/bin/ksh/lex.h index a620b72684d..70771c9c0f0 100644 --- a/bin/ksh/lex.h +++ b/bin/ksh/lex.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.h,v 1.19 2018/01/04 19:06:16 millert Exp $ */ +/* $OpenBSD: lex.h,v 1.20 2018/01/06 16:28:58 millert Exp $ */ /* * Source input, lexer and parser @@ -110,7 +110,7 @@ extern char ident[IDENT+1]; extern char **history; /* saved commands */ extern char **histptr; /* last history item */ -extern int histsize; /* history size */ +extern uint32_t histsize; /* history size */ #endif /* HISTORY */ diff --git a/bin/ksh/misc.c b/bin/ksh/misc.c index 425da9cca6d..f9f41ba23bc 100644 --- a/bin/ksh/misc.c +++ b/bin/ksh/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.64 2018/01/05 15:44:31 jca Exp $ */ +/* $OpenBSD: misc.c,v 1.65 2018/01/06 16:28:58 millert Exp $ */ /* * Miscellaneous functions @@ -105,7 +105,7 @@ str_nsave(const char *s, int n, Area *ap) /* called from expand.h:XcheckN() to grow buffer */ char * -Xcheck_grow_(XString *xsp, char *xp, int more) +Xcheck_grow_(XString *xsp, char *xp, size_t more) { char *old_beg = xsp->beg; @@ -175,11 +175,11 @@ const struct option sh_options[] = { int option(const char *n) { - int i; + unsigned int ele; - for (i = 0; i < NELEM(sh_options); i++) - if (sh_options[i].name && strcmp(sh_options[i].name, n) == 0) - return i; + for (ele = 0; ele < NELEM(sh_options); ele++) + if (sh_options[ele].name && strcmp(sh_options[ele].name, n) == 0) + return ele; return -1; } @@ -210,20 +210,21 @@ options_fmt_entry(void *arg, int i, char *buf, int buflen) static void printoptions(int verbose) { - int i; + unsigned int ele; if (verbose) { struct options_info oi; - int n, len; + unsigned int n; + int len; /* verbose version */ shprintf("Current option settings\n"); - for (i = n = oi.opt_width = 0; i < NELEM(sh_options); i++) { - if (sh_options[i].name) { - len = strlen(sh_options[i].name); - oi.opts[n].name = sh_options[i].name; - oi.opts[n++].flag = i; + for (ele = n = oi.opt_width = 0; ele < NELEM(sh_options); ele++) { + if (sh_options[ele].name) { + len = strlen(sh_options[ele].name); + oi.opts[n].name = sh_options[ele].name; + oi.opts[n++].flag = ele; if (len > oi.opt_width) oi.opt_width = len; } @@ -233,11 +234,11 @@ printoptions(int verbose) } else { /* short version ala ksh93 */ shprintf("set"); - for (i = 0; i < NELEM(sh_options); i++) { - if (sh_options[i].name) + for (ele = 0; ele < NELEM(sh_options); ele++) { + if (sh_options[ele].name) shprintf(" %co %s", - Flag(i) ? '-' : '+', - sh_options[i].name); + Flag(ele) ? '-' : '+', + sh_options[ele].name); } shprintf("\n"); } @@ -246,13 +247,13 @@ printoptions(int verbose) char * getoptions(void) { - int i; + unsigned int ele; char m[(int) FNFLAGS + 1]; char *cp = m; - for (i = 0; i < NELEM(sh_options); i++) - if (sh_options[i].c && Flag(i)) - *cp++ = sh_options[i].c; + for (ele = 0; ele < NELEM(sh_options); ele++) + if (sh_options[ele].c && Flag(ele)) + *cp++ = sh_options[ele].c; *cp = 0; return str_save(m, ATEMP); } @@ -325,7 +326,8 @@ parse_args(char **argv, char *opts; char *array = NULL; Getopt go; - int i, optc, set, sortargs = 0, arrayset = 0; + int i, optc, sortargs = 0, arrayset = 0; + unsigned int ele; /* First call? Build option strings... */ if (cmd_opts[0] == '\0') { @@ -337,12 +339,12 @@ parse_args(char **argv, /* see set_opts[] declaration */ strlcpy(set_opts, "A:o;s", sizeof set_opts); q = set_opts + strlen(set_opts); - for (i = 0; i < NELEM(sh_options); i++) { - if (sh_options[i].c) { - if (sh_options[i].flags & OF_CMDLINE) - *p++ = sh_options[i].c; - if (sh_options[i].flags & OF_SET) - *q++ = sh_options[i].c; + for (ele = 0; ele < NELEM(sh_options); ele++) { + if (sh_options[ele].c) { + if (sh_options[ele].flags & OF_CMDLINE) + *p++ = sh_options[ele].c; + if (sh_options[ele].flags & OF_SET) + *q++ = sh_options[ele].c; } } *p = '\0'; @@ -361,7 +363,7 @@ parse_args(char **argv, opts = set_opts; ksh_getopt_reset(&go, GF_ERROR|GF_PLUSOPT); while ((optc = ksh_getopt(argv, &go, opts)) != -1) { - set = (go.info & GI_PLUS) ? 0 : 1; + int set = (go.info & GI_PLUS) ? 0 : 1; switch (optc) { case 'A': arrayset = set ? 1 : -1; @@ -380,14 +382,14 @@ parse_args(char **argv, break; } i = option(go.optarg); - if (i >= 0 && set == Flag(i)) + if (i != -1 && set == Flag(i)) /* Don't check the context if the flag * isn't changing - makes "set -o interactive" * work if you're already interactive. Needed * if the output of "set +o" is to be used. */ ; - else if (i >= 0 && (sh_options[i].flags & what)) + else if (i != -1 && (sh_options[i].flags & what)) change_flag((enum sh_flag) i, what, set); else { bi_errorf("%s: bad option", go.optarg); @@ -404,14 +406,14 @@ parse_args(char **argv, sortargs = 1; break; } - for (i = 0; i < NELEM(sh_options); i++) - if (optc == sh_options[i].c && - (what & sh_options[i].flags)) { - change_flag((enum sh_flag) i, what, + for (ele = 0; ele < NELEM(sh_options); ele++) + if (optc == sh_options[ele].c && + (what & sh_options[ele].flags)) { + change_flag((enum sh_flag) ele, what, set); break; } - if (i == NELEM(sh_options)) { + if (ele == NELEM(sh_options)) { internal_errorf(1, "parse_args: `%c'", optc); return -1; /* not reached */ } @@ -500,7 +502,7 @@ gmatch(const char *s, const char *p, int isfile) * the pattern. If check fails, just to a strcmp(). */ if (!isfile && !has_globbing(p, pe)) { - int len = pe - p + 1; + size_t len = pe - p + 1; char tbuf[64]; char *t = len <= sizeof(tbuf) ? tbuf : alloc(len, ATEMP); diff --git a/bin/ksh/path.c b/bin/ksh/path.c index ff8d26e61d0..5da57a3f829 100644 --- a/bin/ksh/path.c +++ b/bin/ksh/path.c @@ -1,4 +1,4 @@ -/* $OpenBSD: path.c,v 1.21 2018/01/04 19:06:16 millert Exp $ */ +/* $OpenBSD: path.c,v 1.22 2018/01/06 16:28:58 millert Exp $ */ #include @@ -228,7 +228,7 @@ do_phys_path(XString *xsp, char *xp, const char *path) p++; if (!*p) break; - len = (q = strchr(p, '/')) ? q - p : strlen(p); + len = (q = strchr(p, '/')) ? (size_t)(q - p) : strlen(p); if (len == 1 && p[0] == '.') continue; if (len == 2 && p[0] == '.' && p[1] == '.') { diff --git a/bin/ksh/sh.h b/bin/ksh/sh.h index 03b860f078d..e573b847a5d 100644 --- a/bin/ksh/sh.h +++ b/bin/ksh/sh.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sh.h,v 1.67 2018/01/05 15:44:31 jca Exp $ */ +/* $OpenBSD: sh.h,v 1.68 2018/01/06 16:28:58 millert Exp $ */ /* * Public Domain Bourne/Korn shell @@ -13,6 +13,7 @@ #include #include #include +#include #include #include diff --git a/bin/ksh/tree.c b/bin/ksh/tree.c index 1760f19f5fd..71081c891f9 100644 --- a/bin/ksh/tree.c +++ b/bin/ksh/tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tree.c,v 1.29 2018/01/04 19:06:16 millert Exp $ */ +/* $OpenBSD: tree.c,v 1.30 2018/01/06 16:28:58 millert Exp $ */ /* * command tree climbing @@ -390,6 +390,15 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va) case 'c': tputc(va_arg(va, int), shf); break; + case 'd': /* decimal */ + n = va_arg(va, int); + neg = n < 0; + p = ulton(neg ? -n : n, 10); + if (neg) + *--p = '-'; + while (*p) + tputc(*p++, shf); + break; case 's': p = va_arg(va, char *); while (*p) @@ -399,13 +408,8 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va) p = va_arg(va, char *); tputS(p, shf); break; - case 'd': case 'u': /* decimal */ - n = (c == 'd') ? va_arg(va, int) : - va_arg(va, unsigned int); - neg = c=='d' && n<0; - p = ulton((neg) ? -n : n, 10); - if (neg) - *--p = '-'; + case 'u': /* unsigned decimal */ + p = ulton(va_arg(va, unsigned int), 10); while (*p) tputc(*p++, shf); break; diff --git a/bin/ksh/var.c b/bin/ksh/var.c index 28a8a816f22..31f97e6baf4 100644 --- a/bin/ksh/var.c +++ b/bin/ksh/var.c @@ -1,4 +1,4 @@ -/* $OpenBSD: var.c,v 1.62 2018/01/04 19:06:16 millert Exp $ */ +/* $OpenBSD: var.c,v 1.63 2018/01/06 16:28:58 millert Exp $ */ #include @@ -306,7 +306,7 @@ str_val(struct tbl *vp) "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" : "0123456789abcdefghijklmnopqrstuvwxyz"; unsigned long n; - int base; + unsigned int base; s = strbuf + sizeof(strbuf); if (vp->flag & INT_U) diff --git a/bin/ksh/vi.c b/bin/ksh/vi.c index da682c87b54..0bf16919fd7 100644 --- a/bin/ksh/vi.c +++ b/bin/ksh/vi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vi.c,v 1.52 2018/01/04 19:06:16 millert Exp $ */ +/* $OpenBSD: vi.c,v 1.53 2018/01/06 16:28:58 millert Exp $ */ /* * vi command editing @@ -238,7 +238,7 @@ x_vi(char *buf, size_t len) x_putc('\r'); x_putc('\n'); x_flush(); - if (c == -1 || len <= es->linelen) + if (c == -1 || len <= (size_t)es->linelen) return -1; if (es->cbuf != buf)