]> Savannah Git Hosting - gnulib.git/commitdiff
nl_langinfo: Fix multithread-safety bug on OpenBSD 3.8.
authorBruno Haible <bruno@clisp.org>
Tue, 17 Dec 2019 13:10:45 +0000 (14:10 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 17 Dec 2019 13:10:45 +0000 (14:10 +0100)
* lib/nl_langinfo.c (ctype_codeset): Invoke setlocale_null instead of
setlocale.
* m4/nl_langinfo.m4 (gl_FUNC_NL_LANGINFO): Require
gl_FUNC_SETLOCALE_NULL. Set LIB_NL_LANGINFO.
* modules/nl_langinfo (Depends-on): Add setlocale-null.

ChangeLog
lib/nl_langinfo.c
m4/nl_langinfo.m4
modules/nl_langinfo

index bb6b22b26d967401a8fc8b3726c453790308e3ee..a42ab8efe6b8cce57d25b10140699d68b04e7529 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2019-12-17  Bruno Haible  <bruno@clisp.org>
+
+       nl_langinfo: Fix multithread-safety bug on OpenBSD 3.8.
+       * lib/nl_langinfo.c (ctype_codeset): Invoke setlocale_null instead of
+       setlocale.
+       * m4/nl_langinfo.m4 (gl_FUNC_NL_LANGINFO): Require
+       gl_FUNC_SETLOCALE_NULL. Set LIB_NL_LANGINFO.
+       * modules/nl_langinfo (Depends-on): Add setlocale-null.
+
 2019-12-17  Bruno Haible  <bruno@clisp.org>
 
        nl_langinfo: Fix multithread-safety bug on mingw and MSVC.
index 2c4d3a4f58b9f9463f20249b6eb850bc3272aa04..ff0e93600c8e7457a2e9c3590c1703cdc56bfcb7 100644 (file)
@@ -47,9 +47,14 @@ ctype_codeset (void)
 {
   static char result[2 + 10 + 1];
   char buf[2 + 10 + 1];
-  char const *locale = setlocale (LC_CTYPE, NULL);
-  char *codeset = buf;
+  char locale[SETLOCALE_NULL_MAX];
+  char *codeset;
   size_t codesetlen;
+
+  if (setlocale_null (LC_CTYPE, locale, sizeof (locale)))
+    locale[0] = '\0';
+
+  codeset = buf;
   codeset[0] = '\0';
 
   if (locale && locale[0])
index 66eee41d8895dc8545459475a1c615faba21c515..c62d8e7e7867140be815293506c5d8c671294534 100644 (file)
@@ -1,4 +1,4 @@
-# nl_langinfo.m4 serial 6
+# nl_langinfo.m4 serial 7
 dnl Copyright (C) 2009-2019 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -10,6 +10,7 @@ AC_DEFUN([gl_FUNC_NL_LANGINFO],
   AC_REQUIRE([gl_LANGINFO_H])
   AC_CHECK_FUNCS_ONCE([nl_langinfo])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_REQUIRE([gl_FUNC_SETLOCALE_NULL])
   if test $ac_cv_func_nl_langinfo = yes; then
     # On Irix 6.5, YESEXPR is defined, but nl_langinfo(YESEXPR) is broken.
     AC_CACHE_CHECK([whether YESEXPR works],
@@ -50,4 +51,11 @@ AC_DEFUN([gl_FUNC_NL_LANGINFO],
   else
     HAVE_NL_LANGINFO=0
   fi
+  if test $HAVE_NL_LANGINFO = 0 || test $HAVE_LANGINFO_CODESET = 0; then
+    LIB_NL_LANGINFO="$LIB_SETLOCALE_NULL"
+  else
+    LIB_NL_LANGINFO=
+  fi
+  dnl LIB_NL_LANGINFO is expected to be empty everywhere.
+  AC_SUBST([LIB_NL_LANGINFO])
 ])
index cd8ce44bf35e09f33c945afd90b478641f7f86f9..aeeec095ac03a86c9c5f93913b882dd01308bba1 100644 (file)
@@ -8,6 +8,7 @@ m4/nl_langinfo.m4
 Depends-on:
 langinfo
 localeconv      [test $HAVE_NL_LANGINFO = 0 || test $REPLACE_NL_LANGINFO = 1]
+setlocale-null  [test $HAVE_NL_LANGINFO = 0 || test $HAVE_LANGINFO_CODESET = 0]
 
 configure.ac:
 gl_FUNC_NL_LANGINFO