- s/%q/%ll
- cast off_t to long long for printf()
- delete pointless casts to off_t, void*, and uid_t when that's the 
  argument's type
- s/0L/0/
- when casting to a larger type for multiplication, cast *before* 
  multiplying!  Wrong: (off_t)(x * y)    Right: (off_t)x * y

ok?


Index: libexec/ftpd/ftpcmd.y
===================================================================
RCS file: /data/src/openbsd/src/libexec/ftpd/ftpcmd.y,v
retrieving revision 1.62
diff -u -p -r1.62 ftpcmd.y
--- libexec/ftpd/ftpcmd.y       16 Nov 2015 17:31:14 -0000      1.62
+++ libexec/ftpd/ftpcmd.y       14 Aug 2016 22:09:54 -0000
@@ -143,7 +143,7 @@ cmd_list
                                free(fromname);
                                fromname = NULL;
                        }
-                       restart_point = (off_t) 0;
+                       restart_point = 0;
                }
        | cmd_list rcmd
        ;
@@ -638,7 +638,7 @@ cmd
 rcmd
        : RNFR check_login SP pathname CRLF
                {
-                       restart_point = (off_t) 0;
+                       restart_point = 0;
                        if ($2 && $4) {
                                if (fromname)
                                        free(fromname);
Index: libexec/ftpd/ftpd.c
===================================================================
RCS file: /data/src/openbsd/src/libexec/ftpd/ftpd.c,v
retrieving revision 1.217
diff -u -p -r1.217 ftpd.c
--- libexec/ftpd/ftpd.c 4 Jul 2016 03:24:48 -0000       1.217
+++ libexec/ftpd/ftpd.c 14 Aug 2016 22:14:10 -0000
@@ -185,11 +185,11 @@ char      proctitle[BUFSIZ];      /* initial part 
                *(file2) == '/' ? "" : curdir(), file2);
 #define LOGBYTES(cmd, file, cnt) \
        if (logging > 1) { \
-               if (cnt == (off_t)-1) \
+               if (cnt == -1) \
                    syslog(LOG_INFO,"%s %s%s", cmd, \
                        *(file) == '/' ? "" : curdir(), file); \
                else \
-                   syslog(LOG_INFO, "%s %s%s = %qd bytes", \
+                   syslog(LOG_INFO, "%s %s%s = %lld bytes", \
                        cmd, (*(file) == '/') ? "" : curdir(), file, cnt); \
        }
 
@@ -979,7 +979,7 @@ pass(char *passwd)
                flags |= LOGIN_SETUMASK;
        else
                (void) umask(defumask);
-       if (setusercontext(lc, pw, (uid_t)0, flags) != 0) {
+       if (setusercontext(lc, pw, 0, flags) != 0) {
                perror_reply(421, "Local resource failure: setusercontext");
                syslog(LOG_NOTICE, "setusercontext: %m");
                dologout(1);
@@ -992,7 +992,7 @@ pass(char *passwd)
 
        /* open utmp before chroot */
        if (doutmp) {
-               memset((void *)&utmp, 0, sizeof(utmp));
+               memset(&utmp, 0, sizeof(utmp));
                (void)time(&utmp.ut_time);
                (void)strncpy(utmp.ut_name, pw->pw_name, sizeof(utmp.ut_name));
                (void)strncpy(utmp.ut_host, remotehost, sizeof(utmp.ut_host));
@@ -1205,7 +1205,7 @@ retrieve(char *cmd, char *name)
        if (dout == NULL)
                goto done;
        time(&start);
-       send_data(fin, dout, (off_t)st.st_blksize, st.st_size,
+       send_data(fin, dout, st.st_blksize, st.st_size,
            (restart_point == 0 && cmd == NULL && S_ISREG(st.st_mode)));
        if ((cmd == NULL) && stats)
                logxfer(name, byte_count, start);
@@ -1277,7 +1277,7 @@ store(char *name, char *mode, int unique
                         * because we are changing from reading to
                         * writing.
                         */
-                       if (fseek(fout, 0L, SEEK_CUR) < 0) {
+                       if (fseek(fout, 0, SEEK_CUR) < 0) {
                                perror_reply(550, name);
                                goto done;
                        }
@@ -1286,7 +1286,7 @@ store(char *name, char *mode, int unique
                        goto done;
                }
        }
-       din = dataconn(name, (off_t)-1, "r");
+       din = dataconn(name, -1, "r");
        if (din == NULL)
                goto done;
        if (receive_data(din, fout) == 0) {
@@ -1380,9 +1380,9 @@ dataconn(char *name, off_t size, char *m
 
        file_size = size;
        byte_count = 0;
-       if (size != (off_t) -1) {
-               (void) snprintf(sizebuf, sizeof(sizebuf), " (%qd bytes)",
-                   size);
+       if (size != -1) {
+               (void) snprintf(sizebuf, sizeof(sizebuf), " (%lld bytes)",
+                   (long long)size);
        } else
                sizebuf[0] = '\0';
        if (pdata >= 0) {
@@ -1573,7 +1573,7 @@ send_data(FILE *instr, FILE *outstr, off
                netfd = fileno(outstr);
                filefd = fileno(instr);
 
-               if (isreg && filesize < (off_t)16 * 1024 * 1024) {
+               if (isreg && filesize < 16 * 1024 * 1024) {
                        size_t fsize = (size_t)filesize;
 
                        if (fsize == 0) {
@@ -1582,8 +1582,7 @@ send_data(FILE *instr, FILE *outstr, off
                                return(0);
                        }
 
-                       buf = mmap(0, fsize, PROT_READ, MAP_SHARED, filefd,
-                           (off_t)0);
+                       buf = mmap(0, fsize, PROT_READ, MAP_SHARED, filefd, 0);
                        if (buf == MAP_FAILED) {
                                syslog(LOG_WARNING, "mmap(%llu): %m",
                                    (unsigned long long)fsize);
@@ -2236,11 +2235,12 @@ myoob(void)
        }
        if (strcmp(cp, "STAT\r\n") == 0) {
                tmpline[0] = '\0';
-               if (file_size != (off_t) -1)
-                       reply(213, "Status: %qd of %qd bytes transferred",
-                           byte_count, file_size);
+               if (file_size != -1)
+                       reply(213, "Status: %lld of %lld bytes transferred",
+                           (long long)byte_count, (long long)file_size);
                else
-                       reply(213, "Status: %qd bytes transferred", byte_count);
+                       reply(213, "Status: %lld bytes transferred",
+                           (long long)byte_count);
        }
 }
 
@@ -2680,7 +2680,7 @@ send_file_list(char *whichf)
 
                if (S_ISREG(st.st_mode)) {
                        if (dout == NULL) {
-                               dout = dataconn("file list", (off_t)-1, "w");
+                               dout = dataconn("file list", -1, "w");
                                if (dout == NULL)
                                        goto out;
                                transflag++;
@@ -2721,8 +2721,7 @@ send_file_list(char *whichf)
                            (fstatat(dirfd(dirp), dir->d_name, &st, 0) == 0 &&
                            S_ISREG(st.st_mode))) {
                                if (dout == NULL) {
-                                       dout = dataconn("file list", (off_t)-1,
-                                               "w");
+                                       dout = dataconn("file list", -1, "w");
                                        if (dout == NULL)
                                                goto out;
                                        transflag++;
@@ -2802,7 +2801,7 @@ logxfer(char *name, off_t size, time_t s
                strvis(vpw, guest? guestpw : pw->pw_name, VIS_SAFE|VIS_NOSLASH);
 
                len = snprintf(buf, sizeof(buf),
-                   "%.24s %lld %s %qd %s %c %s %c %c %s ftp %d %s %s\n",
+                   "%.24s %lld %s %lld %s %c %s %c %c %s ftp %d %s %s\n",
                    ctime(&now), (long long)(now - start + (now == start)),
                    vremotehost, (long long)size, vpath,
                    ((type == TYPE_A) ? 'a' : 'b'), "*" /* none yet */,
Index: libexec/ftpd/logutmp.c
===================================================================
RCS file: /data/src/openbsd/src/libexec/ftpd/logutmp.c,v
retrieving revision 1.12
diff -u -p -r1.12 logutmp.c
--- libexec/ftpd/logutmp.c      25 Oct 2014 03:19:22 -0000      1.12
+++ libexec/ftpd/logutmp.c      14 Aug 2016 22:10:39 -0000
@@ -76,7 +76,7 @@ ftpd_login(struct utmp *ut)
        /*
         * Now find a slot that's not in use...
         */
-       (void)lseek(fd, (off_t)(topslot * sizeof(struct utmp)), SEEK_SET);
+       (void)lseek(fd, (off_t)topslot * sizeof(struct utmp), SEEK_SET);
 
        while (1) {
                if (read(fd, &ubuf, sizeof(struct utmp)) ==
@@ -88,8 +88,8 @@ ftpd_login(struct utmp *ut)
                        }
                        topslot++;
                } else {
-                       (void)lseek(fd, (off_t)(topslot *
-                           sizeof(struct utmp)), SEEK_SET);
+                       (void)lseek(fd, (off_t)topslot * sizeof(struct utmp),
+                           SEEK_SET);
                        break;
                }
        }

Reply via email to