summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Sperling <stsp@cvs.openbsd.org>2013-05-16 12:44:49 +0000
committerStefan Sperling <stsp@cvs.openbsd.org>2013-05-16 12:44:49 +0000
commit0f6eb1b312e9754d351d10ccb2ec7e37e9a68ef3 (patch)
treeb343c96ddd9f84f12286845eb36010e0bdd2ed42
parentb944a7770f6d8c4bf0a7038f51e91d6412097b8f (diff)
Switch rcsdiff(1) binary file detection from !(isprint() || isspace()) to
checking for embedded NULs, as was done for grep(1) and diff(1) some time ago. Avoids problems with e.g. latin1-encoded files being treated as binary, since isprint() uses only ASCII by default and rcsdiff(1) doesn't call setlocale(). ok sthen
-rw-r--r--usr.bin/rcs/diff.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/usr.bin/rcs/diff.c b/usr.bin/rcs/diff.c
index 3dede6b45f2..260b2352882 100644
--- a/usr.bin/rcs/diff.c
+++ b/usr.bin/rcs/diff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff.c,v 1.33 2011/04/20 19:34:16 nicm Exp $ */
+/* $OpenBSD: diff.c,v 1.34 2013/05/16 12:44:48 stsp Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
* All rights reserved.
@@ -1132,17 +1132,14 @@ static int
asciifile(FILE *f)
{
unsigned char buf[BUFSIZ];
- size_t i, cnt;
+ size_t cnt;
if (f == NULL)
return (1);
rewind(f);
cnt = fread(buf, 1, sizeof(buf), f);
- for (i = 0; i < cnt; i++)
- if (!isprint(buf[i]) && !isspace(buf[i]))
- return (0);
- return (1);
+ return (memchr(buf, '\0', cnt) == NULL);
}
#define begins_with(s, pre) (strncmp(s, pre, sizeof(pre)-1) == 0)