Fix sign compare warnings; OK martijn@
authormillert <millert@openbsd.org>
Wed, 13 Dec 2017 16:06:34 +0000 (16:06 +0000)
committermillert <millert@openbsd.org>
Wed, 13 Dec 2017 16:06:34 +0000 (16:06 +0000)
usr.bin/sed/compile.c
usr.bin/sed/defs.h
usr.bin/sed/main.c
usr.bin/sed/process.c

index 113adf6..cef3fdd 100644 (file)
@@ -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;
index 4864d62..2543401 100644 (file)
@@ -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 */
 };
index 69fcbde..3ddc5e7 100644 (file)
@@ -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;
index d8192aa..654cf75 100644 (file)
@@ -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);