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.
This commit is contained in:
Kyle Evans committed 2020-04-27 22:34:45 +00:00
1 parent 56abb2db24
commit f5a5ea795d
3 files changed
+11 -11
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/stable/11/; revision=360405

No files matched your search

+3 -3
View File
@@ -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@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],
+6 -6
View File
@@ -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 capsicum)
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 capsicum)
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--;
+2 -2
View File
@@ -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@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@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;