From fbfc2664030502c0cad8ba1ff6d8d328e3843509 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 12 Dec 2019 17:52:50 +0100 Subject: [PATCH] duplocale: Fix test failure on AIX 7.2 with xlclang. * lib/duplocale.c: Include . (rpl_duplocale): Use a heap-allocated copy of the first setlocale return value. --- ChangeLog | 7 +++++++ lib/duplocale.c | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index edbcab28e2..6f4f764de7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2019-12-12 Bruno Haible + + duplocale: Fix test failure on AIX 7.2 with xlclang. + * lib/duplocale.c: Include . + (rpl_duplocale): Use a heap-allocated copy of the first setlocale return + value. + 2019-12-12 Bruno Haible stddef: Document the AIX xlc issue. diff --git a/lib/duplocale.c b/lib/duplocale.c index eaecf8cb44..3b958bab51 100644 --- a/lib/duplocale.c +++ b/lib/duplocale.c @@ -22,6 +22,7 @@ #include #include +#include #include #define SIZEOF(a) (sizeof(a) / sizeof(a[0])) @@ -67,14 +68,21 @@ rpl_duplocale (locale_t locale) , { LC_IDENTIFICATION, LC_IDENTIFICATION_MASK } #endif }; - const char *base_name; + char *base_name; locale_t base_copy; unsigned int i; - base_name = setlocale (LC_CTYPE, NULL); + base_name = strdup (setlocale (LC_CTYPE, NULL)); + if (base_name == NULL) + return NULL; base_copy = newlocale (LC_ALL_MASK, base_name, NULL); if (base_copy == NULL) - return NULL; + { + int saved_errno = errno; + free (base_name); + errno = saved_errno; + return NULL; + } for (i = 0; i < SIZEOF (categories); i++) { @@ -88,6 +96,7 @@ rpl_duplocale (locale_t locale) { int saved_errno = errno; freelocale (base_copy); + free (base_name); errno = saved_errno; return NULL; } @@ -97,6 +106,7 @@ rpl_duplocale (locale_t locale) } } + free (base_name); return base_copy; } -- 2.39.5