Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Feb 2026 06:15:39 +0000
From:      Colin Percival <cperciva@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Cc:        Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject:   git: 3c10ed2ba3aa - releng/14.4 - diff: Report I/O errors in Stone algorithm
Message-ID:  <698c1e8b.33b68.58cd342e@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch releng/14.4 has been updated by cperciva:

URL: https://cgit.FreeBSD.org/src/commit/?id=3c10ed2ba3aaef386e57e6078d6d8421429a55d7

commit 3c10ed2ba3aaef386e57e6078d6d8421429a55d7
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-02-05 17:41:56 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2026-02-11 06:14:50 +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.
    
    Approved by:    re (cperciva)
    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)
    (cherry picked from commit 37ceb8794c22d88a41e261d23d347bc7ac08b2c8)
---
 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 954e0542b576..6ade8bfb8237 100644
--- a/usr.bin/diff/diffreg.c
+++ b/usr.bin/diff/diffreg.c
@@ -381,6 +381,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;
@@ -474,9 +478,9 @@ files_differ(FILE *f1, FILE *f2, int flags)
 		return (0);
 
 	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);


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?698c1e8b.33b68.58cd342e>