From: millert Date: Wed, 13 Dec 2017 16:06:34 +0000 (+0000) Subject: Fix sign compare warnings; OK martijn@ X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=59d77f5c783aa6cfef50d393a5a58f808980ed16;p=openbsd Fix sign compare warnings; OK martijn@ --- diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c index 113adf671f3..cef3fddbbe7 100644 --- a/usr.bin/sed/compile.c +++ b/usr.bin/sed/compile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: compile.c,v 1.45 2017/12/12 12:52:01 martijn Exp $ */ +/* $OpenBSD: compile.c,v 1.46 2017/12/13 16:06:34 millert Exp $ */ /*- * Copyright (c) 1992 Diomidis Spinellis. @@ -458,7 +458,7 @@ compile_subst(char *p, struct s_subst *s) { static char *lbuf; static size_t bufsize; - int asize, ref, size; + size_t asize, ref, size; char c, *text, *op, *sp; int sawesc = 0; @@ -665,9 +665,9 @@ compile_tr(char *old, char **transtab) static char * compile_text(void) { - int asize, esc_nl, size; + size_t asize, size, bufsize; char *lbuf, *text, *p, *op, *s; - size_t bufsize; + int esc_nl; lbuf = text = NULL; asize = size = 0; diff --git a/usr.bin/sed/defs.h b/usr.bin/sed/defs.h index 4864d620399..2543401c010 100644 --- a/usr.bin/sed/defs.h +++ b/usr.bin/sed/defs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: defs.h,v 1.8 2017/01/20 10:26:16 krw Exp $ */ +/* $OpenBSD: defs.h,v 1.9 2017/12/13 16:06:34 millert Exp $ */ /*- * Copyright (c) 1992 Diomidis Spinellis. * Copyright (c) 1992, 1993 @@ -63,7 +63,7 @@ struct s_subst { char *wfile; /* NULL if no wfile */ int wfd; /* Cached file descriptor */ regex_t *re; /* Regular expression */ - int maxbref; /* Largest backreference. */ + u_int maxbref; /* Largest backreference. */ u_long linenum; /* Line number. */ char *new; /* Replacement text */ }; diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c index 69fcbde2a2d..3ddc5e7a7a1 100644 --- a/usr.bin/sed/main.c +++ b/usr.bin/sed/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.35 2017/08/01 18:05:53 martijn Exp $ */ +/* $OpenBSD: main.c,v 1.36 2017/12/13 16:06:34 millert Exp $ */ /*- * Copyright (c) 1992 Diomidis Spinellis. @@ -237,9 +237,9 @@ again: state = ST_FILE; goto again; case CU_STRING: - if ((snprintf(string_ident, - sizeof(string_ident), "\"%s\"", script->s)) >= - sizeof(string_ident)) + len = snprintf(string_ident, sizeof(string_ident), + "\"%s\"", script->s); + if (len >= sizeof(string_ident)) strlcpy(string_ident + sizeof(string_ident) - 6, " ...\"", 5); fname = string_ident; diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c index d8192aa01e0..654cf758ab8 100644 --- a/usr.bin/sed/process.c +++ b/usr.bin/sed/process.c @@ -1,4 +1,4 @@ -/* $OpenBSD: process.c,v 1.32 2017/02/22 14:09:09 tom Exp $ */ +/* $OpenBSD: process.c,v 1.33 2017/12/13 16:06:34 millert Exp $ */ /*- * Copyright (c) 1992 Diomidis Spinellis. @@ -67,7 +67,7 @@ static void regsub(SPACE *, char *, char *); static int substitute(struct s_command *); struct s_appends *appends; /* Array of pointers to strings to append. */ -static int appendx; /* Index into appends array. */ +static size_t appendx; /* Index into appends array. */ size_t appendnum; /* Size of appends array. */ static int lastaddr; /* Set by applies if last address of a range. */ @@ -227,7 +227,7 @@ redirect: DEFFILEMODE)) == -1) error(FATAL, "%s: %s", cp->t, strerror(errno)); - if (write(cp->u.fd, ps, psl) != psl || + if ((size_t)write(cp->u.fd, ps, psl) != psl || write(cp->u.fd, "\n", 1) != 1) error(FATAL, "%s: %s", cp->t, strerror(errno)); @@ -334,7 +334,7 @@ substitute(struct s_command *cp) regex_t *re; regoff_t slen; int n, lastempty; - size_t le = 0; + regoff_t le = 0; char *s; s = ps; @@ -428,7 +428,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) error(FATAL, "%s: %s", cp->u.s->wfile, strerror(errno)); - if (write(cp->u.s->wfd, ps, psl) != psl || + if ((size_t)write(cp->u.s->wfd, ps, psl) != psl || write(cp->u.s->wfd, "\n", 1) != 1) error(FATAL, "%s: %s", cp->u.s->wfile, strerror(errno)); } @@ -443,13 +443,13 @@ static void flush_appends(void) { FILE *f; - int count, i; + size_t count, idx; char buf[8 * 1024]; - for (i = 0; i < appendx; i++) - switch (appends[i].type) { + for (idx = 0; idx < appendx; idx++) + switch (appends[idx].type) { case AP_STRING: - fwrite(appends[i].s, sizeof(char), appends[i].len, + fwrite(appends[idx].s, sizeof(char), appends[idx].len, outfile); break; case AP_FILE: @@ -461,7 +461,7 @@ flush_appends(void) * would be truly bizarre, but possible. It's probably * not that big a performance win, anyhow. */ - if ((f = fopen(appends[i].s, "r")) == NULL) + if ((f = fopen(appends[idx].s, "r")) == NULL) break; while ((count = fread(buf, sizeof(char), sizeof(buf), f))) (void)fwrite(buf, sizeof(char), count, outfile);