From d3e5e11ce68f43e7cb5f7546533dbd0fa9b20e47 Mon Sep 17 00:00:00 2001 From: David Malone Date: Sat, 9 Feb 2008 09:12:02 +0000 Subject: [PATCH] WARNS fixes: 1) Add missing parens around assignment that is compared to zero. 2) Make some variables that only take non-negative values unsigned. 3) Some casts/type changes to fix other constness warnings. 4) Make one variable a const char *. 5) Make sure termwidth is positive, it doesn't make sense for it to be negative. Approved by: dds --- usr.bin/sed/compile.c | 2 +- usr.bin/sed/defs.h | 6 +++--- usr.bin/sed/main.c | 2 +- usr.bin/sed/process.c | 12 +++++++----- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c index 635e058eac6..2e3a2ced23c 100644 --- a/usr.bin/sed/compile.c +++ b/usr.bin/sed/compile.c @@ -443,7 +443,7 @@ compile_re(char *re, int case_insensitive) flags |= REG_ICASE; if ((rep = malloc(sizeof(regex_t))) == NULL) err(1, "malloc"); - if (eval = regcomp(rep, re, flags) != 0) + if ((eval = regcomp(rep, re, flags)) != 0) errx(1, "%lu: %s: RE error: %s", linenum, fname, strregerror(eval, rep)); if (maxnsub < rep->re_nsub) diff --git a/usr.bin/sed/defs.h b/usr.bin/sed/defs.h index cbc0790afa1..895e719d47b 100644 --- a/usr.bin/sed/defs.h +++ b/usr.bin/sed/defs.h @@ -64,7 +64,7 @@ struct s_subst { char *wfile; /* NULL if no wfile */ int wfd; /* Cached file descriptor */ regex_t *re; /* Regular expression */ - int maxbref; /* Largest backreference. */ + unsigned int maxbref; /* Largest backreference. */ u_long linenum; /* Line number. */ char *new; /* Replacement text */ }; @@ -75,9 +75,9 @@ struct s_subst { struct s_tr { unsigned char bytetab[256]; struct trmulti { - int fromlen; + size_t fromlen; char from[MB_LEN_MAX]; - int tolen; + size_t tolen; char to[MB_LEN_MAX]; } *multis; int nmultis; diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c index b3fa1f5fa21..1a140b14414 100644 --- a/usr.bin/sed/main.c +++ b/usr.bin/sed/main.c @@ -232,7 +232,7 @@ again: state = ST_FILE; goto again; case CU_STRING: - if ((snprintf(string_ident, + if (((size_t)snprintf(string_ident, sizeof(string_ident), "\"%s\"", script->s)) >= sizeof(string_ident) - 1) (void)strcpy(string_ident + diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c index fb3f9004f9e..a29fe0ea8c7 100644 --- a/usr.bin/sed/process.c +++ b/usr.bin/sed/process.c @@ -229,7 +229,7 @@ redirect: O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, DEFFILEMODE)) == -1) err(1, "%s", cp->t); - if (write(cp->u.fd, ps, psl) != psl || + if (write(cp->u.fd, ps, psl) != (ssize_t)psl || write(cp->u.fd, "\n", 1) != 1) err(1, "%s", cp->t); break; @@ -363,7 +363,7 @@ substitute(struct s_command *cp) if (re == NULL) { if (defpreg != NULL && cp->u.s->maxbref > defpreg->re_nsub) { linenum = cp->u.s->linenum; - errx(1, "%lu: %s: \\%d not defined in the RE", + errx(1, "%lu: %s: \\%u not defined in the RE", linenum, fname, cp->u.s->maxbref); } } @@ -449,7 +449,7 @@ substitute(struct s_command *cp) if (cp->u.s->wfd == -1 && (cp->u.s->wfd = open(cp->u.s->wfile, O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, DEFFILEMODE)) == -1) err(1, "%s", cp->u.s->wfile); - if (write(cp->u.s->wfd, ps, psl) != psl || + if (write(cp->u.s->wfd, ps, psl) != (ssize_t)psl || write(cp->u.s->wfd, "\n", 1) != 1) err(1, "%s", cp->u.s->wfile); } @@ -554,7 +554,7 @@ lputs(char *s, size_t len) { static const char escapes[] = "\\\a\b\f\r\t\v"; int c, col, width; - char *p; + const char *p; struct winsize win; static int termwidth = -1; size_t clen, i; @@ -572,6 +572,8 @@ lputs(char *s, size_t len) else termwidth = 60; } + if (termwidth <= 0) + termwidth = 1; memset(&mbs, 0, sizeof(mbs)); col = 0; @@ -607,7 +609,7 @@ lputs(char *s, size_t len) fprintf(outfile, "\\%c", "\\abfrtv"[p - escapes]); col += 2; } else { - if (col + 4 * clen >= termwidth) { + if (col + 4 * clen >= (unsigned)termwidth) { fprintf(outfile, "\\\n"); col = 0; }