Quiet some sign warnings from the compiler.  The common "st.st_size
> SIZE_MAX" check causes many of them.  To avoid this we need to
cast st_size (which is off_t) to a large unsigned type.  I think
uintmax_t makes the most sense for this.

 - todd

Index: buf.c
===================================================================
RCS file: /cvs/src/usr.bin/cvs/buf.c,v
retrieving revision 1.83
diff -u -p -u -r1.83 buf.c
--- buf.c       5 Nov 2015 09:48:21 -0000       1.83
+++ buf.c       12 Oct 2016 18:18:38 -0000
@@ -106,7 +106,7 @@ buf_load_fd(int fd)
        if (lseek(fd, 0, SEEK_SET) == -1)
                fatal("buf_load_fd: lseek: %s", strerror(errno));
 
-       if (st.st_size > SIZE_MAX)
+       if ((uintmax_t)st.st_size > SIZE_MAX)
                fatal("buf_load_fd: file size too big");
        buf = buf_alloc(st.st_size);
        if (atomicio(read, fd, buf->cb_buf, buf->cb_size) != buf->cb_size)
Index: buf.h
===================================================================
RCS file: /cvs/src/usr.bin/cvs/buf.h,v
retrieving revision 1.28
diff -u -p -u -r1.28 buf.h
--- buf.h       1 Aug 2010 09:55:40 -0000       1.28
+++ buf.h       12 Oct 2016 18:10:34 -0000
@@ -30,6 +30,7 @@
 #include <sys/types.h>
 
 typedef struct buf BUF;
+struct timeval;
 
 BUF            *buf_alloc(size_t);
 BUF            *buf_load(const char *);
Index: diff3.c
===================================================================
RCS file: /cvs/src/usr.bin/cvs/diff3.c,v
retrieving revision 1.59
diff -u -p -u -r1.59 diff3.c
--- diff3.c     5 Nov 2015 09:48:21 -0000       1.59
+++ diff3.c     12 Oct 2016 18:21:38 -0000
@@ -295,7 +295,8 @@ diff3_internal(int argc, char **argv, co
        free(overlap);
        free(de);
 
-       de = d13 = d23 = overlap = NULL;
+       de = d13 = d23 = NULL;
+       overlap = NULL;
 
        increase();
 
@@ -793,7 +794,7 @@ edscript(int n)
                (void)fseek(fp[2], (long)de[n].new.from, SEEK_SET);
                for (k = de[n].new.to-de[n].new.from; k > 0; k-= j) {
                        j = k > BUFSIZ ? BUFSIZ : k;
-                       if (fread(block, 1, j, fp[2]) != j)
+                       if (fread(block, 1, j, fp[2]) != (size_t)j)
                                return (-1);
                        block[j] = '\0';
                        diff_output("%s", block);
Index: diff_internals.c
===================================================================
RCS file: /cvs/src/usr.bin/cvs/diff_internals.c,v
retrieving revision 1.38
diff -u -p -u -r1.38 diff_internals.c
--- diff_internals.c    5 Nov 2015 09:48:21 -0000       1.38
+++ diff_internals.c    12 Oct 2016 18:22:48 -0000
@@ -455,13 +455,13 @@ prepare(int i, FILE *fd, off_t filesize,
 
        rewind(fd);
 
-       sz = (filesize <= SIZE_MAX ? filesize : SIZE_MAX) / 25;
+       sz = ((uintmax_t)filesize <= SIZE_MAX ? (size_t)filesize : SIZE_MAX) / 
25;
        if (sz < 100)
                sz = 100;
 
        p = xcalloc(sz + 3, sizeof(*p));
        for (j = 0; (h = readhash(fd, flags));) {
-               if (j == sz) {
+               if ((size_t)j == sz) {
                        sz = sz * 3 / 2;
                        p = xreallocarray(p, sz + 3, sizeof(*p));
                }
Index: file.c
===================================================================
RCS file: /cvs/src/usr.bin/cvs/file.c,v
retrieving revision 1.267
diff -u -p -u -r1.267 file.c
--- file.c      5 Nov 2015 09:48:21 -0000       1.267
+++ file.c      12 Oct 2016 18:25:47 -0000
@@ -461,12 +461,13 @@ cvs_file_walkdir(struct cvs_file *cf, st
                fatal("cvs_file_walkdir: %s %s", cf->file_path,
                    strerror(errno));
 
-       if (st.st_size > SIZE_MAX)
+       if ((uintmax_t)st.st_size > SIZE_MAX)
                fatal("cvs_file_walkdir: %s: file size too big", cf->file_name);
 
-       bufsize = st.st_size;
-       if (bufsize < st.st_blksize)
+       if (st.st_size < st.st_blksize)
                bufsize = st.st_blksize;
+       else
+               bufsize = st.st_size;
 
        buf = xmalloc(bufsize);
        RB_INIT(&fl);
@@ -1032,7 +1033,7 @@ cvs_file_cmp(const char *file1, const ch
        if (S_ISREG(stb1.st_mode)) {
                void *p1, *p2;
 
-               if (stb1.st_size > SIZE_MAX) {
+               if ((uintmax_t)stb1.st_size > SIZE_MAX) {
                        ret = 1;
                        goto out;
                }
@@ -1089,7 +1090,7 @@ cvs_file_copy(const char *from, const ch
                char *p;
                int saved_errno;
 
-               if (st.st_size > SIZE_MAX) {
+               if ((uintmax_t)st.st_size > SIZE_MAX) {
                        ret = -1;
                        goto out;
                }
@@ -1108,7 +1109,7 @@ cvs_file_copy(const char *from, const ch
 
                madvise(p, st.st_size, MADV_SEQUENTIAL);
 
-               if (atomicio(vwrite, dst, p, st.st_size) != st.st_size) {
+               if (atomicio(vwrite, dst, p, st.st_size) != (size_t)st.st_size) 
{
                        saved_errno = errno;
                        (void)unlink(to);
                        fatal("cvs_file_copy: `%s': %s", from,
Index: getlog.c
===================================================================
RCS file: /cvs/src/usr.bin/cvs/getlog.c,v
retrieving revision 1.98
diff -u -p -u -r1.98 getlog.c
--- getlog.c    1 Dec 2014 21:58:46 -0000       1.98
+++ getlog.c    12 Oct 2016 18:27:04 -0000
@@ -233,7 +233,7 @@ cvs_log_local(struct cvs_file *cf)
        if (logrev != NULL)
                nrev = cvs_revision_select(cf->file_rcs, logrev);
        else if (logdate != NULL) {
-               if ((nrev = date_select(cf->file_rcs, logdate)) == -1) {
+               if ((nrev = date_select(cf->file_rcs, logdate)) == (u_int)-1) {
                        cvs_log(LP_ERR, "invalid date: %s", logdate);
                        return;
                }
Index: logmsg.c
===================================================================
RCS file: /cvs/src/usr.bin/cvs/logmsg.c,v
retrieving revision 1.58
diff -u -p -u -r1.58 logmsg.c
--- logmsg.c    16 Aug 2016 19:00:59 -0000      1.58
+++ logmsg.c    12 Oct 2016 18:27:35 -0000
@@ -59,7 +59,7 @@ cvs_logmsg_read(const char *path)
        if ((fp = fdopen(fd, "r")) == NULL)
                fatal("cvs_logmsg_read: fdopen %s", strerror(errno));
 
-       if (st.st_size > SIZE_MAX)
+       if ((uintmax_t)st.st_size > SIZE_MAX)
                fatal("cvs_logmsg_read: %s: file size too big", path);
 
        lbuf = NULL;
@@ -142,7 +142,7 @@ cvs_logmsg_create(char *dir, struct cvs_
                        if ((rp = fdopen(rd, "r")) == NULL)
                                fatal("cvs_logmsg_create: fdopen %s",
                                    strerror(errno));
-                       if (st.st_size > SIZE_MAX)
+                       if ((uintmax_t)st.st_size > SIZE_MAX)
                                fatal("cvs_logmsg_create: %s: file size "
                                    "too big", line->line);
                        logmsg = xmalloc(st.st_size);
Index: rcs.c
===================================================================
RCS file: /cvs/src/usr.bin/cvs/rcs.c,v
retrieving revision 1.313
diff -u -p -u -r1.313 rcs.c
--- rcs.c       5 Nov 2015 09:48:21 -0000       1.313
+++ rcs.c       12 Oct 2016 18:31:04 -0000
@@ -2434,7 +2434,7 @@ rcs_kwexp_line(char *rcsfile, struct rcs
                                            "truncated");
 
                                lp = xcalloc(1, sizeof(*lp));
-                               xasprintf(&(lp->l_line), "%s%s\n",
+                               xasprintf((char *)&(lp->l_line), "%s%s\n",
                                    prefix, linebuf);
                                lp->l_len = strlen(lp->l_line);
                                TAILQ_INSERT_AFTER(&(lines->l_lines), cur, lp,
@@ -2448,10 +2448,10 @@ rcs_kwexp_line(char *rcsfile, struct rcs
                                        lp = xcalloc(1, sizeof(*lp));
 
                                        if (l_line[0] == '\0') {
-                                               xasprintf(&(lp->l_line), "%s\n",
-                                                   sprefix);
+                                               xasprintf((char *)&(lp->l_line),
+                                                   "%s\n", sprefix);
                                        } else {
-                                               xasprintf(&(lp->l_line),
+                                               xasprintf((char *)&(lp->l_line),
                                                    "%s%s\n", prefix, l_line);
                                        }
 
Index: update.c
===================================================================
RCS file: /cvs/src/usr.bin/cvs/update.c,v
retrieving revision 1.171
diff -u -p -u -r1.171 update.c
--- update.c    5 Nov 2015 09:48:21 -0000       1.171
+++ update.c    12 Oct 2016 18:25:37 -0000
@@ -259,13 +259,14 @@ cvs_update_leavedir(struct cvs_file *cf)
        if (fstat(cf->fd, &st) == -1)
                fatal("cvs_update_leavedir: %s", strerror(errno));
 
-       bufsize = st.st_size;
-       if (bufsize < st.st_blksize)
-               bufsize = st.st_blksize;
-
-       if (st.st_size > SIZE_MAX)
+       if ((uintmax_t)st.st_size > SIZE_MAX)
                fatal("cvs_update_leavedir: %s: file size too big",
                    cf->file_name);
+
+       if (st.st_size < st.st_blksize)
+               bufsize = st.st_blksize;
+       else
+               bufsize = st.st_size;
 
        isempty = 1;
        buf = xmalloc(bufsize);

Reply via email to