From: Pádraig Brady
Date: Wed, 23 Feb 2022 17:50:46 +0000 (+0000)
Subject: fmt: fix invalid multi-byte splitting on macOS
X-Git-Tag: v9.1~40
X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6dc702928ec84b9d511396e756184403fd96cc6c;p=thirdparty%2Fcoreutils.git
fmt: fix invalid multi-byte splitting on macOS
On macOS, isspace(0x85) returns true,
which results in splitting within multi-byte characters.
* src/fmt.c (get_line): s/isspace/c_isspace/.
* tests/fmt/non-space.sh: Add a new test.
* tests/local.mk: Reference new test.
* NEWS: Mention the fix.
Addresses https://bugs.gnu.org/54124
---
diff --git a/NEWS b/NEWS
index b6713bfc50..eec705b2f4 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,10 @@ GNU coreutils NEWS -*- outline -*-
and B is in some other file system.
[bug introduced in coreutils-9.0]
+ On macOS, fmt no longer corrupts multi-byte characters
+ by misdetecting their component bytes as spaces.
+ [This bug was present in "the beginning".]
+
'id xyz' now uses the name 'xyz' to determine groups, instead of xyz's uid.
[bug introduced in coreutils-8.22]
diff --git a/src/fmt.c b/src/fmt.c
index 1eb7019b04..05bafabd6c 100644
--- a/src/fmt.c
+++ b/src/fmt.c
@@ -26,6 +26,7 @@
it to be a type get syntax errors for the variable declaration below. */
#define word unused_word_type
+#include "c-ctype.h"
#include "system.h"
#include "error.h"
#include "die.h"
@@ -702,7 +703,7 @@ get_line (FILE *f, int c)
*wptr++ = c;
c = getc (f);
}
- while (c != EOF && !isspace (c));
+ while (c != EOF && !c_isspace (c));
in_column += word_limit->length = wptr - word_limit->text;
check_punctuation (word_limit);
diff --git a/tests/fmt/non-space.sh b/tests/fmt/non-space.sh
new file mode 100755
index 0000000000..093c9393ac
--- /dev/null
+++ b/tests/fmt/non-space.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+# Test fmt space handling
+
+# Copyright (C) 2022 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see