As the full review might take some time, would it be possible to apply
at least the part related to fuse.portal file systems? They started to
cause problems recently:
Bruno Haible [Sun, 6 Jun 2021 22:56:50 +0000 (00:56 +0200)]
scratch_buffer: Avoid conflict with prepr. macros owned by the system.
* lib/scratch_buffer.h: Don't include <libc-config.h>. Define
_GL_LIKELY, _GL_UNLIKELY. Include malloc/scratch_buffer.gl.h instead of
malloc/scratch_buffer.h.
* modules/scratch_buffer (Depends-on): Add builtin-expect.
(Makefile.am): Arrange to create malloc/scratch_buffer.gl.h from
malloc/scratch_buffer.h.
Bruno Haible [Sun, 6 Jun 2021 22:54:25 +0000 (00:54 +0200)]
dynarray: Avoid conflict with preprocessor macros owned by the system.
* lib/dynarray.h: Don't include <libc-config.h>. Define _GL_LIKELY,
_GL_UNLIKELY. Include malloc/dynarray.gl.h instead of malloc/dynarray.h.
Include malloc/dynarray-skeleton.gl.h instead of
malloc/dynarray-skeleton.c.
* modules/dynarray (Depends-on): Add builtin-expect.
(Makefile.am): Arrange to create malloc/dynarray.gl.h from
malloc/dynarray.h and malloc/dynarray-skeleton.gl.h from
malloc/dynarray-skeleton.c.
Dmitry V. Levin [Sun, 6 Jun 2021 08:00:00 +0000 (08:00 +0000)]
regex-tests: remove incorrect comment
* tests/test-regex.c (tests): Remove the comment saying that some tests
are not used. That comment was copied along with tests from glibc
where some of these tests are commented out.
Fixes: 70b673eb7 ("regex: fix longstanding backref match bug")
Bruno Haible [Sat, 5 Jun 2021 13:44:26 +0000 (15:44 +0200)]
vasnprintf: Don't leak memory when memory allocation fails.
Found by Coverity. Reported by Mike Fabian <mfabian@redhat.com> in
<https://lists.gnu.org/archive/html/bug-libunistring/2021-06/msg00000.html>.
* lib/vasnprintf.c (VASNPRINTF): In places where a local variable points
to heap-allocated storage, free that storage before doing
'goto out_of_memory;'.
* gnulib-tool: Don't document --more-symlinks and --more-hardlinks any
more.
(do_copyrights): Remove variable.
(func_import): Don't perform license updates on imported files any more.
* pygnulib/GLInfo.py: Don't document --more-symlinks any more.
* doc/gnulib-intro.texi (Copyright): Document the new situation.
* doc/gnulib.texi (Module description): Likewise.
* NEWS: Mention the change.
Bruno Haible [Fri, 4 Jun 2021 18:49:16 +0000 (20:49 +0200)]
Revamp check-copyright script.
* check-copyright: Search only the first 50 lines of each file.
Recognize 'LGPLv3+ or GPLv2+', 'unlimited', and 'public domain' license
notices. For files that are part of several modules, consider the
weakest among the licenses. Allocate more room for the first output
column.
Paul Eggert [Sun, 30 May 2021 17:04:06 +0000 (10:04 -0700)]
reallocarray-tests: port to weird platforms
* tests/test-reallocarray.c (main): Don’t assume that
PTRDIFF_MAX / 2 + 1 <= SIZE_MAX. POSIX allows platforms
where this isn’t true, though I don’t know of any examples.
Paul Eggert [Sun, 30 May 2021 17:02:20 +0000 (10:02 -0700)]
dfa, etc.: prefer xreallocarray to older name
* lib/dfa.c (addtok_mb, realloc_trans_if_necessary, enlist):
* lib/readtokens.c (readtokens):
* tests/uninorm/test-u32-normalize-big.c:
(read_normalization_test_file):
Prefer xreallocarray to the equivalent xnrealloc.
The newer name follows the glibc lead of ‘reallocarray’.
Paul Eggert [Sat, 29 May 2021 17:14:01 +0000 (10:14 -0700)]
sigsegv: Port to Solaris 11
Problem reported by Kiyoshi KANAZAWA in:
https://lists.gnu.org/r/bug-m4/2021-05/msg00020.html
* lib/stackvma.c (_FILE_OFFSET_BITS): #undef on Solaris and Android.
Paul Eggert [Fri, 21 May 2021 21:41:42 +0000 (14:41 -0700)]
sigsegv: don’t assume SIGSTKSZ is a constant
* m4/sigaltstack.m4 (SV_SIGALTSTACK): Don’t attempt to override
SIGSTKSZ. Instead, use an array that is plenty large, while
checking that it’s large enough. Also, be consistent about
putting that array in static storage rather than on the stack.
* tests/altstack-util.h (SIGSTKSZ): Don’t define.
(MYSTACK_SIZE): New macro, used consistently instead of SIGSTKSZ.
(mystack_storage, mystack): Now static.
(prepare_alternate_stack) [defined SIGSTKSZ]:
Check that MYSTACK_SIZE is large enough.
Pádraig Brady [Sat, 15 May 2021 16:50:33 +0000 (17:50 +0100)]
realloc-gnu: avoid glibc MALLOC_CHECK_ issue
* tests/test-realloc-gnu.c (main): if MALLOC_CHECK_ env var
is set then don't check ENOMEM is returned from realloc().
See https://sourceware.org/bugzilla/show_bug.cgi?id=27870
Note it doesn't suffice to unsetenv() this var within the program,
as the hooks have already been set up at that stage.
Paul Eggert [Sat, 15 May 2021 05:48:20 +0000 (22:48 -0700)]
c-stack: work around Solaris 11 bugs
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2021-05/msg00062.html
* lib/c-stack.c: Always include sigsegv.h if HAVE_LIBSIGSEGV.
(USE_LIBSIGSEGV): Do not use libsigsegv if the kernel
has the si_addr bug and libsigsegv is too old to work
around it.
(segv_handler) [!USE_LIBSIGSEGV]: Do not trust si_addr
if BOGUS_SI_ADDR_UPON_STACK_OVERFLOW.
* m4/c-stack.m4 (AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC):
Define BOGUS_SI_ADDR_UPON_STACK_OVERFLOW on Solaris 2.11 SPARC.
And do not define HAVE_XSI_STACK_OVERFLOW_HEURISTIC.
Bruno Haible [Fri, 14 May 2021 21:32:08 +0000 (23:32 +0200)]
linked-list-unportable-test: New module.
* modules/linked-list-unportable-tests: New file, based on
modules/linked-list-tests.
* modules/linked-list-tests: Remove the unportable tests from here.
Depend on linked-list-unportable-tests.
Simon Josefsson [Fri, 14 May 2021 17:23:23 +0000 (19:23 +0200)]
valgrind-tests: Doc fix and introduce AM_VALGRINDFLAGS.
* doc/valgrind-tests.texi (Using valgrind automatically): Clarify
when the parallel vs serial test harness is used, suggested by
Bruno Haible <bruno@clisp.org>.
* m4/valgrind-tests.m4: Add VALGRIND_PROGRAM and AM_VALGRINDFLAGS.
Simon Josefsson [Fri, 14 May 2021 12:17:20 +0000 (14:17 +0200)]
valgrind-tests: Better option handling.
* m4/valgrind-tests.m4: Support new variables VALGRINDFLAGS and
DEFAULT_VALGRINDFLAGS.
* doc/valgrind-tests.texi (Running self-tests under valgrind): Improve.
Bruno Haible [Thu, 13 May 2021 19:33:55 +0000 (21:33 +0200)]
getrandom: Produce a better error code.
Reported by Paul Eggert in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-05/msg00025.html>.
* lib/getrandom.c (getrandom): When open() fails with an error that does
not indicate the absence of the file, fail with that error code, not
with ENOSYS.
Bruno Haible [Thu, 13 May 2021 13:48:38 +0000 (15:48 +0200)]
posix_spawn, posix_spawnp: Fix build error on Minix 3.3.
* m4/posix_spawn.m4 (gl_POSIX_SPAWN_BODY): If posix_spawn does not exist
but is declared, set REPLACE_POSIX_SPAWN.
* doc/posix-functions/posix_spawn.texi: Update platforms list.
* doc/posix-functions/posix_spawnp.texi: Likewise.
* m4/realloc.m4 (gl_FUNC_REALLOC_POSIX): Don't reset REPLACE_REALLOC
to 0 if it is already 1 after gl_FUNC_REALLOC_GNU was executed.
* m4/calloc.m4 (gl_FUNC_CALLOC_POSIX): Don't reset REPLACE_CALLOC
to 0 if it is already 1 after gl_FUNC_CALLOC_GNU was executed.
* m4/malloc.m4 (gl_FUNC_MALLOC_GNU): Don't assume that
_AC_FUNC_MALLOC_IF expands to a single shell statement.
* m4/realloc.m4 (gl_FUNC_REALLOC_GNU): Don't assume that
_AC_FUNC_REALLOC_IF expands to a single shell statement.
* m4/calloc.m4 (gl_FUNC_CALLOC_GNU): Don't assume that
_AC_FUNC_CALLOC_IF expands to a single shell statement.
Bruno Haible [Sun, 9 May 2021 16:34:58 +0000 (18:34 +0200)]
malloc-gnu, realloc-gnu, calloc-gnu tests: Verify errno is set.
* tests/test-malloc-gnu.c: Include <errno.h>.
(main): Verify that, when an allocation larger than PTRDIFF_MAX failed,
errno is ENOMEM.
* tests/test-realloc-gnu.c: Likewise.
* tests/test-calloc-gnu.c: Likewise.
Bruno Haible [Sun, 9 May 2021 02:19:48 +0000 (04:19 +0200)]
Fix build error when libintl is installed.
* modules/posix_spawn_file_actions_addchdir-tests (Makefile.am): Link
test-posix_spawn-chdir with libintl.
* modules/posix_spawn_file_actions_addfchdir-tests (Makefile.am): Link
test-posix_spawn-fchdir with libintl.
Bruno Haible [Fri, 7 May 2021 10:51:47 +0000 (12:51 +0200)]
Fix build when an older libunistring is installed (regr. 2020-02-23).
* modules/unitypes (configure.ac): Arrange to generate the .h file if
the installed one is from a version < 0.9.11.
* modules/unicase/base (configure.ac): Likewise.
* modules/uniconv/base (configure.ac): Likewise.
* modules/unilbrk/base (configure.ac): Likewise.
* modules/uninorm/base (configure.ac): Likewise.
* modules/unistdio/base (configure.ac): Likewise.
* modules/unistr/base (configure.ac): Likewise.
* modules/uniwbrk/base (configure.ac): Likewise.
* modules/uniwidth/base (configure.ac): Likewise.
* modules/unictype/base (configure.ac): Arrange to generate the .h file
if the installed one is from a version < 0.9.8.
* modules/unigbrk/base (configure.ac): Likewise.
Paul Eggert [Tue, 27 Apr 2021 18:23:28 +0000 (11:23 -0700)]
libc-config: fix include problem on older Debian
https://lists.gnu.org/r/bug-gnulib/2021-04/msg00198.html
* lib/cdefs.h: Use __GNULIB_CDEFS, not __GLIBC__,
to determine whether to include the bits/* files.
* lib/libc-config.h (__WORDSIZE): Remove.
(__GNULIB_CDEFS): New macro.
Paul Eggert [Tue, 27 Apr 2021 06:31:29 +0000 (23:31 -0700)]
gnulib-tool: port better to current Autoconf
* doc/gnulib-tool.texi (Initial import): Don’t mention
AC_PROG_CC_STDC as it’s deprecated in current Autoconf.
* gnulib-tool (func_done_dir): Suggest replacing
AC_PROG_CC_STDC and AC_PROG_CC_C99, as per current Autoconf.
Paul Eggert [Mon, 26 Apr 2021 06:11:15 +0000 (23:11 -0700)]
reallocarray: a bit more tuning
* lib/reallocarray.c: Include intprops.h.
(reallocarray): Use INT_MULTIPLY_WRAPV instead of
xalloc_oversized, as it now suffices and is likely a bit more
efficient (five fewer machine insns on Ubuntu 20.10 x86-64).
* modules/reallocarray (Depends-on): Depend on intprops, not
xalloc-oversized. Use conditional dependencies to avoid building
realloc-gnu when not needed.
Paul Eggert [Mon, 26 Apr 2021 01:24:42 +0000 (18:24 -0700)]
reallocarray: don’t crash if item size is 0
This problem affects only platforms where xalloc_oversized
divides a number by the size arg. Fix this by defining
xalloc_oversized (n, s) to work even if s == 0.
* lib/malloca.h, lib/xalloc-oversized.h: Document new behavior.
* lib/xalloc-oversized.h (__xalloc_oversized): Do not crash if S==0.
* tests/test-reallocarray.c (main): Test for the bug.
Paul Eggert [Sun, 25 Apr 2021 01:13:40 +0000 (18:13 -0700)]
xmalloca, etc.: avoid unlikely trap
* lib/xmalloca.h (xnmalloca):
Use size_t, not ptrdiff_t, to avoid implementation-defined
behavior (which could include a trap) if N is 0 and S exceeds
PTRDIFF_MAX.
* lib/xalloc-oversized.h: Adjust comment to match.
Paul Eggert [Sun, 25 Apr 2021 00:59:53 +0000 (17:59 -0700)]
xmalloca, etc.: fix some xalloc-oversized issues
* lib/malloca.h (nmalloca):
* lib/xmalloca.h (xnmalloca): Convert S to ptrdiff_t to avoid
arithmetic overflow if N and S are both narrower than ptrdiff_t.
* lib/xalloc-oversized.h (xalloc_oversized):
Don’t say that args must be ptrdiff_t or size_t or wider.
The macro returns the correct answer even when that is not
the case, and it’s the caller’s responsibility to avoid
howlers like (xalloc_oversized (n, s) ? NULL : malloc (n * s))
when N and S are both narrower than ptrdiff_t and size_t.
Add a comment to that effect.
* lib/xmalloca.h: Include xalloc-oversized.h, since this file uses
xalloc_oversized. Add comments about side effects and avoid
unnecessary parens.
* modules/xmalloca (Depends-on): Add xalloc-oversized.
Paul Eggert [Sat, 24 Apr 2021 17:12:15 +0000 (10:12 -0700)]
calloc-gnu-tests: add overflow tests
* tests/test-calloc-gnu.c (identity): New function, replacing ‘eight’.
(main): Do 2 * log2(SIZE_MAX) tests instead of just two tests.
Don’t bother to free on failure.
Paul Eggert [Thu, 22 Apr 2021 19:29:49 +0000 (12:29 -0700)]
libc-config: port better to Fedora Rawhide
Problem reported by Eric Blake in:
https://lists.gnu.org/r/bug-gnulib/2021-04/msg00181.html
* lib/cdefs.h: Make this closer to glibc, so that we can
merge Gnulib into glibc here.
(__attribute_maybe_unused__): Make identical to glibc’s
definition, though with an additional comment.
(__attribute_nonnull__): Add clarifying comment.
Make inclusion of bits/wordsize.h, bits/long-double.h
dependent on __GLIBC__, not on !__WORDSIZE.
* lib/libc-config.h: Use __attribute_nonnull__,
not __attribute_maybe_unused__, to detect whether
to include sys/cdefs.h.
Paul Eggert [Wed, 21 Apr 2021 18:09:01 +0000 (11:09 -0700)]
malloc: simplify
* lib/malloc.c: Omit unnecessary "#undef malloc".
I recently introduced it by mistake. This module defines
_GL_USE_STDLIB_ALLOC and so malloc isn’t redefined to rpl_malloc.
Paul Eggert [Wed, 21 Apr 2021 18:07:18 +0000 (11:07 -0700)]
malloca: avoid ptrdiff_t overflow
* lib/malloca.c: Include idx.h, intprops.h.
(mmalloca): Check for ptrdiff_t overflow. Since this module uses
_GL_USE_STDLIB_ALLOC, it cannot assume GNU malloc semantics.
* modules/malloca (Depends-on): Add idx, intprops.
Paul Eggert [Wed, 21 Apr 2021 17:13:50 +0000 (10:13 -0700)]
execute-tests: pacify compiler
* tests/test-execute-main.c (main): Use 0x7DEADBEE rather than
0xDEADBEEF for nonces, to avoid provoking AIX XLC compiler warning
that the latter is out of int range.
Paul Eggert [Wed, 21 Apr 2021 00:11:51 +0000 (17:11 -0700)]
malloc-gnu-tests, etc.: use volatile for clang
In some more test locations, store the result of malloc etc. into
a volatile pointer so that clang doesn’t optimize away the malloc
and thus bypass the test. This fixes a malloc-gnu test failure on
macOS 11.2.3 with clang 12.0.0 on ARM.
* tests/test-alloca-opt.c (do_allocation):
* tests/test-malloc-gnu.c (main):
* tests/test-malloca.c (do_allocation):
* tests/test-realloc-gnu.c (main):
* tests/test-reallocarray.c (main):
* tests/test-aligned-malloc.c (main):
* tests/test-aligned_alloc.c (main):
Store malloc etc. results into a volatile pointer.
Paul Eggert [Mon, 19 Apr 2021 03:50:55 +0000 (20:50 -0700)]
safe-alloc: fix pointer implementation
The old implementation assumed that all pointers use the same
internal representation, but the C standard doesn’t guarantee
this. Use void * (pointer) not void ** (pointer-to-pointer) for
the internal functions’ API. The internal functions now return
NULL if and only if they failed, and the macros translate that
into -1 or 0 to satisfy the existing API.
* doc/safe-alloc.texi (Safe Allocation Macros): Mention overflow.
* lib/safe-alloc.c: Major rewrite. Now this simply
defines SAFE_ALLOC_INLINE and includes safe-alloc.h.
* lib/safe-alloc.h: Include stddef.h, not stdlib.h.
(SAFE_ALLOC_INLINE): New macro; use Gnulib inline function style.
(safe_alloc_realloc_n): New API, which passes and returns
the pointer, and which returns NULL if and only if failure occurs.
(safe_alloc_check): New function.
(ALLOC, ALLOC_N, ALLOC_N_UNINITIALIZED, REALLOC_N):
Redo using the new API for internal functions, and using calloc
which is good enough since it’s GNU-compatible now.
(FREE): Expand to an expression rather than merely to something
that needs a following ‘;’ to become a statement.
* modules/safe-alloc (Depends-on): Add calloc-gnu.
Paul Eggert [Mon, 19 Apr 2021 03:52:29 +0000 (20:52 -0700)]
calloc-gnu: now LGPLv2+
* modules/calloc-gnu (License): Change from GPL to LGPLv2+.
The old value was evidently a longstanding typo, and calloc
will be needed by LGPLv2+ modules that will want to rely
on GNU behavior.
Paul Eggert [Sun, 18 Apr 2021 23:53:11 +0000 (16:53 -0700)]
safe-alloc: simplify via reallocarray
* lib/safe-alloc.c: Do not include xalloc-oversized.h.
(safe_alloc_alloc_n, safe_alloc_realloc_n):
Use reallocarray to check for size or ptrdiff_t overflow.
* modules/reallocarray (License): Switch from LGPL to LGPLv2+, as
this is needed for safe-alloc and anyway is more appropriate for
this library function common with BSD.
* modules/safe-alloc (Depends-on): Depend on reallocarray
rather than xalloc-oversized.
Paul Eggert [Sun, 18 Apr 2021 23:30:59 +0000 (16:30 -0700)]
xalloc-oversized: fix SIZE_MAX optimization bug
* lib/xalloc-oversized.h (xalloc_count_t): Remove; no longer
needed and was evidently error-prone anyway.
(xalloc_oversized): Omit some over-optimization that caused
SIZE_MAX to not be treated as too large (the Gnulib convention) on
unusual platforms where PTRDIFF_MAX == SIZE_MAX. This change
should not affect typical platforms where PTRDIFF_MAX < SIZE_MAX.
When optimizing, simply use ptrdiff_t instead of xalloc_count_t.
Paul Eggert [Sun, 18 Apr 2021 23:24:51 +0000 (16:24 -0700)]
xalloc: new function xreallocarray
This effectively replaces xnmalloc, which perhaps should be deprecated.
The name xreallocarray should be easier to remember now that
reallocarray is a standard GNU function.
* lib/xalloc.h [GNULIB_XALLOC]: Do not include xalloc-oversized.h.
(xnmalloc, xnrealloc, x2nrealloc): Simplify by using xreallocarray.
* lib/xmalloc.c (xreallocarray): New function.
* modules/xalloc (Depends-on): Add reallocarray;
remove xalloc-oversized.
Paul Eggert [Sun, 18 Apr 2021 23:05:30 +0000 (16:05 -0700)]
backupfile: simplify via realloc-gnu
* lib/backupfile.c: Do not include xalloc-oversized.h.
(numbered_backup): Simplify now that realloc will do the right
thing about ptrdiff_t overflow.
* modules/backupfile (Depends-on): Add realloc-gnu;
remove xalloc-oversized.