From 47bc90320f03d4b4e990a3ddd8411e4e330d7d1e Mon Sep 17 00:00:00 2001 From: bapt Date: Sat, 30 Apr 2016 14:48:30 +0000 Subject: [PATCH] When checking for binary file, check if ch is not EOF only ch actually got a value assigned Reported by: pfg --- usr.bin/sdiff/sdiff.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/usr.bin/sdiff/sdiff.c b/usr.bin/sdiff/sdiff.c index 0c822aae738b..3a97e1041562 100644 --- a/usr.bin/sdiff/sdiff.c +++ b/usr.bin/sdiff/sdiff.c @@ -514,12 +514,14 @@ istextfile(FILE *f) if (f == NULL) return (1); rewind(f); - for (i = 0; i <= MAX_CHECK || ch != EOF; i++) { + for (i = 0; i <= MAX_CHECK; i++) { ch = fgetc(f); if (ch == '\0') { rewind(f); return (0); } + if (ch == EOF) + break; } rewind(f); return (1);