Paul Eggert [Sun, 4 Apr 2021 03:14:36 +0000 (20:14 -0700)]
savedir: avoid unlikely undefined behavior
* lib/savedir.c (streamsavedir): Prefer idx_to size_t where
either will do. Simplify reallocation of entries.
Use xpalloc to reallocate name_space, to avoid some unlikely
integer overflows.
Paul Eggert [Sun, 4 Apr 2021 02:59:10 +0000 (19:59 -0700)]
quotearg: avoid undefined and/or O(N**2)
Avoid undefined and O(N**2) behavior in some very unlikely cases.
* lib/quotearg.c (quotearg_n_options): Document that N must
be less than MIN (INT_MAX, IDX_MAX), and add this to the
abort test; this also avoids a conditional branch.
Use xpalloc instead of xrealloc, to avoid O(N**2) behavior in
very-unlikely cases.
Paul Eggert [Sat, 3 Apr 2021 23:07:21 +0000 (16:07 -0700)]
xgethostname: reorganize / simplify
xgethostname and xgetdomainname were essentially copies long
ago, but they’ve diverged. Bring them back together again
by implementing the (rarely used) latter in terms of the former.
And avoid some unnecessary realloc calls while we’re at it.
* lib/xgetdomainname.c: Rewrite from scratch so that it merely
includes xgethostname.c with a few preliminaries.
* lib/xgethostname.c: Generalize so that it can be included
from xgetdomainname.c.
(GETANAME, XGETANAME): New macros.
(INITIAL_HOSTNAME_LENGTH): Remove. No need for this parameter.
Use 100 instead, as few hostnames are longer than that.
(XGETANAME): Try getting the hostname into the stack first,
as that avoids a malloc call in the usual case.
Check for both POSIX-style truncation and SunOS 5.5 bug
in a cleaner way, by simply checking string length.
Don’t use x2realloc, which wastes time preserving buffer garbage;
use xpalloc with NULL instead. Don’t bother shrinking buffer
in the very rare case where the hostname is longer than sizeof
buf; it’s not worth the aggravation.
* modules/xgetdomainname (Depends-on): Remove free-posix, xalloc.
Add xgethostname.
Bruno Haible [Sat, 3 Apr 2021 15:41:18 +0000 (17:41 +0200)]
xalloc-die: Fix compilation error (regression from 2021-03-28).
* lib/xalloc.h: Don't include idx.h and xalloc-oversized.h if the module
'xalloc' is not in use.
* modules/xalloc-die (Depends-on): Remove xalloc-oversized.
Bruno Haible [Fri, 2 Apr 2021 17:50:19 +0000 (19:50 +0200)]
strtol, strtoul, strtoll, strtoull: Optimize.
* lib/strtol.c (GROUP_PARAM_PROTO): New macro.
(INTERNAL): Define differently if !USE_NUMBER_GROUPING.
(INTERNAL (strtol)): Define without 'int group' parameter if
!USE_NUMBER_GROUPING.
(strtol): Don't define if !USE_NUMBER_GROUPING.
Paul Eggert [Thu, 1 Apr 2021 07:59:54 +0000 (00:59 -0700)]
xalloc: delay setting size until success
* lib/xalloc.h (x2nrealloc): Don’t change *PN until after xrealloc
succeeds, in case xalloc_die or one of its callees or longjmp
targets uses *PN. Similar code in xpalloc already does this.
Paul Eggert [Mon, 29 Mar 2021 03:02:21 +0000 (20:02 -0700)]
xalloc: new function xpalloc, from dfa
Move xpalloc from dfa.c to xmalloc.c and change it from static to
extern. The function is useful in other contexts; I’m about to
use it in coreutils.
* lib/dfa.c: Include idx.h, instead of rolling our own idx_t and
IDX_MAX. Do not include intprops.h; no longer needed.
(xpalloc): Move from here ...
* lib/xmalloc.c (xpalloc): ... to here, and make it extern.
Include intprops.h and minmax.h, needed by xpalloc.
* lib/xalloc.h: Include idx.h, for idx_t.
* modules/dfa (Depends-on): Add idx; remove intprops.
* modules/xalloc (Depends-on): Add idx, intprops, minmax.
Bruno Haible [Sun, 28 Mar 2021 18:10:43 +0000 (20:10 +0200)]
linked-list tests: Add another test for SIGNAL_SAFE_LIST.
* tests/test-asyncsafe-linked_list-strong.c: Renamed from
tests/test-asyncsafe-linked_list.c.
* tests/test-asyncsafe-linked_list-strong.sh: Renamed from
tests/test-asyncsafe-linked_list.sh.
* tests/test-asyncsafe-linked_list-weak.c: New file, based on
tests/test-asyncsafe-linked_list.c.
* tests/test-asyncsafe-linked_list-weak.sh: New file, based on
tests/test-asyncsafe-linked_list.sh.
* modules/linked-list-tests (Files): Add
tests/test-asyncsafe-linked_list-weak.*,
tests/test-asyncsafe-linked_list-strong.*.
(Makefile.am): Arrange to test also
tests/test-asyncsafe-linked_list-weak.sh. Mark
test-asyncsafe-linked_list-weak.sh and
test-asyncsafe-linked_list-strong.sh as expected failures.
Bruno Haible [Mon, 22 Mar 2021 23:08:38 +0000 (00:08 +0100)]
clean-temp-simple: Remove dependency upon xalloc, xalloc-die, xlist.
* lib/clean-temp-private.h (clean_temp_init): Change return type to
'int'.
* lib/clean-temp-simple.h (register_temporary_file): Change return type
to 'int'.
* lib/clean-temp-simple.c: Don't include xalloc.h, gl_xlist.h. Include
gl_list.h instead.
(init_failed): New variable.
(do_clean_temp_init): Set it.
(clean_temp_init): Return an error indicator.
(register_temporary_file): Invoke gl_list_nx_create_empty instead of
gl_list_create_empty. Invoke strdup instead of xstrdup. Invoke
gl_list_nx_add_first instead of gl_list_add_first. Return an error
indicator.
* lib/clean-temp.c (create_temp_dir, gen_register_open_temp): Call
xalloc_die() if clean_temp_init or register_temporary_file failed.
* modules/clean-temp-simple (Depends-on): Remove xalloc, xalloc-die,
xlist.
Bruno Haible [Mon, 22 Mar 2021 21:48:23 +0000 (22:48 +0100)]
clean-temp-simple: New module.
* lib/clean-temp-simple.h: New file, based on lib/clean-temp.h.
* lib/clean-temp-private.h: New file, based on lib/clean-temp.c.
* lib/clean-temp-simple.c: New file, based on lib/clean-temp.c.
* lib/clean-temp.h: Include clean-temp-simple.h.
(register_temporary_file, unregister_temporary_file,
cleanup_temporary_file): Remove declarations.
* lib/clean-temp.c: Don't include <limits.h>, <stdint.h>. Include
<signal.h>, <stdio.h>, clean-temp-simple.h, clean-temp-private.h.
(file_cleanup_list_lock, file_cleanup_list): Moved to
clean-temp-simple.c.
(struct tempdir, dir_cleanup_list, struct closeable_fd, descriptors):
Moved to clean-temp-private.h.
(string_equals, SIZE_BITS, string_hash, fatal_signal_set,
init_fatal_signal_set, asyncsafe_close): Moved to clean-temp-simple.c.
(asyncsafe_fclose_variant): Use get_fatal_signal_set() here.
(cleanup_action, do_init_clean_temp, clean_temp_once, init_clean_temp,
register_temporary_file, unregister_temporary_file, do_unlink,
cleanup_temporary_file): Moved to clean-temp-simple.c.
(create_temp_dir, cleanup_temp_file, cleanup_temp_dir_contents,
gen_register_open_temp, close_temp): Update for changed function names.
(fclose_variant_temp): Don't call init_fatal_signal_set().
* modules/clean-temp-simple: New file, based on modules/clean-temp.
* modules/clean-temp (Depends-on): Add clean-temp-simple, list. Remove
stdint.
(configure.ac): Don't define SIGNAL_SAFE_LIST here.
Bruno Haible [Mon, 22 Mar 2021 17:28:02 +0000 (18:28 +0100)]
error: Relicense under LGPLv2+.
Pino Toscano's approval is in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-03/msg00109.html>.
Paul Eggert's approval is in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-03/msg00110.html>.
Bruno Haible [Mon, 22 Mar 2021 17:25:09 +0000 (18:25 +0100)]
getprogname: Relicense under LGPLv2+.
Pino Toscano's approval is in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-03/msg00109.html>.
Paul Eggert's approval is in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-03/msg00110.html>.
Jim Meyering's approval is in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-03/msg00107.html>.
Gisle Vanem's approval is in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-03/msg00115.html>.
Daniel Richard G's approval is in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-03/msg00112.html>.
John David Anglin's approval is in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-03/msg00108.html>.
Benji Wiebe's approval is in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-03/msg00114.html>.
* modules/getprogname (License): Change to LGPLv2+.
Bruno Haible [Mon, 22 Mar 2021 12:47:44 +0000 (13:47 +0100)]
doc: Mention an open glibc bug.
* doc/posix-functions/mbrtowc.texi: Mention the possible out-of-range
wchar_t values returned by this function on glibc.
* doc/posix-functions/mbtowc.texi: Likewise.
Paul Eggert [Sun, 21 Mar 2021 21:52:08 +0000 (14:52 -0700)]
tests: fix signed overflow issues
* tests/test-dynarray.c (value_at): Avoid undefined behavior
in signed integer multiplication.
* tests/test-scratch-buffer.c (byte_at): Likewise, for the
theoretically-possible case where size_t is narrower than int.
Bruno Haible [Sun, 21 Mar 2021 02:46:05 +0000 (03:46 +0100)]
ftello: Work around bug in macOS >= 10.15.
Reported by Martin Storsjö <martin@martin.st> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00002.html>.
* m4/ungetc.m4 (gl_FUNC_UNGETC_WORKS): On macOS, don't define
FUNC_UNGETC_BROKEN. Instead, set gl_ftello_broken_after_ungetc to yes.
* m4/ftello.m4 (gl_FUNC_FTELLO): Invoke gl_FUNC_UNGETC_WORKS, and
arrange to provide the workaround if ftello is broken after ungetc.
* lib/ftello.c: Include <errno.h>, intprops.h.
(ftello) [FTELLO_BROKEN_AFTER_UNGETC]: Implement from scratch.
* modules/ftello (Files): Add m4/ungetc.m4.
(Depends-on): Add intprops.
* doc/posix-functions/ftello.texi: Mention the macOS bug.
Paul Eggert [Thu, 18 Mar 2021 18:00:53 +0000 (11:00 -0700)]
argmatch: fix testing typo
Problem and fix reported by Gisle Vanem in:
https://lists.gnu.org/r/bug-gnulib/2021-03/msg00083.html
* lib/argmatch.c (main) [TEST]: Fix address-of typo.
Paul Eggert [Wed, 10 Mar 2021 23:04:55 +0000 (15:04 -0800)]
libc-config: port to DragonFlyBSD 5.9
DragonFlyBSD defines __nonnull incompatibly with glibc,
so avoid the use of __nonnull in Gnulib code.
Problem reported by Gavin Smith in:
https://lists.gnu.org/r/bug-gnulib/2021-03/msg00066.html
* lib/cdefs.h (__attribute_nonnull__): Rename from __nonnull.
All uses in Gnulib changed. There should be no need to change
glibc code that is not shared with Gnulib.
(__nonnull): New macro, defined in terms of __attribute_nonnull__,
and which can be used in glibc code that is not shared with Gnulib.
Paul Eggert [Sun, 7 Mar 2021 21:47:02 +0000 (13:47 -0800)]
manywarnings: modernize documentation
Problem reported by Reuben Thomas in:
https://lists.gnu.org/r/bug-gnulib/2021-03/msg00046.html
* doc/manywarnings.texi (manywarnings): Update in
the light of recent changes to the manywarnings module.
Bruno Haible [Sun, 7 Mar 2021 00:58:10 +0000 (01:58 +0100)]
unlocked-io-internal: New module.
* m4/unlocked-io.m4 (gl_FUNC_GLIBC_UNLOCKED_IO): Don't define
USE_UNLOCKED_IO here.
* modules/unlocked-io-internal: New file, based on modules/unlocked-io.
* modules/unlocked-io (Description): Clarify.
(Files, Depends-on): Just use the unlocked-io-internal module.
(configure.ac): Define GNULIB_STDIO_SINGLE_THREAD and USE_UNLOCKED_IO
here.
* doc/multithread.texi: Clarify when the 'unlocked-io' module can be
used.
Bruno Haible [Sat, 6 Mar 2021 23:40:27 +0000 (00:40 +0100)]
dynarray: Make the module usable on its own.
* lib/dynarray.h: Document the exported API. Comments taken from
lib/malloc/dynarray-skeleton.c and lib/malloc/dynarray.h.
Distinguish an internal include from an include for instantiation.
In the latter case, include <libc-config.h> and
<malloc/dynarray-skeleton.c>.
* modules/dynarray (Depends-on): Add intprops.
(Include): Reduce to just "dynarray.h".
Paul Eggert [Sat, 6 Mar 2021 16:23:48 +0000 (08:23 -0800)]
parse-datetime2: fix licensing
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2021-03/msg00017.html
* gnulib-tool (func_get_license): Treat parse-datetime2
(actually, anything starting with "parse-datetime")
like parse-datetime, as far as licenses go.
Paul Eggert [Thu, 4 Mar 2021 08:47:19 +0000 (00:47 -0800)]
stdalign: port to tcc + glibc
* lib/stdalign.in.h (_Alignas): Do not define using __attribute__
if __attribute__ is defined as a macro, as __attribute__ surely a
no-op in that case and this is an area where __attribute__ cannot
simply be ignored.
* m4/stdalign.m4 (gl_STDALIGN_H): Include <stdint.h> so that
it #defines __attribute__(x) to nothing on glibc-based systems
when non-GNU-C-compatible compilers are used.
This exposes a bug in Tiny C Compiler 0.9.27’s implementation
of _Alignas on glibc platforms.
Bruno Haible [Wed, 3 Mar 2021 02:56:50 +0000 (03:56 +0100)]
stddef: Work around an interoperability problem of tcc with glibc.
Reported by Luca Saiu <positron@gnu.org> in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-03/msg00011.html>.
* lib/stddef.in.h [__TINYC__]: In case of the special invocation
convention, undefine the macros that TinyCC's <stddef.h> should undefine
but doesn't.
* doc/posix-headers/stddef.texi: Mention the TinyCC bug.
Paul Eggert [Wed, 3 Mar 2021 00:27:39 +0000 (16:27 -0800)]
mbrtowc: port to AIX 7.1 with xlc 12.1
Fix a problem with locks when building GNU Tar (Savannah commit 55f2a0772e08b9febac3ac0de5cb048d4c60d2f5) on AIX 7.1 with IBM XL
C/C++ V12.1 using ‘./configure CC=xlc’. The link fails due to
missing definitions of pthread_mutex_lock and
pthread_mutex_unlock. GNU Tar uses unlocked-io and so
should not need to worry about multithreading or locks.
* lib/mbtowc-lock.h (mbtowc_with_lock) [USE_UNLOCKED_IO]:
Don’t bother with locks, since this app is single-threaded.
There may be similar linking problems with lib/nl_langinfo.c and
lib/setlocale_null.c but my GNU Tar build didn’t run into them, so
I left them alone for now.
Paul Eggert [Mon, 1 Mar 2021 08:27:25 +0000 (00:27 -0800)]
unlocked-io: do not redefine getc_unlocked etc.
I ran into this problem on AIX 7.1 with GNU Tar, which
enables visibility of getc_unlocked etc. after testing
whether they’re declared, causing argp-namefrob.h and
unlocked-io.h to redefine the macros.
* lib/argp-namefrob.h, lib/unlocked-io.h:
(clearerr_unlocked, feof_unlocked ferror_unlocked)
(fflush_unlocked, fgets_unlocked, fputc_unlocked, fputs_unlocked)
(fread_unlocked, fwrite_unlocked, getc_unlocked, getchar_unlocked)
(putc_unlocked, putchar_unlocked): Do not define if already defined.
Paul Eggert [Mon, 1 Mar 2021 08:24:05 +0000 (00:24 -0800)]
parse-datetime2: new module
This splits the old parse-datetime into two parts; the
first is parse-datetime2 which supports all the new bells
and whistles, the second is parse-datetime, which reverts to
its original intent. This avoids some bogus diagnostics
when build GNU Tar with gcc -flto -fanalyze and
with --enable-gcc-warnings. And it slims down the
executable a bit.
* NEWS: Mention this.
* lib/parse-datetime.y (parser_control) [!GNULIB_PARSE_DATETIME2]:
Omit parse_datetime_debug member.
(debugging): New function. Use it everywhere the old code
would load parse_datetime_debug.
(parse_datetime_body): New static function, with the body
of the old parse_datetime2. Set pc.parse_datetime_debug
only if GNULIB_PARSE_DATETIME2.
(parse_datetime2, parse_datetime): Use this new function.
(parse_datetime2) [!GNULIB_PARSE_DATETIME2]: Remove.
Paul Eggert [Wed, 24 Feb 2021 18:52:59 +0000 (10:52 -0800)]
glob: include libc-config.h in a more-standard way
Inspired by Tom Tromey’s report for RHEL 6 in:
https://lists.gnu.org/r/bug-gnulib/2021-02/msg00088.html
* lib/glob.c [!_LIBC]: Include libc-config.h, not just config.h
Bruno Haible [Sun, 21 Feb 2021 20:39:07 +0000 (21:39 +0100)]
string-buffer: New module.
* lib/string-buffer.h: New file.
* lib/string-buffer.c: New file.
* modules/string-buffer: New file.
* doc/posix-functions/open_memstream.texi: Mention the new module.
Bruno Haible [Sun, 21 Feb 2021 18:21:42 +0000 (19:21 +0100)]
DEPENDENCIES: Update.
* DEPENDENCIES: Require GCC >= 3.1. Tell where to find working GNU m4
tarballs. Mention awk. Point to pre-built packages for gettext, bison,
gperf, texinfo.
Paul Eggert [Tue, 16 Feb 2021 19:41:19 +0000 (11:41 -0800)]
Port better to macOS Mojave
Problem reported by Tom Shields in:
https://lists.gnu.org/r/bug-gnulib/2021-02/msg00064.html
* config/srclist.txt: Comment out dynarray_finalize.c.
* lib/dynarray.h (__libc_dynarray_at_failure): Don’t include
libc-config.h here, as that’s the includer’s responsibility.
* lib/malloc/dynarray_at_failure.c:
* lib/malloc/dynarray_emplace_enlarge.c:
* lib/malloc/dynarray_finalize.c:
* lib/malloc/dynarray_resize.c:
* lib/malloc/dynarray_resize_clear.c:
If _LIBC is not defined, include libc-config.h.