diff options
author | 2012-07-08 15:48:56 +0000 | |
---|---|---|
committer | 2012-07-08 15:48:56 +0000 | |
commit | 0631431f7b2c0aa4f75021c3bf71b9dcc647c3d8 (patch) | |
tree | dab5a9dc6b75ee716bf16bee2801ce076fc287d9 /usr.bin/diff/diffreg.c | |
parent | - plug text_to_relayhost() in parse.y to support relay URLs. (diff) | |
download | wireguard-openbsd-0631431f7b2c0aa4f75021c3bf71b9dcc647c3d8.tar.xz wireguard-openbsd-0631431f7b2c0aa4f75021c3bf71b9dcc647c3d8.zip |
Switch diff(1) binary file detection from !(isprint() || isspace()) to
checking for embedded NULs, as was done for grep(1) some time ago.
Avoids problems with e.g. latin1-encoded files being treated as binary, since
isprint() uses only ASCII by default and diff(1) doesn't call setlocale().
prodded by and ok bluhm
Diffstat (limited to 'usr.bin/diff/diffreg.c')
-rw-r--r-- | usr.bin/diff/diffreg.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index 80907aa5554..14f0d17bf32 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diffreg.c,v 1.81 2012/05/22 12:30:24 millert Exp $ */ +/* $OpenBSD: diffreg.c,v 1.82 2012/07/08 15:48:56 stsp Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. @@ -1288,17 +1288,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) |