Add WARNINGS=yes to ksh and fix the resulting sign compare warnings. Still passes regress. Note that gcc is pickier than clang in this respect as it requires a matching sign for ternary operations.
I tried to limit the use of casts. - todd Index: Makefile =================================================================== RCS file: /cvs/src/bin/ksh/Makefile,v retrieving revision 1.35 diff -u -p -u -r1.35 Makefile --- Makefile 27 Dec 2017 13:02:57 -0000 1.35 +++ Makefile 27 Dec 2017 13:58:59 -0000 @@ -6,7 +6,8 @@ SRCS= alloc.c c_ksh.c c_sh.c c_test.c 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 Index: c_ksh.c =================================================================== RCS file: /cvs/src/bin/ksh/c_ksh.c,v retrieving revision 1.52 diff -u -p -u -r1.52 c_ksh.c --- c_ksh.c 27 Dec 2017 13:02:57 -0000 1.52 +++ c_ksh.c 27 Dec 2017 13:58:59 -0000 @@ -1194,7 +1194,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; Index: edit.c =================================================================== RCS file: /cvs/src/bin/ksh/edit.c,v retrieving revision 1.58 diff -u -p -u -r1.58 edit.c --- edit.c 27 Dec 2017 13:02:57 -0000 1.58 +++ edit.c 27 Dec 2017 13:58:59 -0000 @@ -224,7 +224,7 @@ set_editmode(const char *ed) #endif }; char *rcp; - int i; + unsigned int i; if ((rcp = strrchr(ed, '/'))) ed = ++rcp; Index: emacs.c =================================================================== RCS file: /cvs/src/bin/ksh/emacs.c,v retrieving revision 1.77 diff -u -p -u -r1.77 emacs.c --- emacs.c 27 Dec 2017 13:02:57 -0000 1.77 +++ emacs.c 27 Dec 2017 13:58:59 -0000 @@ -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,7 +1292,7 @@ kb_del(struct kb_entry *k) static struct kb_entry * kb_add_string(void *func, void *args, char *str) { - int i, count; + unsigned 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 */ { - int i; + unsigned int i; struct kb_entry *k, *kb; char in[LINE + 1]; Index: eval.c =================================================================== RCS file: /cvs/src/bin/ksh/eval.c,v retrieving revision 1.54 diff -u -p -u -r1.54 eval.c --- eval.c 27 Aug 2017 00:29:04 -0000 1.54 +++ eval.c 27 Dec 2017 13:59:00 -0000 @@ -1114,10 +1114,11 @@ debunk(char *dp, const char *sp, size_t 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 /* extended pattern operators: *+?@! */ if ((*s & 0x7f) != ' ') *d++ = *s & 0x7f; - if (d - dp < dlen) + if (d < dp + dlen) *d++ = '('; } *d = '\0'; Index: expand.h =================================================================== RCS file: /cvs/src/bin/ksh/expand.h,v retrieving revision 1.12 diff -u -p -u -r1.12 expand.h --- expand.h 8 Nov 2015 17:52:43 -0000 1.12 +++ expand.h 27 Dec 2017 13:59:00 -0000 @@ -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; \ + size_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 Index: history.c =================================================================== RCS file: /cvs/src/bin/ksh/history.c,v retrieving revision 1.75 diff -u -p -u -r1.75 history.c --- history.c 21 Nov 2017 17:57:41 -0000 1.75 +++ history.c 27 Dec 2017 13:59:00 -0000 @@ -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 */ Index: lex.c =================================================================== RCS file: /cvs/src/bin/ksh/lex.c,v retrieving revision 1.74 diff -u -p -u -r1.74 lex.c --- lex.c 27 Dec 2017 13:02:57 -0000 1.74 +++ lex.c 27 Dec 2017 13:59:00 -0000 @@ -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 != '\\' \ Index: lex.h =================================================================== RCS file: /cvs/src/bin/ksh/lex.h,v retrieving revision 1.17 diff -u -p -u -r1.17 lex.h --- lex.h 7 Dec 2017 01:54:33 -0000 1.17 +++ lex.h 27 Dec 2017 13:59:00 -0000 @@ -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 */ Index: misc.c =================================================================== RCS file: /cvs/src/bin/ksh/misc.c,v retrieving revision 1.61 diff -u -p -u -r1.61 misc.c --- misc.c 27 Dec 2017 13:02:57 -0000 1.61 +++ misc.c 27 Dec 2017 13:59:00 -0000 @@ -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; @@ -181,7 +181,7 @@ const struct option sh_options[] = { int option(const char *n) { - int i; + unsigned int i; for (i = 0; i < NELEM(sh_options); i++) if (sh_options[i].name && strcmp(sh_options[i].name, n) == 0) @@ -216,11 +216,12 @@ options_fmt_entry(void *arg, int i, char static void printoptions(int verbose) { - int i; + unsigned int i; if (verbose) { struct options_info oi; - int n, len; + unsigned int n; + int len; /* verbose version */ shprintf("Current option settings\n"); @@ -252,7 +253,7 @@ printoptions(int verbose) char * getoptions(void) { - int i; + unsigned int i; char m[(int) FNFLAGS + 1]; char *cp = m; @@ -333,7 +334,8 @@ parse_args(char **argv, char *opts; char *array = NULL; Getopt go; - int i, optc, set, sortargs = 0, arrayset = 0; + int res, optc, sortargs = 0, arrayset = 0; + unsigned int i; /* First call? Build option strings... */ if (cmd_opts[0] == '\0') { @@ -369,7 +371,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; @@ -387,16 +389,16 @@ parse_args(char **argv, printoptions(set); break; } - i = option(go.optarg); - if (i >= 0 && set == Flag(i)) + res = option(go.optarg); + if (res != -1 && set == Flag(res)) /* 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)) - change_flag((enum sh_flag) i, what, set); + else if (res != -1 && (sh_options[res].flags & what)) + change_flag((enum sh_flag) res, what, set); else { bi_errorf("%s: bad option", go.optarg); return -1; @@ -508,7 +510,7 @@ gmatch(const char *s, const char *p, int * 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); Index: path.c =================================================================== RCS file: /cvs/src/bin/ksh/path.c,v retrieving revision 1.19 diff -u -p -u -r1.19 path.c --- path.c 3 Sep 2017 11:52:01 -0000 1.19 +++ path.c 27 Dec 2017 13:59:00 -0000 @@ -228,7 +228,7 @@ do_phys_path(XString *xsp, char *xp, con 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] == '.') { Index: tree.c =================================================================== RCS file: /cvs/src/bin/ksh/tree.c,v retrieving revision 1.27 diff -u -p -u -r1.27 tree.c --- tree.c 1 Nov 2015 15:38:53 -0000 1.27 +++ tree.c 27 Dec 2017 13:59:00 -0000 @@ -390,6 +390,15 @@ vfptreef(struct shf *shf, int indent, co 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, co 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; Index: var.c =================================================================== RCS file: /cvs/src/bin/ksh/var.c,v retrieving revision 1.60 diff -u -p -u -r1.60 var.c --- var.c 27 Dec 2017 13:02:57 -0000 1.60 +++ var.c 27 Dec 2017 13:59:00 -0000 @@ -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) @@ -997,7 +997,7 @@ setspec(struct tbl *vp) break; case V_HISTSIZE: vp->flag &= ~SPECIAL; - sethistsize((int) intval(vp)); + sethistsize(intval(vp)); vp->flag |= SPECIAL; break; case V_HISTFILE: Index: vi.c =================================================================== RCS file: /cvs/src/bin/ksh/vi.c,v retrieving revision 1.50 diff -u -p -u -r1.50 vi.c --- vi.c 27 Nov 2017 04:23:50 -0000 1.50 +++ vi.c 27 Dec 2017 13:59:00 -0000 @@ -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)