Oops - my patch contained a bug (though it worked on my machine).
Here is a corrected patch for /usr/src/usr.bin/wc/wc.c
diff -r a60ac28f79ee wc.c
--- a/wc.c Wed Sep 26 17:49:53 2018 +0100
+++ b/wc.c Thu Sep 27 16:16:02 2018 +0100
@@ -208,7 +208,8 @@
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) {
@@ -228,7 +229,7 @@
}
} else {
charct += len;
- for (C = buf; *C != '\0'; ++C) {
+ for (C = buf; len--; ++C) {
if (isspace((unsigned char)*C)) {
gotsp = 1;
if (*C == '\n')