Paul Eggert [Sun, 30 Jun 2024 10:27:48 +0000 (11:27 +0100)]
strnlen: avoid undefined memcmp behavior
Problem reported by Po Lu in:
https://lists.gnu.org/r/bug-gnulib/2024-06/msg00288.html
* config/srclist.txt: Don’t mention strnlen.c even in a comment,
as the Gnulib and glibc implementations have diverged for
portability reasons, and they’re never likely to merge.
* lib/strnlen.c (strnlen): Avoid undefined behavior if
the array S points to has fewer than MAXLEN bytes.
Bruno Haible [Wed, 19 Jun 2024 00:58:34 +0000 (02:58 +0200)]
copysignl tests: Avoid failure on Solaris 11.4.
* tests/test-copysignl.c: Include <float.h>.
(LDBL_BYTES): New macro.
(main): Use it instead of sizeof (long double).
* modules/copysignl-tests (Depends-on): Add float.
Bruno Haible [Sun, 9 Jun 2024 17:16:01 +0000 (19:16 +0200)]
c32rtomb: Add a sanity check, working around Solaris 11 OmniOS.
* m4/c32rtomb.m4 (gl_CHECK_FUNC_C32RTOMB): New macro, extracted from
gl_FUNC_C32RTOMB.
(gl_C32RTOMB_SANITYCHECK): New macro.
(gl_FUNC_C32RTOMB): Require gl_CHECK_FUNC_C32RTOMB and
gl_C32RTOMB_SANITYCHECK. If HAVE_WORKING_C32RTOMB is 0, set
REPLACE_C32RTOMB.
* lib/c32rtomb.c (c32rtomb): Together with HAVE_WORKING_MBRTOC32, test
also HAVE_WORKING_C32RTOMB.
* m4/mbrtoc32.m4 (gl_PREREQ_MBRTOC32): Require gl_C32RTOMB_SANITYCHECK.
* lib/mbrtoc32.c (mbrtoc32): Together with HAVE_WORKING_MBRTOC32, test
also HAVE_WORKING_C32RTOMB.
* modules/mbrtoc32 (Files): Add m4/c32rtomb.m4.
* lib/btoc32.c (btoc32): Together with HAVE_WORKING_MBRTOC32, test also
HAVE_WORKING_C32RTOMB.
* lib/mbsrtoc32s.c: Together with HAVE_WORKING_MBRTOC32, test also
HAVE_WORKING_C32RTOMB.
* lib/mbsnrtoc32s.c: Together with HAVE_WORKING_MBRTOC32, test also
HAVE_WORKING_C32RTOMB.
* lib/c32tob.c (c32tob): Together with HAVE_WORKING_MBRTOC32, test also
HAVE_WORKING_C32RTOMB.
* modules/c32tob (Files): Add m4/c32rtomb.m4.
(configure.ac): Require gl_C32RTOMB_SANITYCHECK.
* lib/c32srtombs.c: Together with HAVE_WORKING_MBRTOC32, test also
HAVE_WORKING_C32RTOMB.
* lib/c32snrtombs.c: Together with HAVE_WORKING_MBRTOC32, test also
HAVE_WORKING_C32RTOMB.
* lib/c32to-impl.h (FUNC): Together with HAVE_WORKING_MBRTOC32, test
also HAVE_WORKING_C32RTOMB.
* modules/c32tolower (Files): Add m4/c32rtomb.m4.
(configure.ac): Require gl_C32RTOMB_SANITYCHECK.
* modules/c32toupper (Files): Add m4/c32rtomb.m4.
(configure.ac): Require gl_C32RTOMB_SANITYCHECK.
* lib/c32width.c (c32width): Together with HAVE_WORKING_MBRTOC32, test
also HAVE_WORKING_C32RTOMB.
* modules/c32width (Files): Add m4/c32rtomb.m4.
(configure.ac): Require gl_C32RTOMB_SANITYCHECK.
Paul Eggert [Tue, 11 Jun 2024 22:09:55 +0000 (15:09 -0700)]
mktempd: use GNU-style -t if available
This better satisfies Jim Meyering’s point in:
https://lists.gnu.org/archive/html/bug-gnulib/2016-03/msg00074.html
that it’s more useful when each temporary test directory name
includes the corresponding test’s name.
* build-aux/mktempd: Try mktemp -t only with GNU syntax, so that
NetBSD mktemp fails. Also, reject templates beginning with "-" so
that they are not treated as options.
* tests/init.sh (mktempd_): Likewise.
Bruno Haible [Thu, 6 Jun 2024 00:33:41 +0000 (02:33 +0200)]
setenv: On native Windows, don't modify _environ directly.
* m4/setenv.m4 (gl_PREREQ_SETENV): Check for _putenv.
* lib/setenv.c: On native Windows, include <windows.h> and define
SetEnvironmentVariable.
(setenv) [HAVE_DECL__PUTENV]: New implementation for platforms with
_putenv.
* modules/setenv (Depends-on): Add malloc-posix.
Bruno Haible [Tue, 4 Jun 2024 01:59:37 +0000 (03:59 +0200)]
readlinkat: Work around a Cygwin 3.3.6 bug.
* m4/readlinkat.m4 (gl_FUNC_READLINKAT): Set REPLACE_READLINKAT to 1 on
Cygwin.
* lib/readlinkat.c (rpl_readlinkat): On Cygwin, for /dev/* files, don't
return results that start with a backslash.
* doc/posix-functions/readlinkat.texi: Mention the Cygwin bug.
Bruno Haible [Mon, 3 Jun 2024 23:48:04 +0000 (01:48 +0200)]
readlink: Work around a Cygwin 3.3.6 bug.
* m4/readlink.m4 (gl_FUNC_READLINK): Set REPLACE_READLINK to 1 on Cygwin.
* lib/readlink.c (rpl_readlink): On Cygwin, for /dev/* files, don't
return results that start with a backslash.
* tests/test-readlink.h (test_readlink): Add a test of /dev/null.
* tests/test-canonicalize-lgpl.c (main): Likewise.
* tests/test-canonicalize.c (main): Likewise.
* doc/posix-functions/readlink.texi: Mention the Cygwin bug.
Bruno Haible [Mon, 3 Jun 2024 15:20:20 +0000 (17:20 +0200)]
acl-permissions: Fix test-file-has-acl-2.sh failure on Cygwin.
* lib/acl-internal.c: Include <sys/types.h>, <grp.h>, <string.h>.
(acl_access_nontrivial): On Cygwin, ignore group:SYSTEM:*,
group:Administrators:*, group:Users:*, mask::* entries.
* doc/acl-resources.txt: Add one more reference.
Bruno Haible [Mon, 3 Jun 2024 13:34:21 +0000 (15:34 +0200)]
dprintf-posix tests: Skip the memory leak test on macOS.
* tests/test-dprintf-posix2.c: Skip the test on macOS.
(main): Return a different exit code at each point. Allow 100 KB extra
memory consumption.
* tests/test-dprintf-posix2.sh: Update.
Bruno Haible [Sun, 2 Jun 2024 16:34:36 +0000 (18:34 +0200)]
isnanf, isnand, isnanl: Fix link errors on AIX 7.1 with xlc.
* lib/isnanf-nolibm.h (HAVE_ISNANF_NOLIBM): New macro.
* lib/isnand-nolibm.h (HAVE_ISNAND_NOLIBM): New macro.
* lib/isnanl-nolibm.h (HAVE_ISNANL_NOLIBM): New macro.
* lib/math.h (isnanf): Don't define via isnan if HAVE_ISNANF_NOLIBM is
defined.
(isnand): Don't define via isnan if HAVE_ISNAND_NOLIBM is defined.
(isnanl): Don't define via isnan if HAVE_ISNANL_NOLIBM is defined.
Bruno Haible [Thu, 30 May 2024 18:06:58 +0000 (20:06 +0200)]
assert-h, verify: Fix compilation error with g++ (4.8.5) -std=gnu++11.
Reported by Harmen <harmen@stoppels.ch> at
<https://savannah.gnu.org/bugs/index.php?65811>.
* lib/verify.h (static_assert): In C++ mode with g++ < 6 and
-std=gnu++11, define in a way that supports also the 1-argument
invocations and the invocations inside C++ struct and class.
Bruno Haible [Thu, 30 May 2024 08:23:22 +0000 (10:23 +0200)]
windows-once: Free allocated resources when done.
Based on an observation regarding Cygwin's pthread_once implementation
by Takashi Yano <takashi.yano@nifty.ne.jp> at
<https://cygwin.com/pipermail/cygwin/2024-January/255182.html> and
<https://cygwin.com/pipermail/cygwin-patches/2024q1/012600.html>
* lib/windows-once.h (glwthread_once_t): Change type of inited to LONG.
Add field 'num_threads'.
(GLWTHREAD_ONCE_INIT): Initialize it to zero.
* lib/windows-once.c (glwthread_once): Use InterlockedCompareExchange
instead of InterlockedIncrement. Increment num_threads while the thread
uses the lock. Let the last thread that uses the lock destroy it.
Bruno Haible [Thu, 30 May 2024 08:55:40 +0000 (10:55 +0200)]
call_once: Work around Cygwin 3.5.3 bug.
* m4/call_once.m4 (gl_FUNC_CALL_ONCE): Require AC_CANONICAL_HOST.
On Cygwin, set REPLACE_CALL_ONCE to 1.
* lib/call_once.c (call_once): On Cygwin, use a cast, to avoid a
compiler warning.
* modules/call_once (Depends-on): Add pthread-once.
* doc/posix-functions/call_once.texi: Mention the Cygwin bug.
Bruno Haible [Tue, 28 May 2024 20:35:54 +0000 (22:35 +0200)]
pthread-once: Work around Cygwin 3.5.3 bug.
* m4/pthread-once.m4 (gl_PTHREAD_ONCE): On Cygwin, set
REPLACE_PTHREAD_ONCE to 1.
* lib/pthread-once.c (pthread_once): Add an implementation for Cygwin.
* doc/posix-functions/pthread_once.texi: Mention the Cygwin bug.
Bruno Haible [Mon, 27 May 2024 21:29:36 +0000 (23:29 +0200)]
nstrftime: Make %r work on macOS, FreeBSD, native Windows.
* doc/posix-functions/strftime.texi: Mention the %r problem.
* lib/nstrftime.c (__strftime_internal): On macOS, FreeBSD, and native
Windows, for %r, use the English AM/PM format.
Bruno Haible [Mon, 27 May 2024 21:01:50 +0000 (23:01 +0200)]
nstrftime: Make %c work on native Windows.
* doc/posix-functions/strftime.texi: Mention the %c problem.
* lib/nstrftime.c: Include <locale.h>. Include hard-locale.h.
(__strftime_internal): For %c, use a subformat that contains the weekday
name (or abbrev.) and the month name (or abbrev.).
* modules/nstrftime (Depends-on): Add hard-locale.
(Link): New section.
* modules/nstrftime-tests (Makefile.am): Link test-nstrftime with
$(HARD_LOCALE_LIB).
Bruno Haible [Mon, 27 May 2024 15:42:20 +0000 (17:42 +0200)]
parse-datetime tests: Avoid failure on native Windows.
* tests/test-parse-datetime.c (SOME_TIMEPOINT): New macro.
(main): Use it. On native Windows, use Windows time zone names.
Invoke tzset() after setting TZ.
* doc/posix-functions/gmtime.texi: Mention the native Windows problem.
* doc/posix-functions/localtime.texi: Likewise.
Bruno Haible [Thu, 23 May 2024 21:46:52 +0000 (23:46 +0200)]
mbrtoc32: Work around bug in Cygwin 3.5.3.
* m4/mbrtoc32.m4 (gl_MBRTOC32_UTF8_LOCALE): New macro.
(gl_FUNC_MBRTOC32): Invoke it. If mbrtoc32 has this bug, define
MBRTOC32_MULTIBYTE_LOCALE_BUG and reset LOCALE_ZH_CN to 'none'.
* lib/mbrtoc32.c (mbrtoc32): Test MBRTOC32_MULTIBYTE_LOCALE_BUG.
* doc/posix-functions/mbrtoc32.texi: Mention the Cygwin bug.
Bruno Haible [Thu, 23 May 2024 13:15:40 +0000 (15:15 +0200)]
renameatu: Work around Cygwin 3.4.6 bug.
* m4/renameat.m4 (gl_FUNC_RENAMEAT): Test whether renameat2 works, and
define HAVE_WORKING_RENAMEAT2 if so.
* lib/renameatu.c (renameatu): Test HAVE_WORKING_RENAMEAT2 instead of
HAVE_RENAMEAT2.
Bruno Haible [Wed, 22 May 2024 23:10:18 +0000 (01:10 +0200)]
iconv: Reject the broken macOS 14.4 iconv implementation.
Reported by Daniel Collins <solemnwarning@solemnwarning.net> at
<https://savannah.gnu.org/bugs/?65686>.
* m4/iconv.m4 (AM_ICONV_LINK): In the test "for working iconv", test
against the macOS 14.4 iconv bug.
* doc/posix-functions/iconv.texi: Document the bug.
Bruno Haible [Mon, 20 May 2024 22:33:55 +0000 (00:33 +0200)]
vasnprintf: Don't abort for pseudo-denormal arguments on macOS 12.
Reported by Gaëtan Herfray <g.herfray@gahfy.io> via Erik Blake in
<https://lists.gnu.org/archive/html/bug-m4/2022-03/msg00002.html>
<https://lists.gnu.org/archive/html/bug-gnulib/2022-03/msg00066.html>.
* lib/vasnprintf.c (safe_frexpl): New function.
(decode_long_double, floorlog10l): Invoke it instead of frexpl.
Paul Eggert [Mon, 20 May 2024 21:55:11 +0000 (14:55 -0700)]
getopt-posix: port better to Alpine 3.20.0_rc1
Alpine’s <sys/cdefs.h> is a stub that issues a deprecation #warning.
* m4/getopt.m4 (gl_GETOPT_SUBSTITUTE_HEADER):
* m4/sched_h.m4 (gl_SCHED_H): Use the new macro
gl_CHECK_HEADER_SYS_CDEFS_H instead of checking independently.
* m4/sys_cdefs_h.m4: New file.
* modules/getopt-posix, modules/sched (Files): Add m4/sys_cdefs_h.m4.
Collin Funk [Mon, 20 May 2024 21:23:41 +0000 (14:23 -0700)]
utimensat, utimens: Work around NetBSD 10.0 bugs.
* lib/utimens.c (fdutimens): Work around a NetBSD 10.0 UTIME_OMIT bug in
the same way as Linux kernel 2.6.32 and Solaris 11.1.
(lutimens): Likewise.
* lib/utimensat.c (rpl_utimensat): Likewise. Workaround a NetBSD 10.0
bug where invalid tv_nsec values are not rejected in the same way as
Linux kernel 2.6.22.19 on hppa.
* doc/posix-functions/utimensat.texi: Document the invalid tv_nsec bug.
Bruno Haible [Thu, 9 May 2024 12:01:10 +0000 (14:01 +0200)]
explicit_bzero, memset_explicit tests: Avoid test failures with ASAN.
* tests/test-explicit_bzero.c (test_heap, test_stack): Define to empty
if ASAN is enabled.
* tests/test-memset_explicit.c (test_heap, test_stack): Likewise.
Bruno Haible [Thu, 9 May 2024 10:56:55 +0000 (12:56 +0200)]
dprintf-posix, fprintf-posix tests: Avoid test failures with ASAN.
* tests/test-dprintf-posix2.c (main): Skip the test if ASAN is enabled.
* tests/test-fprintf-posix3.c (main): Likewise.
* tests/test-dprintf-posix2.sh: Update.
* tests/test-fprintf-posix3.sh: Likewise.
Bruno Haible [Wed, 8 May 2024 23:41:52 +0000 (01:41 +0200)]
sigsegv, c-stack tests: Avoid test failures with ASAN.
* tests/test-sigsegv-catch-stackoverflow1.c
(HAVE_STACK_OVERFLOW_RECOVERY): Undefine if ASAN is enabled.
* tests/test-sigsegv-catch-stackoverflow2.c
(HAVE_STACK_OVERFLOW_RECOVERY): Likewise.
* tests/test-c-stack.c (main): Skip the test if ASAN is enabled.
Bruno Haible [Wed, 1 May 2024 22:10:21 +0000 (00:10 +0200)]
stddef: A better workaround against GCC bug 114870.
* lib/stddef.in.h: If STDDEF_NOT_IDEMPOTENT is 1, disable the special
invocation convention.
* m4/stddef_h.m4 (gl_STDDEF_H): Set STDDEF_NOT_IDEMPOTENT.
(gl_STDDEF_H_DEFAULTS): Initialize STDDEF_NOT_IDEMPOTENT.
* modules/stddef (Makefile.am): Substitute STDDEF_NOT_IDEMPOTENT.
Paul Eggert [Sat, 27 Apr 2024 16:09:38 +0000 (09:09 -0700)]
stddef: work around a GCC 14 stddef.h bug
* lib/stddef.in.h: (_GCC_NULLPTR_T): Define if needed to work around
GCC bug 114869.
* m4/stddef_h.m4 (gl_STDDEF_H, gl_STDDEF_H_DEFAULTS):
* modules/stddef (stddef.h):
Detect the two bugs 114869 and 114870.
Bruno Haible [Sat, 27 Apr 2024 00:22:05 +0000 (02:22 +0200)]
login_tty tests: Avoid gcc warnings.
* tests/test-login_tty.c: Include ignore-value.h.
(main): Ignore the results of the freopen calls.
* modules/login_tty-tests (Depends-on): Add ignore-value.
Paul Eggert [Wed, 24 Apr 2024 06:18:07 +0000 (23:18 -0700)]
manywarnings: update C warnings for GCC 14
Adjust for C programs compiled by GCC 14.
(A C++ expert still needs to look at manywarnings-c++.m4.)
* build-aux/gcc-warning.spec: Add warnings introduced in GCC 14.
* m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC):
Add -Wflex-array-member-not-at-end, -Wmissing-variable-declarations.
Bruno Haible [Fri, 5 Apr 2024 14:04:59 +0000 (16:04 +0200)]
roundl: Fix a link error on Linux/powerpc64le.
* m4/check-math-lib.m4 (gl_CHECK_MATH_LIB): Accept an additional TYPE
argument.
* m4/isfinite.m4 (gl_ISFINITE): Use the type 'double'.
* m4/isinf.m4 (gl_ISINF): Likewise.
* m4/round.m4 (gl_FUNC_ROUND): Likewise.
* m4/roundf.m4 (gl_FUNC_ROUNDF): Use the type 'float'.
* m4/roundl.m4 (gl_FUNC_ROUNDL): Use the type 'long double'.
quotearg: fix shell-escape quoting with single quotes
With shell-escape quoting, we misquoted strings
where the first and last characters required escaping,
while the string also contained single quotes.
* lib/quotearg.c (quotearg_buffer_restyled): Ensure that
pending_shell_escape_end is reset to the initial state
when reprocessing input due to single quotes.
Reported by Grisha Levit
* lib/renameatu.c(): Fall back to renameat() when
renameatx_np(RENAME_EXCL) returns "Function not implemented".
This issue was seen with macFUSE.
Reported at https://github.com/coreutils/coreutils/issues/79
Paul Eggert [Fri, 29 Mar 2024 22:56:45 +0000 (15:56 -0700)]
intprops: pacify GCC < 10 -Wsign-compare
Problem reported by Martin Dorey in:
https://savannah.gnu.org/bugs/index.php?65537
* lib/intprops-internal.h (_GL_INT_MULTIPLY_WRAPV):
When working around GCC bug 91450, pacify -Wsign-compare by
casting 0 to the result type.
Bruno Haible [Tue, 5 Mar 2024 16:10:38 +0000 (17:10 +0100)]
c-strtod, c-strtold: Make multithread-safe.
* lib/c-strtod.c: Include <langinfo.h>, c-ctype.h.
(decimal_point_char): New function, copied from lib/vasnprintf.c.
(C_STRTOD): On platforms that don't have STRTOD_L nor a working
uselocale(), pre-parse the number and call STRTOD after having replaced
the '.' with the locale-dependent decimal point character.
* m4/c-strtod.m4 (gl_C_STRTOD, gl_C_STRTOLD): Test for nl_langinfo().
* modules/c-strtod (Depends-on): Add c-ctype. Remove strdup-posix.
* modules/c-strtold (Depends-on): Likewise.