Die immediately if pread fails. It's a fatal error so treat it as
authorray <ray@openbsd.org>
Thu, 15 Jul 2010 18:23:50 +0000 (18:23 +0000)
committerray <ray@openbsd.org>
Thu, 15 Jul 2010 18:23:50 +0000 (18:23 +0000)
such. Besides, we weren't handling the NULL being returned.

From diff. Minor nit by nicm.

OK xsa stsp nicm

usr.bin/cvs/diff_internals.c
usr.bin/rcs/diff.c

index 0eaf950..aa072bf 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: diff_internals.c,v 1.29 2010/07/15 11:10:23 ray Exp $ */
+/*     $OpenBSD: diff_internals.c,v 1.30 2010/07/15 18:23:50 ray Exp $ */
 /*
  * Copyright (C) Caldera International Inc.  2001-2002.
  * All rights reserved.
@@ -859,11 +859,8 @@ preadline(int fd, size_t rlen, off_t off)
        ssize_t nr;
 
        line = xmalloc(rlen + 1);
-       if ((nr = pread(fd, line, rlen, off)) < 0) {
-               cvs_log(LP_ERR, "preadline failed");
-               xfree(line);
-               return (NULL);
-       }
+       if ((nr = pread(fd, line, rlen, off)) < 0)
+               fatal("preadline: %s", strerror(errno));
        line[nr] = '\0';
        return (line);
 }
index 7c5383d..4b806bb 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: diff.c,v 1.28 2010/07/15 18:19:18 ray Exp $   */
+/*     $OpenBSD: diff.c,v 1.29 2010/07/15 18:23:50 ray Exp $   */
 /*
  * Copyright (C) Caldera International Inc.  2001-2002.
  * All rights reserved.
@@ -842,11 +842,8 @@ preadline(int fd, size_t rlen, off_t off)
        ssize_t nr;
 
        line = xmalloc(rlen + 1);
-       if ((nr = pread(fd, line, rlen, off)) < 0) {
-               warn("preadline failed");
-               xfree(line);
-               return (NULL);
-       }
+       if ((nr = pread(fd, line, rlen, off)) < 0)
+               err(D_ERROR, "preadline");
        line[nr] = '\0';
        return (line);
 }