svn commit: r360405 - stable/11/usr.bin/diff
Kyle Evans
kevans at FreeBSD.org
Mon Apr 27 22:34:46 UTC 2020
Author: kevans
Date: Mon Apr 27 22:34:45 2020
New Revision: 360405
URL: https://svnweb.freebsd.org/changeset/base/360405
Log:
MFC r356723-r356725: diff(1) return value checks
r356723:
mkstemp returns -1
r356724:
asprintf returns -1, not an arbitrary value < 0. Also upon error the
(very sloppy specification) leaves an undefined value in *ret, so it is
wrong to inspect it, the error condition is enough.
r356725:
When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case.
Modified:
stable/11/usr.bin/diff/diff.c
stable/11/usr.bin/diff/diffreg.c
stable/11/usr.bin/diff/xmalloc.c
Directory Properties:
stable/11/ (props changed)
Modified: stable/11/usr.bin/diff/diff.c
==============================================================================
--- stable/11/usr.bin/diff/diff.c Mon Apr 27 22:33:32 2020 (r360404)
+++ stable/11/usr.bin/diff/diff.c Mon Apr 27 22:34:45 2020 (r360405)
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff.c,v 1.65 2015/12/29 19:04:46 gsoares Exp $ */
+/* $OpenBSD: diff.c,v 1.67 2019/06/28 13:35:00 deraadt Exp $ */
/*
* Copyright (c) 2003 Todd C. Miller <Todd.Miller at courtesan.com>
@@ -316,12 +316,12 @@ main(int argc, char **argv)
} else {
if (S_ISDIR(stb1.st_mode)) {
argv[0] = splice(argv[0], argv[1]);
- if (stat(argv[0], &stb1) < 0)
+ if (stat(argv[0], &stb1) == -1)
err(2, "%s", argv[0]);
}
if (S_ISDIR(stb2.st_mode)) {
argv[1] = splice(argv[1], argv[0]);
- if (stat(argv[1], &stb2) < 0)
+ if (stat(argv[1], &stb2) == -1)
err(2, "%s", argv[1]);
}
print_status(diffreg(argv[0], argv[1], dflags, 1), argv[0],
Modified: stable/11/usr.bin/diff/diffreg.c
==============================================================================
--- stable/11/usr.bin/diff/diffreg.c Mon Apr 27 22:33:32 2020 (r360404)
+++ stable/11/usr.bin/diff/diffreg.c Mon Apr 27 22:34:45 2020 (r360405)
@@ -1,4 +1,4 @@
-/* $OpenBSD: diffreg.c,v 1.91 2016/03/01 20:57:35 natano Exp $ */
+/* $OpenBSD: diffreg.c,v 1.93 2019/06/28 13:35:00 deraadt Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
@@ -287,7 +287,7 @@ diffreg(char *file1, char *file2, int flags, int capsi
else {
if (!S_ISREG(stb1.st_mode)) {
if ((f1 = opentemp(file1)) == NULL ||
- fstat(fileno(f1), &stb1) < 0) {
+ fstat(fileno(f1), &stb1) == -1) {
warn("%s", file1);
status |= 2;
goto closem;
@@ -308,7 +308,7 @@ diffreg(char *file1, char *file2, int flags, int capsi
else {
if (!S_ISREG(stb2.st_mode)) {
if ((f2 = opentemp(file2)) == NULL ||
- fstat(fileno(f2), &stb2) < 0) {
+ fstat(fileno(f2), &stb2) == -1) {
warn("%s", file2);
status |= 2;
goto closem;
@@ -515,12 +515,12 @@ opentemp(const char *f)
if (strcmp(f, "-") == 0)
ifd = STDIN_FILENO;
- else if ((ifd = open(f, O_RDONLY, 0644)) < 0)
+ else if ((ifd = open(f, O_RDONLY, 0644)) == -1)
return (NULL);
(void)strlcpy(tempfile, _PATH_TMP "/diff.XXXXXXXX", sizeof(tempfile));
- if ((ofd = mkstemp(tempfile)) < 0) {
+ if ((ofd = mkstemp(tempfile)) == -1) {
close(ifd);
return (NULL);
}
@@ -1011,7 +1011,7 @@ preadline(int fd, size_t rlen, off_t off)
ssize_t nr;
line = xmalloc(rlen + 1);
- if ((nr = pread(fd, line, rlen, off)) < 0)
+ if ((nr = pread(fd, line, rlen, off)) == -1)
err(2, "preadline");
if (nr > 0 && line[nr-1] == '\n')
nr--;
Modified: stable/11/usr.bin/diff/xmalloc.c
==============================================================================
--- stable/11/usr.bin/diff/xmalloc.c Mon Apr 27 22:33:32 2020 (r360404)
+++ stable/11/usr.bin/diff/xmalloc.c Mon Apr 27 22:34:45 2020 (r360405)
@@ -1,4 +1,4 @@
-/* $OpenBSD: xmalloc.c,v 1.9 2015/11/17 18:25:02 tobias Exp $ */
+/* $OpenBSD: xmalloc.c,v 1.10 2019/06/28 05:44:09 deraadt Exp $ */
/*
* Author: Tatu Ylonen <ylo at cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo at cs.hut.fi>, Espoo, Finland
@@ -81,7 +81,7 @@ xasprintf(char **ret, const char *fmt, ...)
i = vasprintf(ret, fmt, ap);
va_end(ap);
- if (i < 0 || *ret == NULL)
+ if (i == -1)
err(2, "xasprintf");
return i;
More information about the svn-src-all
mailing list