summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcheloha <cheloha@openbsd.org>2018-09-29 16:17:35 +0000
committercheloha <cheloha@openbsd.org>2018-09-29 16:17:35 +0000
commitdb2f9856a871605acd8ed3b1a8597ff9677368c6 (patch)
tree8e1e3bf1e2230e421edc7ac7174a155a39658175
parentunmark -beta. There is still development happening, and we aren't (diff)
downloadwireguard-openbsd-db2f9856a871605acd8ed3b1a8597ff9677368c6.tar.xz
wireguard-openbsd-db2f9856a871605acd8ed3b1a8597ff9677368c6.zip
Treat NUL like any other byte in the default case; aligns newline count
with that of the '-l' case. From David Hines on bugs@. ok millert@
-rw-r--r--usr.bin/wc/wc.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/usr.bin/wc/wc.c b/usr.bin/wc/wc.c
index 4f2e862c45b..04f8d5c576d 100644
--- a/usr.bin/wc/wc.c
+++ b/usr.bin/wc/wc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wc.c,v 1.22 2018/04/26 12:42:51 guenther Exp $ */
+/* $OpenBSD: wc.c,v 1.23 2018/09/29 16:17:35 cheloha Exp $ */
/*
* Copyright (c) 1980, 1987, 1991, 1993
@@ -209,7 +209,8 @@ cnt(char *file)
gotsp = 1;
while ((len = getline(&buf, &bufsz, stream)) > 0) {
if (multibyte) {
- for (C = buf; *C != '\0'; C += len) {
+ const char *end = buf + len;
+ for (C = buf; C < end; C += len) {
++charct;
len = mbtowc(&wc, C, MB_CUR_MAX);
if (len == -1) {
@@ -229,7 +230,7 @@ cnt(char *file)
}
} else {
charct += len;
- for (C = buf; *C != '\0'; ++C) {
+ for (C = buf; len--; ++C) {
if (isspace((unsigned char)*C)) {
gotsp = 1;
if (*C == '\n')