Back out sign compare changes that appear to cause problems on hppa.
authormillert <millert@openbsd.org>
Thu, 4 Jan 2018 19:06:16 +0000 (19:06 +0000)
committermillert <millert@openbsd.org>
Thu, 4 Jan 2018 19:06:16 +0000 (19:06 +0000)
Requested by deraadt@

14 files changed:
bin/ksh/Makefile
bin/ksh/c_ksh.c
bin/ksh/edit.c
bin/ksh/emacs.c
bin/ksh/eval.c
bin/ksh/expand.h
bin/ksh/history.c
bin/ksh/lex.c
bin/ksh/lex.h
bin/ksh/misc.c
bin/ksh/path.c
bin/ksh/tree.c
bin/ksh/var.c
bin/ksh/vi.c

index 5f3b8a5..dca3c76 100644 (file)
@@ -1,4 +1,4 @@
-#      $OpenBSD: Makefile,v 1.36 2018/01/01 19:45:56 millert Exp $
+#      $OpenBSD: Makefile,v 1.37 2018/01/04 19:06:16 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,8 +6,7 @@ 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
 
-WARNINGS=yes
-DEFS=  -DEMACS -DVI
+DEFS=  -Wall -Wshadow -DEMACS -DVI
 CFLAGS+=${DEFS} -I. -I${.CURDIR} -I${.CURDIR}/../../lib/libc/gen
 MAN=   ksh.1 sh.1
 
index 23371bc..174e79a 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: c_ksh.c,v 1.53 2018/01/01 19:45:56 millert Exp $      */
+/*     $OpenBSD: c_ksh.c,v 1.54 2018/01/04 19:06:16 millert Exp $      */
 
 /*
  * built-in Korn commands: c_*
@@ -1194,8 +1194,7 @@ c_kill(char **wp)
                                ki.num_width++;
 
                        for (i = 0; i < NSIG; i++) {
-                               w = sigtraps[i].name ?
-                                   (int)strlen(sigtraps[i].name) :
+                               w = sigtraps[i].name ? strlen(sigtraps[i].name) :
                                    ki.num_width;
                                if (w > ki.name_width)
                                        ki.name_width = w;
index 6ddd6ad..0df2c42 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: edit.c,v 1.59 2018/01/01 19:45:56 millert Exp $       */
+/*     $OpenBSD: edit.c,v 1.60 2018/01/04 19:06:16 millert Exp $       */
 
 /*
  * Command line editing - common code
@@ -224,13 +224,13 @@ set_editmode(const char *ed)
 #endif
        };
        char *rcp;
-       unsigned int ele;
+       int i;
 
        if ((rcp = strrchr(ed, '/')))
                ed = ++rcp;
-       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);
+       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);
                        return;
                }
 }
index 855bff9..87027c3 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: emacs.c,v 1.78 2018/01/01 19:45:56 millert Exp $      */
+/*     $OpenBSD: emacs.c,v 1.79 2018/01/04 19:06:16 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];
-       unsigned int            i, at = 0;
+       int                     i, at = 0;
 
        l[0] = '\0';
        for (i = 0; i < strlen(s); i++) {
@@ -1292,7 +1292,7 @@ kb_del(struct kb_entry *k)
 static struct kb_entry *
 kb_add_string(void *func, void *args, char *str)
 {
-       unsigned int            i, count;
+       int                     i, count;
        struct kb_entry         *k;
        struct x_ftab           *xf = NULL;
 
@@ -1362,7 +1362,7 @@ x_bind(const char *a1, const char *a2,
        int macro,              /* bind -m */
        int list)               /* bind -l */
 {
-       unsigned int            i;
+       int                     i;
        struct kb_entry         *k, *kb;
        char                    in[LINE + 1];
 
index 2c5b542..fddbc08 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: eval.c,v 1.55 2018/01/01 19:45:56 millert Exp $       */
+/*     $OpenBSD: eval.c,v 1.56 2018/01/04 19:06:16 millert Exp $       */
 
 /*
  * Expansion - quoting, separation, substitution, globbing
@@ -1114,11 +1114,10 @@ debunk(char *dp, const char *sp, size_t dlen)
        char *d, *s;
 
        if ((s = strchr(sp, MAGIC))) {
-               size_t slen = s - sp;
-               if (slen >= dlen)
+               if (s - sp >= dlen)
                        return dp;
-               memcpy(dp, sp, slen);
-               for (d = dp + slen; *s && (d < dp + dlen); s++)
+               memcpy(dp, sp, s - sp);
+               for (d = dp + (s - sp); *s && (d - dp < dlen); s++)
                        if (!ISMAGIC(*s) || !(*++s & 0x80) ||
                            !strchr("*+?@! ", *s & 0x7f))
                                *d++ = *s;
@@ -1126,7 +1125,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';
index 30d134d..59f5303 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: expand.h,v 1.13 2018/01/01 19:45:56 millert Exp $     */
+/*     $OpenBSD: expand.h,v 1.14 2018/01/04 19:06:16 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 { \
-                   size_t more = ((xp) + (n)) - (xs).end; \
+                   int 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, size_t more);
+char * Xcheck_grow_(XString *xsp, char *xp, int more);
 
 /*
  * expandable vector of generic pointers
index b77bf7b..80b1042 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: history.c,v 1.76 2018/01/01 19:45:56 millert Exp $    */
+/*     $OpenBSD: history.c,v 1.77 2018/01/04 19:06:16 millert Exp $    */
 
 /*
  * command history
@@ -545,7 +545,7 @@ sethistcontrol(const char *str)
 void
 sethistsize(int n)
 {
-       if (n > 0 && (uint32_t)n != histsize) {
+       if (n > 0 && n != histsize) {
                int offset = histptr - history;
 
                /* save most recent history */
index 7c1c3d9..540bedd 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lex.c,v 1.75 2018/01/01 19:45:56 millert Exp $        */
+/*     $OpenBSD: lex.c,v 1.76 2018/01/04 19:06:16 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 */
-uint32_t histsize;     /* history size */
+char  **history;       /* saved commands */
+char  **histptr;       /* last history item */
+int    histsize;       /* history size */
 
 /* optimized getsc_bn() */
 #define getsc()                (*source->str != '\0' && *source->str != '\\' \
index 457d727..a620b72 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lex.h,v 1.18 2018/01/01 19:45:56 millert Exp $        */
+/*     $OpenBSD: lex.h,v 1.19 2018/01/04 19:06:16 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 uint32_t        histsize;       /* history size */
+extern int     histsize;       /* history size */
 
 #endif /* HISTORY */
 
index 283488b..921e116 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: misc.c,v 1.62 2018/01/01 19:45:56 millert Exp $       */
+/*     $OpenBSD: misc.c,v 1.63 2018/01/04 19:06:16 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, size_t more)
+Xcheck_grow_(XString *xsp, char *xp, int more)
 {
        char *old_beg = xsp->beg;
 
@@ -181,11 +181,11 @@ const struct option sh_options[] = {
 int
 option(const char *n)
 {
-       unsigned int ele;
+       int i;
 
-       for (ele = 0; ele < NELEM(sh_options); ele++)
-               if (sh_options[ele].name && strcmp(sh_options[ele].name, n) == 0)
-                       return ele;
+       for (i = 0; i < NELEM(sh_options); i++)
+               if (sh_options[i].name && strcmp(sh_options[i].name, n) == 0)
+                       return i;
 
        return -1;
 }
@@ -216,21 +216,20 @@ options_fmt_entry(void *arg, int i, char *buf, int buflen)
 static void
 printoptions(int verbose)
 {
-       unsigned int ele;
+       int i;
 
        if (verbose) {
                struct options_info oi;
-               unsigned int n;
-               int len;
+               int n, len;
 
                /* verbose version */
                shprintf("Current option settings\n");
 
-               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;
+               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;
                                if (len > oi.opt_width)
                                        oi.opt_width = len;
                        }
@@ -240,11 +239,11 @@ printoptions(int verbose)
        } else {
                /* short version ala ksh93 */
                shprintf("set");
-               for (ele = 0; ele < NELEM(sh_options); ele++) {
-                       if (sh_options[ele].name)
+               for (i = 0; i < NELEM(sh_options); i++) {
+                       if (sh_options[i].name)
                                shprintf(" %co %s",
-                                        Flag(ele) ? '-' : '+',
-                                        sh_options[ele].name);
+                                        Flag(i) ? '-' : '+',
+                                        sh_options[i].name);
                }
                shprintf("\n");
        }
@@ -253,13 +252,13 @@ printoptions(int verbose)
 char *
 getoptions(void)
 {
-       unsigned int ele;
+       int i;
        char m[(int) FNFLAGS + 1];
        char *cp = m;
 
-       for (ele = 0; ele < NELEM(sh_options); ele++)
-               if (sh_options[ele].c && Flag(ele))
-                       *cp++ = sh_options[ele].c;
+       for (i = 0; i < NELEM(sh_options); i++)
+               if (sh_options[i].c && Flag(i))
+                       *cp++ = sh_options[i].c;
        *cp = 0;
        return str_save(m, ATEMP);
 }
@@ -334,8 +333,7 @@ parse_args(char **argv,
        char *opts;
        char *array = NULL;
        Getopt go;
-       int i, optc, sortargs = 0, arrayset = 0;
-       unsigned int ele;
+       int i, optc, set, sortargs = 0, arrayset = 0;
 
        /* First call?  Build option strings... */
        if (cmd_opts[0] == '\0') {
@@ -347,12 +345,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 (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;
+               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;
                        }
                }
                *p = '\0';
@@ -371,7 +369,7 @@ parse_args(char **argv,
                opts = set_opts;
        ksh_getopt_reset(&go, GF_ERROR|GF_PLUSOPT);
        while ((optc = ksh_getopt(argv, &go, opts)) != -1) {
-               int set = (go.info & GI_PLUS) ? 0 : 1;
+               set = (go.info & GI_PLUS) ? 0 : 1;
                switch (optc) {
                case 'A':
                        arrayset = set ? 1 : -1;
@@ -390,14 +388,14 @@ parse_args(char **argv,
                                break;
                        }
                        i = option(go.optarg);
-                       if (i != -1 && set == Flag(i))
+                       if (i >= 0 && 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 != -1 && (sh_options[i].flags & what))
+                       else if (i >= 0 && (sh_options[i].flags & what))
                                change_flag((enum sh_flag) i, what, set);
                        else {
                                bi_errorf("%s: bad option", go.optarg);
@@ -414,14 +412,14 @@ parse_args(char **argv,
                                sortargs = 1;
                                break;
                        }
-                       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,
+                       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,
                                            set);
                                        break;
                                }
-                       if (ele == NELEM(sh_options)) {
+                       if (i == NELEM(sh_options)) {
                                internal_errorf(1, "parse_args: `%c'", optc);
                                return -1; /* not reached */
                        }
@@ -510,7 +508,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)) {
-               size_t len = pe - p + 1;
+               int len = pe - p + 1;
                char tbuf[64];
                char *t = len <= sizeof(tbuf) ? tbuf :
                    alloc(len, ATEMP);
index 7262730..ff8d26e 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: path.c,v 1.20 2018/01/01 19:45:56 millert Exp $       */
+/*     $OpenBSD: path.c,v 1.21 2018/01/04 19:06:16 millert Exp $       */
 
 #include <sys/stat.h>
 
@@ -228,7 +228,7 @@ do_phys_path(XString *xsp, char *xp, const char *path)
                        p++;
                if (!*p)
                        break;
-               len = (q = strchr(p, '/')) ? (size_t)(q - p) : strlen(p);
+               len = (q = strchr(p, '/')) ? q - p : strlen(p);
                if (len == 1 && p[0] == '.')
                        continue;
                if (len == 2 && p[0] == '.' && p[1] == '.') {
index 6daed17..1760f19 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: tree.c,v 1.28 2018/01/01 19:45:56 millert Exp $       */
+/*     $OpenBSD: tree.c,v 1.29 2018/01/04 19:06:16 millert Exp $       */
 
 /*
  * command tree climbing
@@ -390,15 +390,6 @@ 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)
@@ -408,8 +399,13 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
                                p = va_arg(va, char *);
                                tputS(p, shf);
                                break;
-                       case 'u': /* unsigned decimal */
-                               p = ulton(va_arg(va, unsigned int), 10);
+                       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 = '-';
                                while (*p)
                                        tputc(*p++, shf);
                                break;
index 409489a..28a8a81 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: var.c,v 1.61 2018/01/01 19:45:56 millert Exp $        */
+/*     $OpenBSD: var.c,v 1.62 2018/01/04 19:06:16 millert Exp $        */
 
 #include <sys/stat.h>
 
@@ -306,7 +306,7 @@ str_val(struct tbl *vp)
                    "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" :
                    "0123456789abcdefghijklmnopqrstuvwxyz";
                unsigned long n;
-               unsigned int base;
+               int base;
 
                s = strbuf + sizeof(strbuf);
                if (vp->flag & INT_U)
@@ -997,7 +997,7 @@ setspec(struct tbl *vp)
                break;
        case V_HISTSIZE:
                vp->flag &= ~SPECIAL;
-               sethistsize(intval(vp));
+               sethistsize((int) intval(vp));
                vp->flag |= SPECIAL;
                break;
        case V_HISTFILE:
index af1c051..da682c8 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: vi.c,v 1.51 2018/01/01 19:45:56 millert Exp $ */
+/*     $OpenBSD: vi.c,v 1.52 2018/01/04 19:06:16 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 <= (size_t)es->linelen)
+       if (c == -1 || len <= es->linelen)
                return -1;
 
        if (es->cbuf != buf)