summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2022-09-11 16:20:56 +0200
committerBruno Haible <bruno@clisp.org>2022-10-09 09:30:35 +0200
commit47753d61727886ec3b701a0eeb32c30c8a87f460 (patch)
tree4b76787f2538a905aad5452113eb791cbb51b161
parentdb403c15ff04562a25c520cfe14e2e1f0e1435a2 (diff)
downloadgettext-47753d61727886ec3b701a0eeb32c30c8a87f460.tar.gz
Update after gnulib changed.
* gettext-runtime/intl/arg-nonnull.h: Update from gnulib. * gettext-runtime/intl/localename.c: Likewise. * gettext-runtime/intl/lock.h: Likewise. * gettext-runtime/intl/relocatable.c: Likewise. * gettext-runtime/intl/relocatable.h: Likewise. * gettext-runtime/intl/threadlib.c: Likewise. * gettext-runtime/intl/vasnprintf.c: Likewise. * gettext-runtime/intl/verify.h: Likewise. * gettext-runtime/intl/xsize.h: Likewise. * gettext-runtime/libasprintf/vasnprintf.c: Likewise. * gettext-runtime/m4/fcntl-o.m4: Likewise. * gettext-runtime/m4/iconv.m4: Likewise. * gettext-runtime/m4/flexmember.m4: Update copyright years. * gettext-runtime/m4/intlmacosx.m4: Likewise. * gettext-runtime/m4/inttypes_h.m4: Likewise. * gettext-runtime/m4/nls.m4: Likewise. * gettext-runtime/m4/po.m4: Likewise. * gettext-runtime/m4/progtest.m4: Likewise. * gettext-runtime/m4/size_max.m4: Likewise. * gettext-runtime/m4/stdint_h.m4: Likewise. * gettext-runtime/m4/xsize.m4: Likewise. * Makefile.am (distcheck-hook): Update.
-rw-r--r--Makefile.am4
-rw-r--r--gettext-runtime/intl/arg-nonnull.h4
-rw-r--r--gettext-runtime/intl/localename.c64
-rw-r--r--gettext-runtime/intl/lock.h6
-rw-r--r--gettext-runtime/intl/relocatable.c15
-rw-r--r--gettext-runtime/intl/relocatable.h7
-rw-r--r--gettext-runtime/intl/threadlib.c37
-rw-r--r--gettext-runtime/intl/vasnprintf.c127
-rw-r--r--gettext-runtime/intl/verify.h71
-rw-r--r--gettext-runtime/intl/xsize.h14
-rw-r--r--gettext-runtime/libasprintf/vasnprintf.c127
-rw-r--r--gettext-runtime/m4/fcntl-o.m45
-rw-r--r--gettext-runtime/m4/flexmember.m42
-rw-r--r--gettext-runtime/m4/iconv.m467
-rw-r--r--gettext-runtime/m4/intlmacosx.m42
-rw-r--r--gettext-runtime/m4/inttypes_h.m42
-rw-r--r--gettext-runtime/m4/nls.m42
-rw-r--r--gettext-runtime/m4/po.m42
-rw-r--r--gettext-runtime/m4/progtest.m42
-rw-r--r--gettext-runtime/m4/size_max.m42
-rw-r--r--gettext-runtime/m4/stdint_h.m42
-rw-r--r--gettext-runtime/m4/xsize.m42
22 files changed, 315 insertions, 251 deletions
diff --git a/Makefile.am b/Makefile.am
index 815e3c7d0..2526eb3dd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,5 @@
## Makefile for the toplevel directory of GNU gettext
-## Copyright (C) 1995-2020 Free Software Foundation, Inc.
+## Copyright (C) 1995-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
@@ -86,7 +86,7 @@ distcheck-hook:
cmp -s $(srcdir)/gettext-runtime/libasprintf/gnulib-m4/intmax_t.m4 $(srcdir)/gettext-tools/gnulib-m4/intmax_t.m4
test "`sed 1,16d $(srcdir)/gettext-runtime/intl/arg-nonnull.h | md5sum`" = "`sed 1,16d $(srcdir)/gettext-tools/gnulib-lib/arg-nonnull.h | md5sum`"
test "`sed 1,16d $(srcdir)/gettext-runtime/intl/attribute.h | md5sum`" = "`sed 1,16d $(srcdir)/gettext-tools/gnulib-lib/attribute.h | md5sum`"
- test "`sed 1,15d $(srcdir)/gettext-runtime/intl/filename.h | md5sum`" = "`sed 1,15d $(srcdir)/gettext-tools/gnulib-lib/filename.h | md5sum`"
+ test "`sed 1,15d $(srcdir)/gettext-runtime/intl/filename.h | md5sum`" = "`sed 1,17d $(srcdir)/gettext-tools/gnulib-lib/filename.h | md5sum`"
test "`sed 1,16d $(srcdir)/gettext-runtime/intl/flexmember.h | md5sum`" = "`sed 1,19d $(srcdir)/gettext-tools/gnulib-lib/flexmember.h | md5sum`"
test "`sed 1,16d $(srcdir)/gettext-runtime/intl/localcharset.h | md5sum`" = "`sed 1,16d $(srcdir)/gettext-tools/gnulib-lib/localcharset.h | md5sum`"
test "`sed 1,16d $(srcdir)/gettext-runtime/intl/localcharset.c | md5sum`" = "`sed 1,16d $(srcdir)/gettext-tools/gnulib-lib/localcharset.c | md5sum`"
diff --git a/gettext-runtime/intl/arg-nonnull.h b/gettext-runtime/intl/arg-nonnull.h
index fbf3355c5..0fa737ffb 100644
--- a/gettext-runtime/intl/arg-nonnull.h
+++ b/gettext-runtime/intl/arg-nonnull.h
@@ -1,5 +1,5 @@
/* A C macro for declaring that specific arguments must not be NULL.
- Copyright (C) 2009-2019 Free Software Foundation, Inc.
+ Copyright (C) 2009-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -18,7 +18,7 @@
that the values passed as arguments n, ..., m must be non-NULL pointers.
n = 1 stands for the first argument, n = 2 for the second argument etc. */
#ifndef _GL_ARG_NONNULL
-# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
+# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || defined __clang__
# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
# else
# define _GL_ARG_NONNULL(params)
diff --git a/gettext-runtime/intl/localename.c b/gettext-runtime/intl/localename.c
index 6458f7574..d77bb8178 100644
--- a/gettext-runtime/intl/localename.c
+++ b/gettext-runtime/intl/localename.c
@@ -1,5 +1,5 @@
/* Determine name of the currently selected locale.
- Copyright (C) 1995-2019 Free Software Foundation, Inc.
+ Copyright (C) 1995-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -28,6 +28,7 @@
#endif
#include <limits.h>
+#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <locale.h>
@@ -35,12 +36,7 @@
#include "flexmember.h"
#include "setlocale_null.h"
-
-/* We cannot support uselocale() on platforms where the locale_t type is fake.
- See intl-thread-locale.m4 for details. */
-#if HAVE_WORKING_USELOCALE && !HAVE_FAKE_LOCALES
-# define HAVE_GOOD_USELOCALE 1
-#endif
+#include "thread-optim.h"
#if HAVE_GOOD_USELOCALE
/* Mac OS X 10.5 defines the locale_t type in <xlocale.h>. */
@@ -62,7 +58,6 @@ extern char * getlocalename_l(int, locale_t);
# endif
# endif
# if HAVE_NAMELESS_LOCALES
-# include <errno.h>
# include "localename-table.h"
# endif
#endif
@@ -2697,31 +2692,34 @@ struniq (const char *string)
/* Out of memory. Return a statically allocated string. */
return "C";
memcpy (new_node->contents, string, size);
- /* Lock while inserting new_node. */
- gl_lock_lock (struniq_lock);
- /* Check whether another thread already added the string while we were
- waiting on the lock. */
- for (p = struniq_hash_table[slot]; p != NULL; p = p->next)
- if (strcmp (p->contents, string) == 0)
- {
- free (new_node);
- new_node = p;
- goto done;
- }
- /* Really insert new_node into the hash table. Fill new_node entirely first,
- because other threads may be iterating over the linked list. */
- new_node->next = struniq_hash_table[slot];
- struniq_hash_table[slot] = new_node;
- done:
- /* Unlock after new_node is inserted. */
- gl_lock_unlock (struniq_lock);
+ {
+ bool mt = gl_multithreaded ();
+ /* Lock while inserting new_node. */
+ if (mt) gl_lock_lock (struniq_lock);
+ /* Check whether another thread already added the string while we were
+ waiting on the lock. */
+ for (p = struniq_hash_table[slot]; p != NULL; p = p->next)
+ if (strcmp (p->contents, string) == 0)
+ {
+ free (new_node);
+ new_node = p;
+ goto done;
+ }
+ /* Really insert new_node into the hash table. Fill new_node entirely
+ first, because other threads may be iterating over the linked list. */
+ new_node->next = struniq_hash_table[slot];
+ struniq_hash_table[slot] = new_node;
+ done:
+ /* Unlock after new_node is inserted. */
+ if (mt) gl_lock_unlock (struniq_lock);
+ }
return new_node->contents;
}
#endif
-#if HAVE_GOOD_USELOCALE && HAVE_NAMELESS_LOCALES
+#if LOCALENAME_ENHANCE_LOCALE_FUNCS
/* The 'locale_t' object does not contain the names of the locale categories.
We have to associate them with the object through a hash table.
@@ -2931,9 +2929,7 @@ newlocale (int category_mask, const char *name, locale_t base)
result = newlocale (category_mask, name, base);
if (result == NULL)
{
- int saved_errno = errno;
free (node);
- errno = saved_errno;
return NULL;
}
@@ -2992,9 +2988,7 @@ duplocale (locale_t locale)
result = duplocale (locale);
if (result == NULL)
{
- int saved_errno = errno;
free (node);
- errno = saved_errno;
return NULL;
}
@@ -3109,7 +3103,7 @@ freelocale (locale_t locale)
static
# endif
const char *
-gl_locale_name_thread_unsafe (int category, const char *categoryname)
+gl_locale_name_thread_unsafe (int category, _GL_UNUSED const char *categoryname)
{
# if HAVE_GOOD_USELOCALE
{
@@ -3224,7 +3218,7 @@ gl_locale_name_thread_unsafe (int category, const char *categoryname)
#endif
const char *
-gl_locale_name_thread (int category, const char *categoryname)
+gl_locale_name_thread (int category, _GL_UNUSED const char *categoryname)
{
#if HAVE_GOOD_USELOCALE
const char *name = gl_locale_name_thread_unsafe (category, categoryname);
@@ -3248,7 +3242,7 @@ gl_locale_name_thread (int category, const char *categoryname)
#endif
const char *
-gl_locale_name_posix (int category, const char *categoryname)
+gl_locale_name_posix (int category, _GL_UNUSED const char *categoryname)
{
#if defined WINDOWS_NATIVE
if (LC_MIN <= category && category <= LC_MAX)
@@ -3313,7 +3307,7 @@ gl_locale_name_posix (int category, const char *categoryname)
}
const char *
-gl_locale_name_environ (int category, const char *categoryname)
+gl_locale_name_environ (_GL_UNUSED int category, const char *categoryname)
{
const char *retval;
diff --git a/gettext-runtime/intl/lock.h b/gettext-runtime/intl/lock.h
index d65f2c033..86dcd0161 100644
--- a/gettext-runtime/intl/lock.h
+++ b/gettext-runtime/intl/lock.h
@@ -1,5 +1,5 @@
/* Locking in multithreaded situations.
- Copyright (C) 2005-2008, 2017-2020 Free Software Foundation, Inc.
+ Copyright (C) 2005-2008, 2017-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -81,7 +81,9 @@
#include <stdlib.h>
#if !defined c11_threads_in_use
-# if HAVE_THREADS_H && USE_POSIX_THREADS_WEAK
+# if HAVE_THREADS_H && USE_POSIX_THREADS_FROM_LIBC
+# define c11_threads_in_use() 1
+# elif HAVE_THREADS_H && USE_POSIX_THREADS_WEAK
# include <threads.h>
# pragma weak thrd_exit
# define c11_threads_in_use() (thrd_exit != NULL)
diff --git a/gettext-runtime/intl/relocatable.c b/gettext-runtime/intl/relocatable.c
index 9461458df..ef41214b6 100644
--- a/gettext-runtime/intl/relocatable.c
+++ b/gettext-runtime/intl/relocatable.c
@@ -1,5 +1,5 @@
/* Provide relocatable packages.
- Copyright (C) 2003-2006, 2008-2020 Free Software Foundation, Inc.
+ Copyright (C) 2003-2006, 2008-2022 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
This program is free software: you can redistribute it and/or modify
@@ -323,7 +323,10 @@ static char *shared_library_fullname;
supports longer file names
(see <https://cygwin.com/ml/cygwin/2011-01/msg00410.html>). */
-/* Determine the full pathname of the shared library when it is loaded. */
+/* Determine the full pathname of the shared library when it is loaded.
+
+ Documentation:
+ <https://docs.microsoft.com/en-us/windows/win32/dlls/dllmain> */
BOOL WINAPI
DllMain (HINSTANCE module_handle, DWORD event, LPVOID reserved)
@@ -343,7 +346,13 @@ DllMain (HINSTANCE module_handle, DWORD event, LPVOID reserved)
/* Shouldn't happen. */
return FALSE;
- shared_library_fullname = strdup (location);
+ /* Avoid a memory leak when the same DLL get attached, detached,
+ attached, detached, and so on. This happens e.g. when a spell
+ checker DLL is used repeatedly by a mail program. */
+ if (!(shared_library_fullname != NULL
+ && strcmp (shared_library_fullname, location) == 0))
+ /* Remember the full pathname of the shared library. */
+ shared_library_fullname = strdup (location);
}
return TRUE;
diff --git a/gettext-runtime/intl/relocatable.h b/gettext-runtime/intl/relocatable.h
index 4253b667c..368e733ee 100644
--- a/gettext-runtime/intl/relocatable.h
+++ b/gettext-runtime/intl/relocatable.h
@@ -1,5 +1,5 @@
/* Provide relocatable packages.
- Copyright (C) 2003, 2005, 2008-2017 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2005, 2008-2022 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
This program is free software: you can redistribute it and/or modify
@@ -18,6 +18,8 @@
#ifndef _RELOCATABLE_H
#define _RELOCATABLE_H
+#include <stdlib.h>
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -83,7 +85,8 @@ extern const char * relocate2 (const char *pathname, char **allocatedp);
Returns it, freshly allocated. Returns NULL upon failure. */
extern char * compute_curr_prefix (const char *orig_installprefix,
const char *orig_installdir,
- const char *curr_pathname);
+ const char *curr_pathname)
+ _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
#else
diff --git a/gettext-runtime/intl/threadlib.c b/gettext-runtime/intl/threadlib.c
index 649810b7e..9840ab49a 100644
--- a/gettext-runtime/intl/threadlib.c
+++ b/gettext-runtime/intl/threadlib.c
@@ -1,5 +1,5 @@
/* Multithreading primitives.
- Copyright (C) 2005-2009 Free Software Foundation, Inc.
+ Copyright (C) 2005-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -24,11 +24,44 @@
/* Use the POSIX threads library. */
+# include <errno.h>
# include <pthread.h>
# include <stdlib.h>
# if PTHREAD_IN_USE_DETECTION_HARD
+# if defined __FreeBSD__ || defined __DragonFly__ /* FreeBSD */
+
+/* Test using pthread_key_create. */
+
+int
+glthread_in_use (void)
+{
+ static int tested;
+ static int result; /* 1: linked with -lpthread, 0: only with libc */
+
+ if (!tested)
+ {
+ pthread_key_t key;
+ int err = pthread_key_create (&key, NULL);
+
+ if (err == ENOSYS)
+ result = 0;
+ else
+ {
+ result = 1;
+ if (err == 0)
+ pthread_key_delete (key);
+ }
+ tested = 1;
+ }
+ return result;
+}
+
+# else /* Solaris, HP-UX */
+
+/* Test using pthread_create. */
+
/* The function to be executed by a dummy thread. */
static void *
dummy_thread_func (void *arg)
@@ -62,6 +95,8 @@ glthread_in_use (void)
return result;
}
+# endif
+
# endif
#endif
diff --git a/gettext-runtime/intl/vasnprintf.c b/gettext-runtime/intl/vasnprintf.c
index 0ef77893c..699274444 100644
--- a/gettext-runtime/intl/vasnprintf.c
+++ b/gettext-runtime/intl/vasnprintf.c
@@ -1,5 +1,5 @@
/* vsprintf with automatic memory allocation.
- Copyright (C) 1999, 2002-2020 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -60,6 +60,14 @@
#ifndef VASNPRINTF
# include <config.h>
#endif
+
+/* As of GCC 11.2.1, gcc -Wanalyzer-too-complex reports that main's
+ use of CHECK macros expands to code that is too complicated for gcc
+ -fanalyzer. Suppress the resulting bogus warnings. */
+#if 10 <= __GNUC__
+# pragma GCC diagnostic ignored "-Wanalyzer-null-argument"
+#endif
+
#ifndef IN_LIBINTL
# include <alloca.h>
#endif
@@ -633,7 +641,8 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */
/* Determine s = GMP_LIMB_BITS - integer_length (msd).
Code copied from gnulib's integer_length.c. */
-# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) \
+ || (__clang_major__ >= 4)
s = __builtin_clz (msd);
# else
# if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
@@ -1858,6 +1867,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
/* errno is already set. */
return NULL;
+ /* Frees the memory allocated by this function. Preserves errno. */
#define CLEANUP() \
if (d.dir != d.direct_alloc_dir) \
free (d.dir); \
@@ -1922,7 +1932,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
/* Ensures that allocated >= needed. Aborts through a jump to
out_of_memory if needed is SIZE_MAX or otherwise too big. */
-#define ENSURE_ALLOCATION(needed) \
+#define ENSURE_ALLOCATION_ELSE(needed, oom_statement) \
if ((needed) > allocated) \
{ \
size_t memory_size; \
@@ -1933,17 +1943,19 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
allocated = (needed); \
memory_size = xtimes (allocated, sizeof (DCHAR_T)); \
if (size_overflow_p (memory_size)) \
- goto out_of_memory; \
+ oom_statement \
if (result == resultbuf || result == NULL) \
memory = (DCHAR_T *) malloc (memory_size); \
else \
memory = (DCHAR_T *) realloc (result, memory_size); \
if (memory == NULL) \
- goto out_of_memory; \
+ oom_statement \
if (result == resultbuf && length > 0) \
DCHAR_CPY (memory, result, length); \
result = memory; \
}
+#define ENSURE_ALLOCATION(needed) \
+ ENSURE_ALLOCATION_ELSE((needed), goto out_of_memory; )
for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++)
{
@@ -2182,18 +2194,17 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
# endif
if (converted == NULL)
{
- int saved_errno = errno;
if (!(result == resultbuf || result == NULL))
free (result);
if (buf_malloced != NULL)
free (buf_malloced);
CLEANUP ();
- errno = saved_errno;
return NULL;
}
if (converted != result + length)
{
- ENSURE_ALLOCATION (xsum (length, converted_len));
+ ENSURE_ALLOCATION_ELSE (xsum (length, converted_len),
+ { free (converted); goto out_of_memory; });
DCHAR_CPY (result + length, converted, converted_len);
free (converted);
}
@@ -2308,18 +2319,17 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
# endif
if (converted == NULL)
{
- int saved_errno = errno;
if (!(result == resultbuf || result == NULL))
free (result);
if (buf_malloced != NULL)
free (buf_malloced);
CLEANUP ();
- errno = saved_errno;
return NULL;
}
if (converted != result + length)
{
- ENSURE_ALLOCATION (xsum (length, converted_len));
+ ENSURE_ALLOCATION_ELSE (xsum (length, converted_len),
+ { free (converted); goto out_of_memory; });
DCHAR_CPY (result + length, converted, converted_len);
free (converted);
}
@@ -2434,18 +2444,17 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
# endif
if (converted == NULL)
{
- int saved_errno = errno;
if (!(result == resultbuf || result == NULL))
free (result);
if (buf_malloced != NULL)
free (buf_malloced);
CLEANUP ();
- errno = saved_errno;
return NULL;
}
if (converted != result + length)
{
- ENSURE_ALLOCATION (xsum (length, converted_len));
+ ENSURE_ALLOCATION_ELSE (xsum (length, converted_len),
+ { free (converted); goto out_of_memory; });
DCHAR_CPY (result + length, converted, converted_len);
free (converted);
}
@@ -2851,14 +2860,12 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
NULL, &tmpdst_len);
if (tmpdst == NULL)
{
- int saved_errno = errno;
free (tmpsrc);
if (!(result == resultbuf || result == NULL))
free (result);
if (buf_malloced != NULL)
free (buf_malloced);
CLEANUP ();
- errno = saved_errno;
return NULL;
}
free (tmpsrc);
@@ -2950,7 +2957,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
}
}
# else
- ENSURE_ALLOCATION (xsum (length, tmpdst_len));
+ ENSURE_ALLOCATION_ELSE (xsum (length, tmpdst_len),
+ { free (tmpdst); goto out_of_memory; });
DCHAR_CPY (result + length, tmpdst, tmpdst_len);
free (tmpdst);
length += tmpdst_len;
@@ -3078,13 +3086,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
NULL, &tmpdst_len);
if (tmpdst == NULL)
{
- int saved_errno = errno;
if (!(result == resultbuf || result == NULL))
free (result);
if (buf_malloced != NULL)
free (buf_malloced);
CLEANUP ();
- errno = saved_errno;
return NULL;
}
# endif
@@ -3155,7 +3161,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
}
}
# else
- ENSURE_ALLOCATION (xsum (length, tmpdst_len));
+ ENSURE_ALLOCATION_ELSE (xsum (length, tmpdst_len),
+ { free (tmpdst); goto out_of_memory; });
DCHAR_CPY (result + length, tmpdst, tmpdst_len);
free (tmpdst);
length += tmpdst_len;
@@ -5116,39 +5123,32 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
#endif
*fbp = dp->conversion;
#if USE_SNPRINTF
-# if ! (((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) \
- && !defined __UCLIBC__) \
- || (defined __APPLE__ && defined __MACH__) \
- || defined __ANDROID__ \
- || (defined _WIN32 && ! defined __CYGWIN__))
- fbp[1] = '%';
- fbp[2] = 'n';
- fbp[3] = '\0';
-# else
- /* On glibc2 systems from glibc >= 2.3 - probably also older
- ones - we know that snprintf's return value conforms to
- ISO C 99: the tests gl_SNPRINTF_RETVAL_C99 and
- gl_SNPRINTF_TRUNCATION_C99 pass.
- Therefore we can avoid using %n in this situation.
- On glibc2 systems from 2004-10-18 or newer, the use of %n
- in format strings in writable memory may crash the program
- (if compiled with _FORTIFY_SOURCE=2), so we should avoid it
- in this situation. */
- /* On Mac OS X 10.3 or newer, we know that snprintf's return
- value conforms to ISO C 99: the tests gl_SNPRINTF_RETVAL_C99
- and gl_SNPRINTF_TRUNCATION_C99 pass.
- Therefore we can avoid using %n in this situation.
- On Mac OS X 10.13 or newer, the use of %n in format strings
- in writable memory by default crashes the program, so we
- should avoid it in this situation. */
- /* On Android, we know that snprintf's return value conforms to
- ISO C 99: the tests gl_SNPRINTF_RETVAL_C99 and
- gl_SNPRINTF_TRUNCATION_C99 pass.
- Therefore we can avoid using %n in this situation.
- Starting on 2018-03-07, the use of %n in format strings
- produces a fatal error (see
- <https://android.googlesource.com/platform/bionic/+/41398d03b7e8e0dfb951660ae713e682e9fc0336>),
- so we should avoid it. */
+# if ((HAVE_SNPRINTF_RETVAL_C99 && HAVE_SNPRINTF_TRUNCATION_C99) \
+ || ((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) \
+ && !defined __UCLIBC__) \
+ || (defined __APPLE__ && defined __MACH__) \
+ || defined __ANDROID__ \
+ || (defined _WIN32 && ! defined __CYGWIN__))
+ /* On systems where we know that snprintf's return value
+ conforms to ISO C 99 (HAVE_SNPRINTF_RETVAL_C99) and that
+ snprintf always produces NUL-terminated strings
+ (HAVE_SNPRINTF_TRUNCATION_C99), it is possible to avoid
+ using %n. And it is desirable to do so, because more and
+ more platforms no longer support %n, for "security reasons".
+ In particular, the following platforms:
+ - On glibc2 systems from 2004-10-18 or newer, the use of
+ %n in format strings in writable memory may crash the
+ program (if compiled with _FORTIFY_SOURCE=2).
+ - On Mac OS X 10.13 or newer, the use of %n in format
+ strings in writable memory by default crashes the
+ program.
+ - On Android, starting on 2018-03-07, the use of %n in
+ format strings produces a fatal error (see
+ <https://android.googlesource.com/platform/bionic/+/41398d03b7e8e0dfb951660ae713e682e9fc0336>).
+ On these platforms, HAVE_SNPRINTF_RETVAL_C99 and
+ HAVE_SNPRINTF_TRUNCATION_C99 are 1. We have listed them
+ explicitly in the condition above, in case of cross-
+ compilation (just to be sure). */
/* On native Windows systems (such as mingw), we can avoid using
%n because:
- Although the gl_SNPRINTF_TRUNCATION_C99 test fails,
@@ -5165,6 +5165,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
<https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/set-printf-count-output>
So we should avoid %n in this situation. */
fbp[1] = '\0';
+# else /* AIX <= 5.1, HP-UX, IRIX, OSF/1, Solaris <= 9, BeOS */
+ fbp[1] = '%';
+ fbp[2] = 'n';
+ fbp[3] = '\0';
# endif
#else
fbp[1] = '\0';
@@ -5451,15 +5455,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
/* Attempt to handle failure. */
if (count < 0)
{
- /* SNPRINTF or sprintf failed. Save and use the errno
- that it has set, if any. */
- int saved_errno = errno;
- if (saved_errno == 0)
+ /* SNPRINTF or sprintf failed. Use the errno that it
+ has set, if any. */
+ if (errno == 0)
{
if (dp->conversion == 'c' || dp->conversion == 's')
- saved_errno = EILSEQ;
+ errno = EILSEQ;
else
- saved_errno = EINVAL;
+ errno = EINVAL;
}
if (!(result == resultbuf || result == NULL))
@@ -5468,7 +5471,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
free (buf_malloced);
CLEANUP ();
- errno = saved_errno;
return NULL;
}
@@ -5604,16 +5606,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
NULL, &tmpdst_len);
if (tmpdst == NULL)
{
- int saved_errno = errno;
if (!(result == resultbuf || result == NULL))
free (result);
if (buf_malloced != NULL)
free (buf_malloced);
CLEANUP ();
- errno = saved_errno;
return NULL;
}
- ENSURE_ALLOCATION (xsum (length, tmpdst_len));
+ ENSURE_ALLOCATION_ELSE (xsum (length, tmpdst_len),
+ { free (tmpdst); goto out_of_memory; });
DCHAR_CPY (result + length, tmpdst, tmpdst_len);
free (tmpdst);
count = tmpdst_len;
diff --git a/gettext-runtime/intl/verify.h b/gettext-runtime/intl/verify.h
index 11dc4bf7a..42307c0be 100644
--- a/gettext-runtime/intl/verify.h
+++ b/gettext-runtime/intl/verify.h
@@ -1,13 +1,13 @@
/* Compile-time assert-like macros.
- Copyright (C) 2005-2006, 2009-2020 Free Software Foundation, Inc.
+ Copyright (C) 2005-2006, 2009-2022 Free Software Foundation, Inc.
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
+ This file is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
+ This file 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 Lesser General Public License for more details.
@@ -22,12 +22,10 @@
/* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert (R, DIAGNOSTIC)
- works as per C11. This is supported by GCC 4.6.0 and later, in C
- mode.
+ works as per C11. This is supported by GCC 4.6.0+ and by clang 4+.
Define _GL_HAVE__STATIC_ASSERT1 to 1 if _Static_assert (R) works as
- per C2X, and define _GL_HAVE_STATIC_ASSERT1 if static_assert (R)
- works as per C++17. This is supported by GCC 9.1 and later.
+ per C2x. This is supported by GCC 9.1+.
Support compilers claiming conformance to the relevant standard,
and also support GCC when not pedantic. If we were willing to slow
@@ -35,17 +33,14 @@
since this affects only the quality of diagnostics, why bother? */
#ifndef __cplusplus
# if (201112L <= __STDC_VERSION__ \
- || (!defined __STRICT_ANSI__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__)))
+ || (!defined __STRICT_ANSI__ \
+ && (4 < __GNUC__ + (6 <= __GNUC_MINOR__) || 5 <= __clang_major__)))
# define _GL_HAVE__STATIC_ASSERT 1
# endif
# if (202000L <= __STDC_VERSION__ \
|| (!defined __STRICT_ANSI__ && 9 <= __GNUC__))
# define _GL_HAVE__STATIC_ASSERT1 1
# endif
-#else
-# if 201703L <= __cplusplus || 9 <= __GNUC__
-# define _GL_HAVE_STATIC_ASSERT1 1
-# endif
#endif
/* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other
@@ -207,12 +202,14 @@ template <int w>
This macro requires three or more arguments but uses at most the first
two, so that the _Static_assert macro optionally defined below supports
- both the C11 two-argument syntax and the C2X one-argument syntax.
+ both the C11 two-argument syntax and the C2x one-argument syntax.
Unfortunately, unlike C11, this implementation must appear as an
ordinary declaration, and cannot appear inside struct { ... }. */
-#if defined _GL_HAVE__STATIC_ASSERT
+#if 200410 <= __cpp_static_assert
+# define _GL_VERIFY(R, DIAGNOSTIC, ...) static_assert (R, DIAGNOSTIC)
+#elif defined _GL_HAVE__STATIC_ASSERT
# define _GL_VERIFY(R, DIAGNOSTIC, ...) _Static_assert (R, DIAGNOSTIC)
#else
# define _GL_VERIFY(R, DIAGNOSTIC, ...) \
@@ -223,11 +220,29 @@ template <int w>
/* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */
#ifdef _GL_STATIC_ASSERT_H
# if !defined _GL_HAVE__STATIC_ASSERT1 && !defined _Static_assert
-# define _Static_assert(...) \
- _GL_VERIFY (__VA_ARGS__, "static assertion failed", -)
+# define _Static_assert(R, ...) \
+ _GL_VERIFY ((R), "static assertion failed", -)
# endif
-# if !defined _GL_HAVE_STATIC_ASSERT1 && !defined static_assert
-# define static_assert _Static_assert /* C11 requires this #define. */
+# if (!defined static_assert \
+ && (!defined __cplusplus \
+ || (__cpp_static_assert < 201411 \
+ && __GNUG__ < 6 && __clang_major__ < 6)))
+# if defined __cplusplus && _MSC_VER >= 1900 && !defined __clang__
+/* MSVC 14 in C++ mode supports the two-arguments static_assert but not
+ the one-argument static_assert, and it does not support _Static_assert.
+ We have to play preprocessor tricks to distinguish the two cases.
+ Since the MSVC preprocessor is not ISO C compliant (cf.
+ <https://stackoverflow.com/questions/5134523/>), the solution is specific
+ to MSVC. */
+# define _GL_EXPAND(x) x
+# define _GL_SA1(a1) static_assert ((a1), "static assertion failed")
+# define _GL_SA2 static_assert
+# define _GL_SA3 static_assert
+# define _GL_SA_PICK(x1,x2,x3,x4,...) x4
+# define static_assert(...) _GL_EXPAND(_GL_SA_PICK(__VA_ARGS__,_GL_SA3,_GL_SA2,_GL_SA1)) (__VA_ARGS__)
+# else
+# define static_assert _Static_assert /* C11 requires this #define. */
+# endif
# endif
#endif
@@ -292,19 +307,27 @@ template <int w>
Although assuming R can help a compiler generate better code or
diagnostics, performance can suffer if R uses hard-to-optimize
- features such as function calls not inlined by the compiler. */
+ features such as function calls not inlined by the compiler.
+
+ Avoid Clang's __builtin_assume, as it breaks GNU Emacs master
+ as of 2020-08-23T21:09:49Z!eggert@cs.ucla.edu; see
+ <https://bugs.gnu.org/43152#71>. It's not known whether this breakage
+ is a Clang bug or an Emacs bug; play it safe for now. */
#if _GL_HAS_BUILTIN_UNREACHABLE
# define assume(R) ((R) ? (void) 0 : __builtin_unreachable ())
#elif 1200 <= _MSC_VER
# define assume(R) __assume (R)
+#elif 202311L <= __STDC_VERSION__
+# include <stddef.h>
+# define assume(R) ((R) ? (void) 0 : unreachable ())
#elif (defined GCC_LINT || defined lint) && _GL_HAS_BUILTIN_TRAP
/* Doing it this way helps various packages when configured with
--enable-gcc-warnings, which compiles with -Dlint. It's nicer
- when 'assume' silences warnings even with older GCCs. */
+ if 'assume' silences warnings with GCC 3.4 through GCC 4.4.7 (2012). */
# define assume(R) ((R) ? (void) 0 : __builtin_trap ())
#else
- /* Some tools grok NOTREACHED, e.g., Oracle Studio 12.6. */
+ /* Some older tools grok NOTREACHED, e.g., Oracle Studio 12.6 (2017). */
# define assume(R) ((R) ? (void) 0 : /*NOTREACHED*/ (void) 0)
#endif
diff --git a/gettext-runtime/intl/xsize.h b/gettext-runtime/intl/xsize.h
index 9b9840f78..0bfa4c889 100644
--- a/gettext-runtime/intl/xsize.h
+++ b/gettext-runtime/intl/xsize.h
@@ -1,19 +1,19 @@
/* xsize.h -- Checked size_t computations.
- Copyright (C) 2003, 2008-2020 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2008-2022 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1, or (at your option)
- any later version.
+ This file is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
+ This file 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
- along with this program; if not, see <https://www.gnu.org/licenses/>. */
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
#ifndef _XSIZE_H
#define _XSIZE_H
diff --git a/gettext-runtime/libasprintf/vasnprintf.c b/gettext-runtime/libasprintf/vasnprintf.c
index 0ef77893c..699274444 100644
--- a/gettext-runtime/libasprintf/vasnprintf.c
+++ b/gettext-runtime/libasprintf/vasnprintf.c
@@ -1,5 +1,5 @@
/* vsprintf with automatic memory allocation.
- Copyright (C) 1999, 2002-2020 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -60,6 +60,14 @@
#ifndef VASNPRINTF
# include <config.h>
#endif
+
+/* As of GCC 11.2.1, gcc -Wanalyzer-too-complex reports that main's
+ use of CHECK macros expands to code that is too complicated for gcc
+ -fanalyzer. Suppress the resulting bogus warnings. */
+#if 10 <= __GNUC__
+# pragma GCC diagnostic ignored "-Wanalyzer-null-argument"
+#endif
+
#ifndef IN_LIBINTL
# include <alloca.h>
#endif
@@ -633,7 +641,8 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */
/* Determine s = GMP_LIMB_BITS - integer_length (msd).
Code copied from gnulib's integer_length.c. */
-# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) \
+ || (__clang_major__ >= 4)
s = __builtin_clz (msd);
# else
# if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
@@ -1858,6 +1867,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
/* errno is already set. */
return NULL;
+ /* Frees the memory allocated by this function. Preserves errno. */
#define CLEANUP() \
if (d.dir != d.direct_alloc_dir) \
free (d.dir); \
@@ -1922,7 +1932,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
/* Ensures that allocated >= needed. Aborts through a jump to
out_of_memory if needed is SIZE_MAX or otherwise too big. */
-#define ENSURE_ALLOCATION(needed) \
+#define ENSURE_ALLOCATION_ELSE(needed, oom_statement) \
if ((needed) > allocated) \
{ \
size_t memory_size; \
@@ -1933,17 +1943,19 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
allocated = (needed); \
memory_size = xtimes (allocated, sizeof (DCHAR_T)); \
if (size_overflow_p (memory_size)) \
- goto out_of_memory; \
+ oom_statement \
if (result == resultbuf || result == NULL) \
memory = (DCHAR_T *) malloc (memory_size); \
else \
memory = (DCHAR_T *) realloc (result, memory_size); \
if (memory == NULL) \
- goto out_of_memory; \
+ oom_statement \
if (result == resultbuf && length > 0) \
DCHAR_CPY (memory, result, length); \
result = memory; \
}
+#define ENSURE_ALLOCATION(needed) \
+ ENSURE_ALLOCATION_ELSE((needed), goto out_of_memory; )
for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++)
{
@@ -2182,18 +2194,17 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
# endif
if (converted == NULL)
{
- int saved_errno = errno;
if (!(result == resultbuf || result == NULL))
free (result);
if (buf_malloced != NULL)
free (buf_malloced);
CLEANUP ();
- errno = saved_errno;
return NULL;
}
if (converted != result + length)
{
- ENSURE_ALLOCATION (xsum (length, converted_len));
+ ENSURE_ALLOCATION_ELSE (xsum (length, converted_len),
+ { free (converted); goto out_of_memory; });
DCHAR_CPY (result + length, converted, converted_len);
free (converted);
}
@@ -2308,18 +2319,17 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
# endif
if (converted == NULL)
{
- int saved_errno = errno;
if (!(result == resultbuf || result == NULL))
free (result);
if (buf_malloced != NULL)
free (buf_malloced);
CLEANUP ();
- errno = saved_errno;
return NULL;
}
if (converted != result + length)
{
- ENSURE_ALLOCATION (xsum (length, converted_len));
+ ENSURE_ALLOCATION_ELSE (xsum (length, converted_len),
+ { free (converted); goto out_of_memory; });
DCHAR_CPY (result + length, converted, converted_len);
free (converted);
}
@@ -2434,18 +2444,17 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
# endif
if (converted == NULL)
{
- int saved_errno = errno;
if (!(result == resultbuf || result == NULL))
free (result);
if (buf_malloced != NULL)
free (buf_malloced);
CLEANUP ();
- errno = saved_errno;
return NULL;
}
if (converted != result + length)
{
- ENSURE_ALLOCATION (xsum (length, converted_len));
+ ENSURE_ALLOCATION_ELSE (xsum (length, converted_len),
+ { free (converted); goto out_of_memory; });
DCHAR_CPY (result + length, converted, converted_len);
free (converted);
}
@@ -2851,14 +2860,12 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
NULL, &tmpdst_len);
if (tmpdst == NULL)
{
- int saved_errno = errno;
free (tmpsrc);
if (!(result == resultbuf || result == NULL))
free (result);
if (buf_malloced != NULL)
free (buf_malloced);
CLEANUP ();
- errno = saved_errno;
return NULL;
}
free (tmpsrc);
@@ -2950,7 +2957,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
}
}
# else
- ENSURE_ALLOCATION (xsum (length, tmpdst_len));
+ ENSURE_ALLOCATION_ELSE (xsum (length, tmpdst_len),
+ { free (tmpdst); goto out_of_memory; });
DCHAR_CPY (result + length, tmpdst, tmpdst_len);
free (tmpdst);
length += tmpdst_len;
@@ -3078,13 +3086,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
NULL, &tmpdst_len);
if (tmpdst == NULL)
{
- int saved_errno = errno;
if (!(result == resultbuf || result == NULL))
free (result);
if (buf_malloced != NULL)
free (buf_malloced);
CLEANUP ();
- errno = saved_errno;
return NULL;
}
# endif
@@ -3155,7 +3161,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
}
}
# else
- ENSURE_ALLOCATION (xsum (length, tmpdst_len));
+ ENSURE_ALLOCATION_ELSE (xsum (length, tmpdst_len),
+ { free (tmpdst); goto out_of_memory; });
DCHAR_CPY (result + length, tmpdst, tmpdst_len);
free (tmpdst);
length += tmpdst_len;
@@ -5116,39 +5123,32 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
#endif
*fbp = dp->conversion;
#if USE_SNPRINTF
-# if ! (((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) \
- && !defined __UCLIBC__) \
- || (defined __APPLE__ && defined __MACH__) \
- || defined __ANDROID__ \
- || (defined _WIN32 && ! defined __CYGWIN__))
- fbp[1] = '%';
- fbp[2] = 'n';
- fbp[3] = '\0';
-# else
- /* On glibc2 systems from glibc >= 2.3 - probably also older
- ones - we know that snprintf's return value conforms to
- ISO C 99: the tests gl_SNPRINTF_RETVAL_C99 and
- gl_SNPRINTF_TRUNCATION_C99 pass.
- Therefore we can avoid using %n in this situation.
- On glibc2 systems from 2004-10-18 or newer, the use of %n
- in format strings in writable memory may crash the program
- (if compiled with _FORTIFY_SOURCE=2), so we should avoid it
- in this situation. */
- /* On Mac OS X 10.3 or newer, we know that snprintf's return
- value conforms to ISO C 99: the tests gl_SNPRINTF_RETVAL_C99
- and gl_SNPRINTF_TRUNCATION_C99 pass.
- Therefore we can avoid using %n in this situation.
- On Mac OS X 10.13 or newer, the use of %n in format strings
- in writable memory by default crashes the program, so we
- should avoid it in this situation. */
- /* On Android, we know that snprintf's return value conforms to
- ISO C 99: the tests gl_SNPRINTF_RETVAL_C99 and
- gl_SNPRINTF_TRUNCATION_C99 pass.
- Therefore we can avoid using %n in this situation.
- Starting on 2018-03-07, the use of %n in format strings
- produces a fatal error (see
- <https://android.googlesource.com/platform/bionic/+/41398d03b7e8e0dfb951660ae713e682e9fc0336>),
- so we should avoid it. */
+# if ((HAVE_SNPRINTF_RETVAL_C99 && HAVE_SNPRINTF_TRUNCATION_C99) \
+ || ((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) \
+ && !defined __UCLIBC__) \
+ || (defined __APPLE__ && defined __MACH__) \
+ || defined __ANDROID__ \
+ || (defined _WIN32 && ! defined __CYGWIN__))
+ /* On systems where we know that snprintf's return value
+ conforms to ISO C 99 (HAVE_SNPRINTF_RETVAL_C99) and that
+ snprintf always produces NUL-terminated strings
+ (HAVE_SNPRINTF_TRUNCATION_C99), it is possible to avoid
+ using %n. And it is desirable to do so, because more and
+ more platforms no longer support %n, for "security reasons".
+ In particular, the following platforms:
+ - On glibc2 systems from 2004-10-18 or newer, the use of
+ %n in format strings in writable memory may crash the
+ program (if compiled with _FORTIFY_SOURCE=2).
+ - On Mac OS X 10.13 or newer, the use of %n in format
+ strings in writable memory by default crashes the
+ program.
+ - On Android, starting on 2018-03-07, the use of %n in
+ format strings produces a fatal error (see
+ <https://android.googlesource.com/platform/bionic/+/41398d03b7e8e0dfb951660ae713e682e9fc0336>).
+ On these platforms, HAVE_SNPRINTF_RETVAL_C99 and
+ HAVE_SNPRINTF_TRUNCATION_C99 are 1. We have listed them
+ explicitly in the condition above, in case of cross-
+ compilation (just to be sure). */
/* On native Windows systems (such as mingw), we can avoid using
%n because:
- Although the gl_SNPRINTF_TRUNCATION_C99 test fails,
@@ -5165,6 +5165,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
<https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/set-printf-count-output>
So we should avoid %n in this situation. */
fbp[1] = '\0';
+# else /* AIX <= 5.1, HP-UX, IRIX, OSF/1, Solaris <= 9, BeOS */
+ fbp[1] = '%';
+ fbp[2] = 'n';
+ fbp[3] = '\0';
# endif
#else
fbp[1] = '\0';
@@ -5451,15 +5455,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
/* Attempt to handle failure. */
if (count < 0)
{
- /* SNPRINTF or sprintf failed. Save and use the errno
- that it has set, if any. */
- int saved_errno = errno;
- if (saved_errno == 0)
+ /* SNPRINTF or sprintf failed. Use the errno that it
+ has set, if any. */
+ if (errno == 0)
{
if (dp->conversion == 'c' || dp->conversion == 's')
- saved_errno = EILSEQ;
+ errno = EILSEQ;
else
- saved_errno = EINVAL;
+ errno = EINVAL;
}
if (!(result == resultbuf || result == NULL))
@@ -5468,7 +5471,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
free (buf_malloced);
CLEANUP ();
- errno = saved_errno;
return NULL;
}
@@ -5604,16 +5606,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
NULL, &tmpdst_len);
if (tmpdst == NULL)
{
- int saved_errno = errno;
if (!(result == resultbuf || result == NULL))
free (result);
if (buf_malloced != NULL)
free (buf_malloced);
CLEANUP ();
- errno = saved_errno;
return NULL;
}
- ENSURE_ALLOCATION (xsum (length, tmpdst_len));
+ ENSURE_ALLOCATION_ELSE (xsum (length, tmpdst_len),
+ { free (tmpdst); goto out_of_memory; });
DCHAR_CPY (result + length, tmpdst, tmpdst_len);
free (tmpdst);
count = tmpdst_len;
diff --git a/gettext-runtime/m4/fcntl-o.m4 b/gettext-runtime/m4/fcntl-o.m4
index 747b86575..4dcde9e06 100644
--- a/gettext-runtime/m4/fcntl-o.m4
+++ b/gettext-runtime/m4/fcntl-o.m4
@@ -1,5 +1,5 @@
-# fcntl-o.m4 serial 6
-dnl Copyright (C) 2006, 2009-2020 Free Software Foundation, Inc.
+# fcntl-o.m4 serial 7
+dnl Copyright (C) 2006, 2009-2022 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
@@ -32,6 +32,7 @@ AC_DEFUN([gl_FCNTL_O_FLAGS],
# defined sleep(n) _sleep ((n) * 1000)
#endif
#include <fcntl.h>
+ ]GL_MDA_DEFINES[
#ifndef O_NOATIME
#define O_NOATIME 0
#endif
diff --git a/gettext-runtime/m4/flexmember.m4 b/gettext-runtime/m4/flexmember.m4
index 90f3dddc6..3b4237e9f 100644
--- a/gettext-runtime/m4/flexmember.m4
+++ b/gettext-runtime/m4/flexmember.m4
@@ -1,7 +1,7 @@
# serial 5
# Check for flexible array member support.
-# Copyright (C) 2006, 2009-2020 Free Software Foundation, Inc.
+# Copyright (C) 2006, 2009-2022 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
diff --git a/gettext-runtime/m4/iconv.m4 b/gettext-runtime/m4/iconv.m4
index e593b7270..00057953e 100644
--- a/gettext-runtime/m4/iconv.m4
+++ b/gettext-runtime/m4/iconv.m4
@@ -1,5 +1,5 @@
-# iconv.m4 serial 21
-dnl Copyright (C) 2000-2002, 2007-2014, 2016-2020 Free Software Foundation,
+# iconv.m4 serial 24
+dnl Copyright (C) 2000-2002, 2007-2014, 2016-2022 Free Software Foundation,
dnl Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -7,6 +7,12 @@ dnl with or without modifications, as long as this notice is preserved.
dnl From Bruno Haible.
+AC_PREREQ([2.64])
+
+dnl Note: AM_ICONV is documented in the GNU gettext manual
+dnl <https://www.gnu.org/software/gettext/manual/html_node/AM_005fICONV.html>.
+dnl Don't make changes that are incompatible with that documentation!
+
AC_DEFUN([AM_ICONV_LINKFLAGS_BODY],
[
dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
@@ -86,8 +92,9 @@ AC_DEFUN([AM_ICONV_LINK],
#endif
]],
[[int result = 0;
- /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
- returns. */
+ /* Test against AIX 5.1...7.2 bug: Failures are not distinguishable from
+ successful returns. This is even documented in
+ <https://www.ibm.com/support/knowledgecenter/ssw_aix_72/i_bostechref/iconv.html> */
{
iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
if (cd_utf8_to_88591 != (iconv_t)(-1))
@@ -225,8 +232,7 @@ AC_DEFUN([AM_ICONV_LINK],
AC_SUBST([LTLIBICONV])
])
-dnl Define AM_ICONV using AC_DEFUN_ONCE for Autoconf >= 2.64, in order to
-dnl avoid warnings like
+dnl Define AM_ICONV using AC_DEFUN_ONCE, in order to avoid warnings like
dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required".
dnl This is tricky because of the way 'aclocal' is implemented:
dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN.
@@ -234,54 +240,43 @@ dnl Otherwise aclocal's initial scan pass would miss the macro definition.
dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions.
dnl Otherwise aclocal would emit many "Use of uninitialized value $1"
dnl warnings.
-m4_define([gl_iconv_AC_DEFUN],
- m4_version_prereq([2.64],
- [[AC_DEFUN_ONCE(
- [$1], [$2])]],
- [m4_ifdef([gl_00GNULIB],
- [[AC_DEFUN_ONCE(
- [$1], [$2])]],
- [[AC_DEFUN(
- [$1], [$2])]])]))
-gl_iconv_AC_DEFUN([AM_ICONV],
+AC_DEFUN_ONCE([AM_ICONV],
[
AM_ICONV_LINK
if test "$am_cv_func_iconv" = yes; then
- AC_MSG_CHECKING([for iconv declaration])
- AC_CACHE_VAL([am_cv_proto_iconv], [
- AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM(
- [[
+ AC_CACHE_CHECK([whether iconv is compatible with its POSIX signature],
+ [gl_cv_iconv_nonconst],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[
#include <stdlib.h>
#include <iconv.h>
extern
#ifdef __cplusplus
"C"
#endif
-#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus)
size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
-#else
-size_t iconv();
-#endif
- ]],
- [[]])],
- [am_cv_proto_iconv_arg1=""],
- [am_cv_proto_iconv_arg1="const"])
- am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"])
- am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
- AC_MSG_RESULT([
- $am_cv_proto_iconv])
+ ]],
+ [[]])],
+ [gl_cv_iconv_nonconst=yes],
+ [gl_cv_iconv_nonconst=no])
+ ])
else
dnl When compiling GNU libiconv on a system that does not have iconv yet,
dnl pick the POSIX compliant declaration without 'const'.
- am_cv_proto_iconv_arg1=""
+ gl_cv_iconv_nonconst=yes
+ fi
+ if test $gl_cv_iconv_nonconst = yes; then
+ iconv_arg1=""
+ else
+ iconv_arg1="const"
fi
- AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1],
+ AC_DEFINE_UNQUOTED([ICONV_CONST], [$iconv_arg1],
[Define as const if the declaration of iconv() needs const.])
dnl Also substitute ICONV_CONST in the gnulib generated <iconv.h>.
m4_ifdef([gl_ICONV_H_DEFAULTS],
[AC_REQUIRE([gl_ICONV_H_DEFAULTS])
- if test -n "$am_cv_proto_iconv_arg1"; then
+ if test $gl_cv_iconv_nonconst != yes; then
ICONV_CONST="const"
fi
])
diff --git a/gettext-runtime/m4/intlmacosx.m4 b/gettext-runtime/m4/intlmacosx.m4
index ebd9937c1..ecc88d6e7 100644
--- a/gettext-runtime/m4/intlmacosx.m4
+++ b/gettext-runtime/m4/intlmacosx.m4
@@ -1,5 +1,5 @@
# intlmacosx.m4 serial 8 (gettext-0.20.2)
-dnl Copyright (C) 2004-2014, 2016, 2019-2020 Free Software Foundation, Inc.
+dnl Copyright (C) 2004-2014, 2016, 2019-2022 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
diff --git a/gettext-runtime/m4/inttypes_h.m4 b/gettext-runtime/m4/inttypes_h.m4
index ebb532037..6e9eebf1b 100644
--- a/gettext-runtime/m4/inttypes_h.m4
+++ b/gettext-runtime/m4/inttypes_h.m4
@@ -1,5 +1,5 @@
# inttypes_h.m4 serial 10
-dnl Copyright (C) 1997-2004, 2006, 2008-2020 Free Software Foundation, Inc.
+dnl Copyright (C) 1997-2004, 2006, 2008-2022 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
diff --git a/gettext-runtime/m4/nls.m4 b/gettext-runtime/m4/nls.m4
index 5a506fc4b..7c11c90f5 100644
--- a/gettext-runtime/m4/nls.m4
+++ b/gettext-runtime/m4/nls.m4
@@ -1,5 +1,5 @@
# nls.m4 serial 6 (gettext-0.20.2)
-dnl Copyright (C) 1995-2003, 2005-2006, 2008-2014, 2016, 2019-2020 Free
+dnl Copyright (C) 1995-2003, 2005-2006, 2008-2014, 2016, 2019-2022 Free
dnl Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
diff --git a/gettext-runtime/m4/po.m4 b/gettext-runtime/m4/po.m4
index 3778fd7aa..ace6f960a 100644
--- a/gettext-runtime/m4/po.m4
+++ b/gettext-runtime/m4/po.m4
@@ -1,5 +1,5 @@
# po.m4 serial 31 (gettext-0.20.2)
-dnl Copyright (C) 1995-2014, 2016, 2018-2020 Free Software Foundation, Inc.
+dnl Copyright (C) 1995-2014, 2016, 2018-2022 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
diff --git a/gettext-runtime/m4/progtest.m4 b/gettext-runtime/m4/progtest.m4
index 0355e61d7..4a5b0b4c6 100644
--- a/gettext-runtime/m4/progtest.m4
+++ b/gettext-runtime/m4/progtest.m4
@@ -1,5 +1,5 @@
# progtest.m4 serial 9 (gettext-0.21.1)
-dnl Copyright (C) 1996-2003, 2005, 2008-2020 Free Software Foundation, Inc.
+dnl Copyright (C) 1996-2003, 2005, 2008-2022 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
diff --git a/gettext-runtime/m4/size_max.m4 b/gettext-runtime/m4/size_max.m4
index 6ebb93f21..1d6abaeaa 100644
--- a/gettext-runtime/m4/size_max.m4
+++ b/gettext-runtime/m4/size_max.m4
@@ -1,5 +1,5 @@
# size_max.m4 serial 12
-dnl Copyright (C) 2003, 2005-2006, 2008-2020 Free Software Foundation, Inc.
+dnl Copyright (C) 2003, 2005-2006, 2008-2022 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
diff --git a/gettext-runtime/m4/stdint_h.m4 b/gettext-runtime/m4/stdint_h.m4
index 9df9e0480..b8684b61a 100644
--- a/gettext-runtime/m4/stdint_h.m4
+++ b/gettext-runtime/m4/stdint_h.m4
@@ -1,5 +1,5 @@
# stdint_h.m4 serial 9
-dnl Copyright (C) 1997-2004, 2006, 2008-2020 Free Software Foundation, Inc.
+dnl Copyright (C) 1997-2004, 2006, 2008-2022 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
diff --git a/gettext-runtime/m4/xsize.m4 b/gettext-runtime/m4/xsize.m4
index 978f99ab6..0109049e0 100644
--- a/gettext-runtime/m4/xsize.m4
+++ b/gettext-runtime/m4/xsize.m4
@@ -1,5 +1,5 @@
# xsize.m4 serial 5
-dnl Copyright (C) 2003-2004, 2008-2020 Free Software Foundation, Inc.
+dnl Copyright (C) 2003-2004, 2008-2022 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.