summaryrefslogtreecommitdiff
path: root/usr.bin/wc/wc.c
diff options
context:
space:
mode:
authorcheloha <cheloha@cvs.openbsd.org>2018-09-29 16:17:36 +0000
committercheloha <cheloha@cvs.openbsd.org>2018-09-29 16:17:36 +0000
commitf088f212fa5df79ace0adee7fb73ab4f99c7d7b5 (patch)
tree25d2490932ec74dd6be1dea057d4bcf492e50fde /usr.bin/wc/wc.c
parentbb7f4d6e95024aa99f7380ff5f5e3611f4aca941 (diff)
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@
Diffstat (limited to 'usr.bin/wc/wc.c')
-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')