"GOT", but the "O" is a cute, smiling sun Index | Thread

From:
Tom Jones <thj@freebsd.org>
Subject:
diff: fread cannot return -1
To:
gameoftrees@openbsd.org
Date:
Tue, 11 Oct 2022 09:43:37 +0100

Download raw body.

fread returns a size_t and can never be -1. fread can signal parameter
errors on some platforms, but this isn't portable. Remove this check and
break out of the loop when fread returns 0.

- Tom
diff --git a/lib/diff_debug.h b/lib/diff_debug.h
index 0ed8a5e..4b7ec80 100644
--- a/lib/diff_debug.h
+++ b/lib/diff_debug.h
@@ -58,8 +58,6 @@ dump_atom(const struct diff_data *left, const struct diff_data *right,
 			int i;
 			r = fread(buf, 1, MIN(remain, sizeof(buf)),
 			    atom->root->f);
-			if (r == -1)
-				abort(); /* cannot return error */
 			if (r == 0)
 				break;
 			remain -= r;