git: 641366df41d8 - stable/13 - diff: Report I/O errors in Stone algorithm
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 10 Feb 2026 15:28:15 UTC
The branch stable/13 has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=641366df41d8e2a3bde877b712a08de8a49a76ee
commit 641366df41d8e2a3bde877b712a08de8a49a76ee
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-02-05 17:41:56 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-02-10 14:24:30 +0000
diff: Report I/O errors in Stone algorithm
In the legacy Stone algorithm, we do a first pass over the files to
check if they're identical before we start diffing them. That code
would correctly set the exit status if an I/O error was encountered,
but would not emit an error message. Do so.
PR: 292198
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: thj
Differential Revision: https://reviews.freebsd.org/D55125
(cherry picked from commit f8c12e6e3874cdd353fb16785da6f4e7eb134cd9)
---
usr.bin/diff/diffreg.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c
index ea7732bb6d99..78f3569a0ecc 100644
--- a/usr.bin/diff/diffreg.c
+++ b/usr.bin/diff/diffreg.c
@@ -369,6 +369,10 @@ diffreg(char *file1, char *file2, int flags, int capsicum)
break;
default:
/* error */
+ if (ferror(f1))
+ warn("%s", file1);
+ if (ferror(f2))
+ warn("%s", file2);
rval = D_ERROR;
status |= 2;
goto closem;
@@ -458,9 +462,9 @@ files_differ(FILE *f1, FILE *f2, int flags)
(stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT))
return (1);
for (;;) {
- i = fread(buf1, 1, sizeof(buf1), f1);
- j = fread(buf2, 1, sizeof(buf2), f2);
- if ((!i && ferror(f1)) || (!j && ferror(f2)))
+ if ((i = fread(buf1, 1, sizeof(buf1), f1)) == 0 && ferror(f1))
+ return (-1);
+ if ((j = fread(buf2, 1, sizeof(buf2), f2)) == 0 && ferror(f2))
return (-1);
if (i != j)
return (1);