]> Savannah Git Hosting - gnulib.git/commitdiff
vasnwprintf-posix: Work around a musl libc bug.
authorBruno Haible <bruno@clisp.org>
Mon, 12 Jun 2023 14:48:03 +0000 (16:48 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 12 Jun 2023 17:13:20 +0000 (19:13 +0200)
* m4/vasnprintf.m4 (gl_PREREQ_VASNWPRINTF): Test also whether swprintf
in the C locale is free of encoding errors, and set
NEED_WPRINTF_DIRECTIVE_C if not.
* doc/posix-functions/swprintf.texi: Clarify the list of platforms for
the %c problem.

ChangeLog
doc/posix-functions/swprintf.texi
m4/vasnprintf.m4

index 406170ce6dcf068fd841e926addeed70d7ddde81..aebce47f42897098297869c3616979763f623615 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-06-12  Bruno Haible  <bruno@clisp.org>
+
+       vasnwprintf-posix: Work around a musl libc bug.
+       * m4/vasnprintf.m4 (gl_PREREQ_VASNWPRINTF): Test also whether swprintf
+       in the C locale is free of encoding errors, and set
+       NEED_WPRINTF_DIRECTIVE_C if not.
+       * doc/posix-functions/swprintf.texi: Clarify the list of platforms for
+       the %c problem.
+
 2023-06-12  Bruno Haible  <bruno@clisp.org>
 
        vasnwprintf: Fix some cross-compilation results.
index 649b541ed0691831cbcf5f3a86b44e6e4ca2c7e7..68578e016bc3fc9ab4766bdad89d42151c00cb07 100644 (file)
@@ -72,7 +72,7 @@ instead.
 @item
 In the C or POSIX locales, the @code{%c} and @code{%s} conversions may fail
 on some platforms:
-glibc 2.35.
+glibc 2.35, musl libc 1.2.4, FreeBSD 13.2, NetBSD 9.3, OpenBSD 7.2, Cygwin 2.9.0.
 @item
 When formatting an integer with grouping flag, this function inserts thousands
 separators even in the "C" locale on some platforms:
index 639b29a1f394709c536d6adef533612c0499fce6..b733f9a84814c8bac602aba8f0f3f9d355044b3b 100644 (file)
@@ -1,4 +1,4 @@
-# vasnprintf.m4 serial 49
+# vasnprintf.m4 serial 50
 dnl Copyright (C) 2002-2004, 2006-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -107,13 +107,56 @@ AC_DEFUN_ONCE([gl_PREREQ_VASNWPRINTF],
   esac
   gl_MBRTOWC_C_LOCALE
   case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in
-    *yes) ;;
-    *)
-      AC_DEFINE([NEED_WPRINTF_DIRECTIVE_C], [1],
-        [Define if the vasnwprintf implementation needs special code for
-         the 'c' directive.])
+    *yes)
+      AC_CACHE_CHECK([whether swprintf in the C locale is free of encoding errors],
+        [gl_cv_func_swprintf_C_locale_sans_EILSEQ],
+        [
+          AC_RUN_IFELSE(
+            [AC_LANG_SOURCE([[
+#ifndef __USE_MINGW_ANSI_STDIO
+# define __USE_MINGW_ANSI_STDIO 1
+#endif
+#include <stdio.h>
+#include <wchar.h>
+int main()
+{
+  int result = 0;
+  { /* This test fails on glibc 2.35, musl libc 1.2.4, FreeBSD 13.2, NetBSD 9.3,
+       OpenBSD 7.2, Cygwin 2.9.0.
+       Reported at <https://www.openwall.com/lists/musl/2023/06/12/2>.  */
+    wchar_t buf[12];
+    int ret = swprintf (buf, 12, L"%c", '\377');
+    if (ret < 0)
+      result |= 1;
+  }
+  return result;
+}]])],
+            [gl_cv_func_swprintf_C_locale_sans_EILSEQ=yes],
+            [gl_cv_func_swprintf_C_locale_sans_EILSEQ=no],
+            [case "$host_os" in
+                                   # Guess no on glibc systems.
+               *-gnu* | gnu*)      gl_cv_func_swprintf_C_locale_sans_EILSEQ="guessing yes";;
+                                   # Guess no on musl systems.
+               *-musl* | midipix*) gl_cv_func_swprintf_C_locale_sans_EILSEQ="guessing no";;
+                                   # If we don't know, obey --enable-cross-guesses.
+               *)                  gl_cv_func_swprintf_C_locale_sans_EILSEQ="$gl_cross_guess_normal";;
+             esac
+            ])
+        ])
       ;;
   esac
+  if case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in
+       *yes) false ;;
+       *) true ;;
+     esac \
+     || case "$gl_cv_func_swprintf_C_locale_sans_EILSEQ" in
+          *yes) false ;;
+          *) true ;;
+        esac; then
+    AC_DEFINE([NEED_WPRINTF_DIRECTIVE_C], [1],
+      [Define if the vasnwprintf implementation needs special code for
+       the 'c' directive.])
+  fi
   gl_SWPRINTF_DIRECTIVE_LA
   case "$gl_cv_func_swprintf_directive_la" in
     *yes) ;;