* lib/mgetgroups.c: Include stdckdint.h.
(mgetgroups): Check for a signed integer overflow when increasing the
size of the array for reallocation.
* modules/mgetgroups (Depends-on): Add stdckdint-h.
Lasse Collin [Sat, 8 Aug 2026 10:30:08 +0000 (13:30 +0300)]
verify: Fix single-argument static_assert with glibc in C89 & C99 modes
* lib/verify.h: glibc's <sys/cdefs.h> may define _Static_assert
with two arguments when the compiler is in C89 or C99 mode.
Undefine it so that Gnulib's own version is used instead.
Reported by G. Branden Robinson in
<https://lists.gnu.org/archive/html/bug-gnulib/2026-08/msg00125.html>.
Lasse Collin [Sat, 8 Aug 2026 10:30:08 +0000 (13:30 +0300)]
verify: Add a comment about Clang on Mac OS 10.7.5
* lib/verify.h: The existing comment says "clang 4+" but the #if
checks for 5 <= __clang_major__. The mismatch looked like a bug.
Add a comment based on the commit 0cda5beb7962 ("verify: port to
Mac OS 10.7.5") to explain why the condition checks for 5 <=.
Bruno Haible [Tue, 4 Aug 2026 15:03:56 +0000 (17:03 +0200)]
readutmp: Add option to make use of wtmpdb.
* m4/wtmpdb.m4: New file.
* m4/readutmp.m4 (gl_READUTMP): Invoke gl_WTMPDB_CHOICE. Define
READUTMP_USE_WTMPDB. Take it into account for READUTMP_LIB.
* lib/readutmp.h (WTMPDB_FILE): New macro.
* lib/readutmp.c: Include <wtmpdb.h>.
(wtmpdb_time_to_timespec): New function.
(struct wtmpdb_locals): New type.
(wtmpdb_callback, read_utmp_from_wtmpdb): New functions.
(read_utmp): For WTMP_FILE, conditionally use read_utmp_from_wtmpdb.
* modules/readutmp (Files): Add m4/wtmpdb.m4.
(Depends-on): Add str_endswith.
* DEPENDENCIES: Mention libwtmpdb.
posix_spawn_faction_add{chdir,fchdir}: Fix checks on glibc-2.44.
Reported by Jason Montleon in
<https://bugzilla.redhat.com/show_bug.cgi?id=2502638>
and by Xi Ruoyao <xry111@xry111.site> in
<https://lists.gnu.org/archive/html/bug-gnulib/2026-07/msg00164.html>.
* m4/posix_spawn_faction_addchdir.m4
(gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR): Use AC_CHECK_DECLS instead
of AC_CHECK_FUNCS_ONCE.
* m4/posix_spawn_faction_addfchdir.m4
(gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR): Use AC_CHECK_DECLS instead
of AC_CHECK_FUNCS_ONCE.
Paul Eggert [Wed, 29 Jul 2026 22:19:28 +0000 (15:19 -0700)]
localename: add GNULIB_LOCALENAME_SINGLE_THREAD
If GNULIB_LOCALENAME_SINGLE_THREAD is defined,
omit locks in localename and getlocalename-related functions.
Useful for GNU grep; see <https://bugs.gnu.org/81515>.
* lib/getlocalename_l-unsafe.c, lib/getlocalename_l.c:
* lib/localename.c (USE_ISOC_AND_POSIX_THREADS, USE_ISOC_THREADS)
(USE_POSIX_THREADS, USE_WINDOWS_THREADS)
[GNULIB_LOCALENAME_SINGLE_THREAD]: Undef.
Bruno Haible [Tue, 28 Jul 2026 20:37:55 +0000 (22:37 +0200)]
tests: Avoid some more runtime errors with Fil-C.
* tests/test-c32ispunct.c (main): Skip a test case that fails on Fil-C.
* tests/test-free.c (main): Avoid converting from a pointer to uintptr_t
and back.
* tests/test-explicit_bzero.c (test_heap): Skip this test on Fil-C.
* tests/test-memset_explicit.c (test_heap): Likewise.
* tests/test-sigsegv-catch-segv1.c: Skip the entire test on Fil-C, since
it relies on converting an uintptr_t value to a pointer.
* tests/test-sigsegv-catch-segv2.c: Likewise.
Paul Eggert [Mon, 27 Jul 2026 20:31:35 +0000 (13:31 -0700)]
malloc: port to current -m32 AddressSanitizer
Also, port better to non-glibc, and in documentation update the
list of platforms needing a fix. This includes 32-bit platforms
using AddressSanitizer, unfortunately.
* m4/malloc.m4 (gl_CHECK_MALLOC_PTRDIFF): Invoke gl_MUSL_LIBC.
musl is safe, as is FreeBSD 11+, NetBSD 8+, OpenBSD 5.6+, AIX,
Microsoft Windows. However, the AddressSanitizer is unsafe.
Bruno Haible [Sun, 26 Jul 2026 22:48:34 +0000 (00:48 +0200)]
Pacify -fsanitize=address in rawmemchr, strchrnul also with clang < 22.
* lib/memchr.c (__has_feature): New macro.
(__memchr): Test the feature 'address_sanitizer'.
* lib/memchr2.c (__has_feature): New macro.
(memchr2): Test the feature 'address_sanitizer'.
* lib/rawmemchr.c (__has_feature): New macro.
(rawmemchr): Test the feature 'address_sanitizer'.
* lib/strchrnul.c (__has_feature): New macro.
(strchrnul): Test the feature 'address_sanitizer'.
Paul Eggert [Sun, 26 Jul 2026 20:46:46 +0000 (13:46 -0700)]
Pacify -fsanitize=address in rawmemchr, strchrnul
Problem reported by Lasse Collin in:
https://lists.gnu.org/r/bug-gnulib/2026-07/msg00174.html
* lib/memchr.c (__memchr), lib/memchr2.c (memchr2):
* lib/rawmemchr.c (rawmemchr), lib/strchrnul.c (strchrnul):
Omit the longword optimization if __SANITIZE_ADDRESS__.
Paul Eggert [Sun, 26 Jul 2026 18:49:42 +0000 (11:49 -0700)]
Fix strict aliasing violations in memchr etc
Problem and fix reported by Lasse Collin in:
https://lists.gnu.org/r/bug-gnulib/2026-07/msg00172.html
* lib/memchr.c (__memchr), lib/memchr2.c (memchr2):
* lib/memrchr.c (__memrchr), lib/rawmemchr.c (rawmemchr):
* lib/strchrnul.c (strchrnul):
Add _GL_ATTRIBUTE_MAY_ALIAS to the longword typedef.
Paul Eggert [Sun, 26 Jul 2026 18:43:06 +0000 (11:43 -0700)]
snprintf, vsnprintf: update doc
* doc/gnulib-intro.texi (Supported Platforms):
Also mention z/OS, Fil-C. Not sure where they should be listed
but I gave it a guess.
* doc/posix-functions/snprintf.texi (snprintf):
* doc/posix-functions/vsnprintf.texi (vsnprintf):
Also mention Fil-C bug.
Bruno Haible [Sat, 25 Jul 2026 23:15:14 +0000 (01:15 +0200)]
szprintf: Port to Fil-C.
* lib/szprintf.c (szprintf): Ensure lenbuf is at most INT_MAX.
* lib/vszprintf.c (vszprintf): Likewise.
* lib/unistdio/u-vsprintf.h (VSPRINTF): Ensure lenbuf is at most
INT_MAX / sizeof (DCHAR_T).
Paul Eggert [Sat, 25 Jul 2026 16:05:21 +0000 (09:05 -0700)]
gettext-h: conform to C on Solaris
On Solaris, gettext.h was sometimes converting char const * to char *
without a cast, which violates a constraint of the C standard.
GCC 3.4.3 complained about this. Though the compile succeeded
it’s better to not violate constraints when it’s easy.
* lib/gettext.h (gettext, dgettext, dcgettext)
[__sun && __GNUC__ && !__clang__ && !__cplusplus && !ENABLE_NLS]:
Cast msgid to char * before returning.
Paul Eggert [Sat, 25 Jul 2026 14:52:01 +0000 (07:52 -0700)]
verify: port to Solaris 10 + gcc 3.4.3 + assert-h
I ran into this problem when building GNU m4 (Savannah commit 7d5125b78d56dfa08b6bb4205428eb9962ad9244) on Solaris 10 sparc.
It has GCC 3.4.3 (csl-sol210-3_4-branch+sol_rpath),
which lacks _Static_assert. GNU m4 both uses assert-h and
includes <verify.h>, and without this patch the latter mistakenly
#undefs the _Static_assert that the former defined.
* lib/verify.h (_Static_assert) [_GL_STATIC_ASSERT]: Do not undef.
Paul Eggert [Sat, 18 Jul 2026 03:59:32 +0000 (20:59 -0700)]
diffseq: gcc bug 80922 should be fixed now
* lib/diffseq.h: Stop ignoring -Wmaybe-uninitialized and
-Wanalyzer-use-of-uninitialized-value in GCC 17 and later,
as the bug I reported to GCC seems to have been fixed.
Paul Eggert [Fri, 17 Jul 2026 20:47:19 +0000 (13:47 -0700)]
getopt: port to NetBSD git head gcc -Wuseless cast
Problem reported by Thomas Klausner in:
https://lists.gnu.org/r/emacs-devel/2026-07/msg00169.html
* lib/getopt-pfx-ext.h (__getopt_argv_const_is_empty): New macro,
defined to 1 when we define __getopt_argv_const to empty.
* lib/getopt1.c (ARGV_CAST): New macro.
(getopt_long, getopt_long_only): Use it.
Paul Eggert [Fri, 17 Jul 2026 17:50:24 +0000 (10:50 -0700)]
gendocs: output human-readable file sizes
* build-aux/gendocs.sh (calcsize): Output human-readable file
size, rather than always size in KiB mislabled as "K bytes".
But fall back on a plain byte count if GNU du is not in use.
(time-stamp-time-zone): Now "UTC0" so scriptversion does not decrease.
* doc/gendocs_template, doc/gendocs_template_min:
Don’t assume sizes are in KiB (the old values were mislabeled anyway).
Be more consistent about file type labels.
physmem: allow physmem_claimable to return more than 4 GiB on NetBSD.
Problem reported by Bruno Haible in:
<https://lists.gnu.org/r/bug-gnulib/2026-07/msg00046.html>.
* m4/physmem.m4 (gl_PHYSMEM): Check for the presence of
uvm/uvm_extern.h.
* lib/physmem.c [HAVE_UVM_UVM_EXTERN_H]: Include uvm/uvm_extern.h.
(physmem_claimable) [HAVE_SYSCTL && VM_UVMEXP2]: Calculate the free
memory using a NetBSD-specific sysctl.
physmem: allow physmem_claimable to return more than 8 GiB on FreeBSD.
Problem reported by Bruno Haible in:
<https://lists.gnu.org/r/bug-gnulib/2026-07/msg00046.html>.
* m4/physmem.m4 (gl_PHYSMEM): Check for the sysctlbyname function.
* lib/physmem.c (physmem_claimable) [HAVE_SYSCTLBYNAME && __FreeBSD__]:
Calculate of free memory from some FreeBSD-specific sysctl strings.
Bruno Haible [Tue, 14 Jul 2026 17:28:10 +0000 (19:28 +0200)]
vasnprintf-extra-tests: Refactor.
* tests/test-vasnprintf-big1.c: New file, based on
tests/test-vasnprintf-big.c.
* tests/test-vasnprintf-big2.c: New file, based on
tests/test-vasnprintf-big.c.
* tests/test-vasnprintf-big.c: Remove file.
* modules/vasnprintf-extra-tests: Update to build two separate programs.
Bruno Haible [Mon, 13 Jul 2026 21:06:33 +0000 (23:06 +0200)]
vaszprintf-extra-tests: New module.
* tests/test-vaszprintf-big.c: New file, extracted from
tests/test-vaszprintf-posix.c.
* tests/test-vaszprintf-posix.c (test_function): Revert last change.
* modules/vaszprintf-extra-tests: New file.
* modules/vaszprintf-tests: New file.
Paul Eggert [Tue, 7 Jul 2026 03:35:24 +0000 (20:35 -0700)]
vasnprintf: fix ("%*d", INT_MAX, n)
I ran into this problem when doing stress testing with GNU m4.
The problem is that ("%*d", INT_MAX, n) fails because the code
refuses to create a buffer of size INT_MAX + 1u,
due to problems when dealing with older nonconforming snprintf.
The simplest fix was to use snprintf only if it handles
sizes like INT_MAX + 1u, and to fall back on sprintf otherwise.
Nowadays I think snprintf should work on most practical targets.
Assuming this patch works out, perhaps we could simplify
lib/vasnprintf.c to ease further maintenance,
as nowadays I hope we can assume both HAVE_SNPRINTF_RETVAL_C99 and
HAVE_SNPRINTF_TRUNCATION_C99 on platforms where USE_SNPRINTF.
* lib/vasnprintf.c: Include minmax.h.
(USE_SNPRINTF): Define to 1 only if glibc 2+, Android, musl,
the BSDs, macOS, or Microsoft UCRT.
(VASNPRINTF) [USE_SNPRINTF]:
Allow maxlen to be 1 greater than INT_MAX on 64-bit platforms.
Document the limit’s derivation by using named locals.
Do not attempt to work around bugs in pre-C99 implementations,
as USE_SNPRINTF is pickier now.
* m4/vasnprintf.m4 (gl_PREREQ_VASNWPRINTF):
Move gl_MUSL_LIBC call from here ...
(gl_PREREQ_VASNXPRINTF): ... to here.
* modules/c-vasnprintf, modules/unistdio/u16-u16-vasnprintf:
* modules/unistdio/u16-vasnprintf:
* modules/unistdio/u32-u32-vasnprintf:
* modules/unistdio/u32-vasnprintf:
* modules/unistdio/u8-u8-vasnprintf:
* modules/unistdio/u8-vasnprintf, modules/unistdio/ulc-vasnprintf:
* modules/vasnprintf, modules/vasnwprintf:
(Files): Add m4/musl.m4 if it isn’t there already.
(Depends-on): Add minmax.
* tests/test-vasnprintf-posix.c:
* tests/test-vasprintf-posix.c:
* tests/test-vaszprintf-posix.c:
Include <limits.h> and <errno.h> if needed.
(test_function): Test for the bug, if RUN_EXPENSIVE_TESTS=yes
in the environment; this the coreutils tradition and I
didn’t see any Gnulib tradition so I just used it.
Paul Eggert [Fri, 26 Jun 2026 18:20:50 +0000 (11:20 -0700)]
bitset: possibly widen unsigned indexes
* lib/bitset/vector.c (vbitset_empty_p, vbitset_not)
(vbitset_disjoint_p, vbitset_and, vbitset_and_or)
(vbitset_and_or_cmp, vbitset_andn_or, vbitset_andn_or_cmp)
(vbitset_or_and, vbitset_or_and_cmp):
In a for-loop, use an index type related to the upper bound’s type
rather than trusting ‘unsigned’ to be wide enough.
Paul Eggert [Fri, 26 Jun 2026 17:29:05 +0000 (10:29 -0700)]
bitrotate: prefer C2y to bitrotate or by-hand
Deprecate the bitrotate module; it is superseded by C2y’s
stdc_rotate_left and stdc_rotate_right. In several places, prefer
the C2y functions to doing things by hand.
* lib/arctwo.c (arctwo_encrypt, arctwo_decyrpt):
* lib/hash.c (raw_hasher):
* lib/hashcode-mem.c (hash_pjw_bare):
* lib/hashcode-string1.c (hash_string):
* lib/hashcode-string2.c (hash_pjw):
* lib/hashkey-string.c (hashkey_string_hash):
* lib/mem-hash-map.c (compute_hashval):
* lib/struniq.h (hash):
* tests/test-array_map.c (string_hash):
* tests/test-avltreehash_list.c (string_hash):
* tests/test-hash_map.c (string_hash):
* tests/test-linkedhash_list.c (string_hash):
* tests/test-linkedhash_map.c (string_hash):
* tests/test-rbtreehash_list.c (string_hash):
Use stdbit.h functions, instead of bitrotate.h functions or doing
things by hand. Include stdbit.h to get them. Don’t include
bitrotate.h, if it was being included.
* lib/getlocalename_l-unsafe.c, lib/getlocalename_l.c:
* lib/localename.c:
Include stdbit.h, since struniq.h now needs this.
* lib/hashcode-mem.c, lib/hashcode-string2.c, lib/hashkey-string.c:
* lib/struniq.h, tests/test-array_map.c, tests/test-avltreehash_list.c:
* tests/test-hash_map.c, tests/test-linkedhash_list.c:
* tests/test-linkedhash_map.c, tests/test-rbtreehash_list.c:
(SIZE_BITS): Remove; no longer needed.
* modules/array-map-tests, modules/avltreehash-list-tests:
* modules/crypto/arctwo, modules/getlocalename_l-simple:
* modules/getlocalename_l-unsafe, modules/hash:
* modules/hash-map-tests, modules/hashcode-mem:
* modules/hashcode-string1, modules/hashcode-string2:
* modules/hashkey-string, modules/linkedhash-list-tests:
* modules/linkedhash-map-tests, modules/localename:
* modules/mem-hash-map, modules/rbtree-list-tests:
Depend on stdc_rotate_left.
Don’t depend on bitrotate, if we were depending on it.
* modules/bitrotate: Deprecate.
* modules/crypto/arctwo: Depend on stdc_rotate_right.
Paul Eggert [Thu, 25 Jun 2026 15:27:36 +0000 (08:27 -0700)]
fstatat: port null file support to Alpine 3.24
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2026-06/msg00093.html
* m4/fstatat.m4 (gl_FUNC_FSTATAT): When checking for
support for a null pointer file, check nonnegative directory
file descriptors as well as AT_FDCWD.
Paul Eggert [Sat, 20 Jun 2026 17:45:10 +0000 (10:45 -0700)]
gethrxtime: don’t use nanouptime, microuptime
* lib/gethrxtime.c (gethrxtime): On platforms with
CLOCK_MONOTONIC, try it first. If it fails, just fall back on
CLOCK_REALTIME as that’s what current_timespec would do anyway.
On platforms lacking CLOCK_MONOTONIC, just use current_timespec.
* m4/gethrxtime.m4 (gl_GETHRXTIME): Don’t check for microuptime or
nanouptime. They aren’t exposed to user space by BSD kernels now,
and it’s not clear that they ever were.