[PATCH] quotearg: improve USE_C_LOCALE + UTF-8

Paul Eggert <[email protected]>
Newsgroups gmane.comp.lib.gnulib.bugs
Message-ID <[email protected]>
Problem reported by Bruno Haible <https://bugs.gnu.org/81135>.
* lib/quotearg.c (chisprint, wchisprint) [USE_C_LOCALE]:
Treat unassigned characters as printable.
---
 ChangeLog      |  7 +++++++
 lib/quotearg.c | 16 ++++++++--------
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a3aa3fc9ae..e6ce36d261 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2026-05-29  Paul Eggert  <[email protected]>
+
+	quotearg: improve USE_C_LOCALE + UTF-8
+	Problem reported by Bruno Haible <https://bugs.gnu.org/81135>.
+	* lib/quotearg.c (chisprint, wchisprint) [USE_C_LOCALE]:
+	Treat unassigned characters as printable.
+
 2026-05-28  Paul Eggert  <[email protected]>
 
 	manywarnings: -Wstrict-overflow is deprecated
diff --git a/lib/quotearg.c b/lib/quotearg.c
index 64850af1e1..ea6fde1aca 100644
--- a/lib/quotearg.c
+++ b/lib/quotearg.c
@@ -39,12 +39,12 @@
 #include <stdlib.h>
 #include <string.h>
 
-/* If USE_C_LOCALE is nonzero, this file defines a function that uses the
-   "C" locale, regardless of the current locale.  Applications
-   defining this macro might avoid the need for Gnulib's c32isprint,
-   gettext-h, mbrtoc32, mbsinit, wchar-h, and uchar-h modules,
-   but they also need the c-ctype module, and they rely on
-   the mbszero module defining MUSL_LIBC as needed.  */
+/* If USE_C_LOCALE is nonzero, this file defines functions that
+   use the "C" locale, regardless of the current locale.
+   The functions also treat unassigned characters as printable.
+   Applications defining this macro might avoid the need for Gnulib's
+   c32isprint, gettext-h, mbrtoc32, mbsinit, and uchar-h modules,
+   but they also need the c-ctype module.  */
 #ifndef USE_C_LOCALE
 # define USE_C_LOCALE 0
 #endif
@@ -109,7 +109,7 @@ static bool
 chisprint (unsigned char c)
 {
 #if USE_C_LOCALE
-  return c_isprint (c);
+  return !c_iscntrl (c);
 #else
   return isprint (c) != 0;
 #endif
@@ -121,7 +121,7 @@ wchisprint (wch w)
 #if !USE_C_LOCALE
   return c32isprint (w);
 #elif C_LOCALE_MIGHT_BE_MULTIBYTE
-  return iswprint (w);
+  return iswcntrl (w) == 0;
 #else
   return chisprint (w);
 #endif
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.