Author: pfg
Date: Mon Dec 12 20:25:59 2016
New Revision: 309936
URL: https://svnweb.freebsd.org/changeset/base/309936

Log:
  ed(1): Simplify some checks.
  
  The return type for both fread(3) and fwrite(3) cannot be negative, this
  renders some checks invalid and variable 'ct' unnecessary.
  Also bump 'len' to size_t to avoid signed/unsigned comparison warnings.

Modified:
  head/bin/ed/buf.c

Modified: head/bin/ed/buf.c
==============================================================================
--- head/bin/ed/buf.c   Mon Dec 12 20:04:31 2016        (r309935)
+++ head/bin/ed/buf.c   Mon Dec 12 20:25:59 2016        (r309936)
@@ -46,9 +46,9 @@ char *
 get_sbuf_line(line_t *lp)
 {
        static char *sfbuf = NULL;      /* buffer */
-       static int sfbufsz = 0;         /* buffer size */
+       static size_t sfbufsz;          /* buffer size */
 
-       int len, ct;
+       size_t len;
 
        if (lp == &buffer_head)
                return NULL;
@@ -64,7 +64,7 @@ get_sbuf_line(line_t *lp)
        }
        len = lp->len;
        REALLOC(sfbuf, sfbufsz, len + 1, NULL);
-       if ((ct = fread(sfbuf, sizeof(char), len, sfp)) <  0 || ct != len) {
+       if ((fread(sfbuf, sizeof(char), len, sfp)) != len) {
                fprintf(stderr, "%s\n", strerror(errno));
                errmsg = "cannot read temp file";
                return NULL;
@@ -81,7 +81,7 @@ const char *
 put_sbuf_line(const char *cs)
 {
        line_t *lp;
-       int len, ct;
+       size_t len;
        const char *s;
 
        if ((lp = (line_t *) malloc(sizeof(line_t))) == NULL) {
@@ -110,7 +110,7 @@ put_sbuf_line(const char *cs)
                seek_write = 0;
        }
        /* assert: SPL1() */
-       if ((ct = fwrite(cs, sizeof(char), len, sfp)) < 0 || ct != len) {
+       if ((fwrite(cs, sizeof(char), len, sfp)) != len) {
                sfseek = -1;
                fprintf(stderr, "%s\n", strerror(errno));
                errmsg = "cannot write temp file";
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to