Bruno Haible [Tue, 8 Dec 2020 20:28:18 +0000 (21:28 +0100)]
argp: Avoid undefined behaviour when invoking qsort().
This fixes a test-argp-2.sh test failure on macOS and FreeBSD.
Reported by Jeffrey Walton <noloader@gmail.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-03/msg00085.html>.
* lib/argp-help.c (group_cmp): Remove third argument.
(hol_sibling_cluster_cmp, hol_cousin_cluster_cmp): New functions, based
upon hol_cluster_cmp.
(hol_cluster_cmp): Use hol_cousin_cluster_cmp.
(hol_entry_cmp): Rewritten to implement a total order.
Bruno Haible [Mon, 7 Dec 2020 18:43:06 +0000 (19:43 +0100)]
get-rusage-data: Fix link error on FreeBSD 12.2/arm64.
* modules/get-rusage-data (configure.ac): Test whether sbrk exists.
* lib/get-rusage-data.c (get_rusage_data_via_setrlimit): Define
trivially of sbrk is not available.
* doc/glibc-functions/sbrk.texi: Mention that the function does not
exist in FreeBSD 12.2/arm64.
* doc/glibc-functions/brk.texi: Likewise.
Paul Eggert [Sun, 6 Dec 2020 18:17:39 +0000 (10:17 -0800)]
doc: fix flat address space discussion
* doc/gnulib-readme.texi (Other portability assumptions):
Move the all-bits-zero assumption outside the flat address space
section, since the two issues are independent.
Bruno Haible [Sun, 6 Dec 2020 14:51:41 +0000 (15:51 +0100)]
doc: Mention some missing function declarations.
* doc/glibc-functions/execvpe.texi: Mention the missing declaration on
AIX.
* doc/glibc-functions/fcloseall.texi: Mention the missing declaration on
FreeBSD.
* doc/pastposix-functions/ecvt.texi: Mention the missing declaration on
Cygwin.
* doc/pastposix-functions/fcvt.texi: Likewise.
* doc/pastposix-functions/gcvt.texi: Likewise.
Bruno Haible [Sun, 6 Dec 2020 11:31:11 +0000 (12:31 +0100)]
parse-datetime: Use idx_t for nonnegative ptrdiff_t variables.
* lib/parse-datetime.y: Include idx.h.
(textint): Mark digits as nonnegative.
(parser_control): Mark dates_seen, days_seen, local_zones_seen,
dsts_seen, times_seen, zones_seen as nonnegative.
(lookup_word): Mark wordlen as nonnegative.
(yylex): Mark count as nonnegative.
(parse_datetime2): Mark tzsize as nonnegative.
* modules/parse-datetime (Depends-on): Add idx.
Paul Eggert [Sun, 6 Dec 2020 01:33:29 +0000 (17:33 -0800)]
doc: fix curved quotes issue
* doc/gnulib.texi: Set txicodequoteundirected and
txicodequotebacktick so that ` and ' in examples do not generate
curved single quotes that do the wrong thing when cut and pasted.
Paul Eggert [Sat, 5 Dec 2020 23:54:22 +0000 (15:54 -0800)]
intprops: Add INT_ADD_OK etc.
* doc/intprops.texi (Checking Integer Overflow): New section.
* lib/intprops.h: From a suggestion by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2020-12/msg00051.html
(SAFE_INT_ADD, SAFE_INT_SUBTRACT, SAFE_INT_MULTIPLY): New macros.
Paul Eggert [Sat, 5 Dec 2020 21:10:28 +0000 (13:10 -0800)]
doc: move exotic platfroms to Target Platforms
* doc/gnulib-intro.texi (Supported Platforms)
(Formerly Supported Platforms, Unsupported Platforms):
New subsections, split off from Target Platforms.
(Unsupported Platforms): Move the exotic-platform stuff here ...
* doc/gnulib-readme.texi (Exotic platforms): ... from this removed
section.
Paul Eggert [Sat, 5 Dec 2020 19:27:13 +0000 (11:27 -0800)]
doc: mention intptr_t etc. and IBM i
* doc/gnulib-readme.texi (Other portability assumptions):
Mention intptr_t and uintptr_t, and that arithmetic on them
works in the usual way.
(Exotic platforms): New section, containing material from
the old 'Integer Portability' section. Also mention IBM i.
* doc/intprops.texi (Wraparound Arithmetic):
Say that the macros work on unsigned integers too.
(Integer Portability): Remove.
Paul Eggert [Fri, 4 Dec 2020 18:44:51 +0000 (10:44 -0800)]
intprops: update doc and mention Unisys
* doc/gnulib-readme.texi (Other portability assumptions):
Also mention ptrdiff_t when talking about widths and overflow.
* doc/intprops.texi (Integer Properties): Summarize new section.
(Arithmetic Type Properties): Document that EXPR_SIGNED no longer
evaluates its argument.
(Integer Bounds): Fix typo.
(Wraparound Arithmetic): Remove obsolete comment about efficiency.
Document that the _WRAPV macros now support pointers to unsigned
integers.
(Integer Range Overflow): Update SEI CERT citation.
(Integer Portability): New subsection, which mentions
the oddball Unisys platforms as non-Gnulib targets.
Bruno Haible [Thu, 3 Dec 2020 20:00:35 +0000 (21:00 +0100)]
fprintf-posix-tests: Avoid a test failure on macOS 10.13.
Reported by Martin Storsjö <martin@martin.st> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00003.html>.
* tests/test-fprintf-posix3.c: Skip the test on macOS.
(main): Return a different exit code at each point. Allow 100 KB extra
memory consumption.
* tests/test-fprintf-posix3.sh: Update. Remove the "get_rusage_as()
doesn't work" diagnostic.
Paul Eggert [Wed, 2 Dec 2020 22:25:43 +0000 (14:25 -0800)]
canonicalize: refactor can_mode flag
* lib/canonicalize.c (MULTIPLE_BITS_SET): Remove, replacing with ...
(multiple_bits_set): ... this new static function. Uses changed.
(canonicalize_filename_mode): Refactor for clarity to avoid
modifying the CAN_MODE argument.
Paul Eggert [Wed, 2 Dec 2020 22:25:43 +0000 (14:25 -0800)]
canonicalize: prefer signed integer types
* lib/canonicalize.c: Include stddef.h, for ptrdiff_t.
(seen_triple, canonicalize_filename_mode): Prefer signed to
unsigned types where either will do, as they avoid some glitches
in comparisons and can trap on overflow when debugging.
Paul Eggert [Wed, 2 Dec 2020 22:25:42 +0000 (14:25 -0800)]
canonicalize: fix most of another EOVERFLOW issue
* lib/canonicalize.c (canonicalize_filename_mode):
Do not call stat if fewer than 20 symlinks have been traversed.
This avoids EOVERFLOW failure in the common case where there
are not that many symlinks, while continuing to catch loops
(or fail due to EOVERFLOW) in the unusual case when there
are many symlinks to traverse.
Paul Eggert [Wed, 2 Dec 2020 22:25:42 +0000 (14:25 -0800)]
canonicalize: do not assume symlinks have st_ino
* lib/canonicalize.c (canonicalize_filename_mode):
When checking for loops, use st_dev and st_ino from the parent
directory not from the symlink, as pre-2017 POSIX says these
members are not reliable for symlinks. Couple this with START
(the remaining file name to be resolved), not NAME (the whole file
name with START as its suffix).
* modules/canonicalize (Depends-on): Depend on stat, not lstat.
Paul Eggert [Wed, 2 Dec 2020 22:25:41 +0000 (14:25 -0800)]
canonicalize: fix EOVERFLOW bug
* lib/canonicalize.c (canonicalize_filename_mode):
When testing whether a directory entry is a symbolic link, or a
directory or other, do not use lstat or stat or
areadlink_with_size. Just use areadlink, as this suffices and it
avoids the EOVERFLOW problem that lstat and stat have.
* modules/canonicalize (Depends-on): Depend on areadlink instead
of areadlink-with-size and stat.
Paul Eggert [Wed, 2 Dec 2020 22:25:41 +0000 (14:25 -0800)]
canonicalize-lgpl: fix EOVERFLOW bug
* lib/canonicalize-lgpl.c: Do not include <sys/stat.h>.
(__realpath): Do not use lstat. Just use readlink, as this
suffices and it avoids the EOVERFLOW problem that lstat has.
* modules/canonicalize-lgpl (Depends-on): Remove lstat, sys_stat.
Bruno Haible [Tue, 1 Dec 2020 18:57:17 +0000 (19:57 +0100)]
vma-iter: Add support for macOS11/arm64.
Patch suggested by Hill Ma <maahiuzeon@gmail.com> in
<https://gitlab.com/gnu-clisp/clisp/-/issues/27>
and by Martin Storsjö <martin@martin.st> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00003.html>.
* lib/vma-iter.c (vma_iterate): On arm64, use 64-bit type definitions.
Akim Demaille [Sun, 29 Nov 2020 14:59:22 +0000 (15:59 +0100)]
bitset: style: use consistent names
* bitset/list.c (lbitset_list_reverse): Rename 'bcount' as 'bitcnt',
and 'boffset' as 'bitoff', for consistency with the other
implementations.
* bitset/table.c (tbitset_list_reverse): Likewise.
Bruno Haible [Sun, 29 Nov 2020 22:14:56 +0000 (23:14 +0100)]
spawn-pipe tests: Fix test failure with MSVC.
* tests/test-spawn-pipe-child.c: Include <stdint.h>.
(gl_msvc_invalid_parameter_handler): New function.
(main): Set a global invalid-parameter handler.
* modules/spawn-pipe-tests (Depends-on): Add msvc-inval, stdint.
Bruno Haible [Sun, 29 Nov 2020 20:13:33 +0000 (21:13 +0100)]
fcntl: Work around NetBSD bug with F_DUPFD_CLOEXEC.
* m4/fcntl.m4 (gl_FUNC_FCNTL): Test whether F_DUPFD_CLOEXEC actually
works.
* lib/fcntl.c (rpl_fcntl_DUPFD_CLOEXEC): On NetBSD, use the same
fallback implementation as on Haiku.
* tests/test-fcntl.c (main): Add a test whether F_DUPFD_CLOEXEC is
effective.
* doc/posix-functions/fcntl.texi: Mention the NetBSD bug.
Bruno Haible [Sun, 29 Nov 2020 17:37:33 +0000 (18:37 +0100)]
spawn-pipe: Fix build on OS/2 kLIBC (regression 2020-11-28).
* lib/os2-spawn.h: New file, based on lib/windows-spawn.h.
* lib/os2-spawn.c: New file, based on lib/windows-spawn.c.
* lib/spawn-pipe.c: On OS/2 kLIBC, include "os2-spawn.h".
* lib/windows-spawn.c: Remove modifications for kLIBC.
* modules/spawn-pipe (Files): Add the new files.
(configure.ac): Arrange to compile os2-spawn.c on OS/2.
* lib/stdio.in.h (_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD,
_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM): New macros.
(_GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD): Renamed from
_GL_ATTRIBUTE_FORMAT_PRINTF. Use _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD.
(_GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM): Use
_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM.
* modules/vasnprintf (Depends-on): Add stdio.
* lib/vasnprintf.h: Include <stdio.h>.
(asnprintf, vasnprintf): Use the standard printf format attribute.
* modules/xvasprintf (Depends-on): Add stdio.
* lib/xvasprintf.h: Include <stdio.h>.
(xasprintf, xvasprintf): Use the standard printf format attribute.
* modules/xprintf (Depends-on): List stdio first.
* lib/xprintf.h (xprintf, xvprintf): Use a printf format attribute that
depends on GNULIB_VPRINTF_POSIX.
(xfprintf, xvfprintf): Use a printf format attribute that depends on
GNULIB_VFPRINTF_POSIX.
* modules/c-vasnprintf (Depends-on): Add stdio.
* lib/c-vasnprintf.h: Include <stdio.h>.
(c_vasnprintf): Use the standard printf format attribute.
* modules/c-vasprintf (Depends-on): Add stdio.
* lib/c-vasprintf.h: Include <stdio.h>.
(c_asprintf, c_vasprintf): Use the standard printf format attribute.
* modules/c-vsnprintf (Depends-on): Add stdio.
* lib/c-vsnprintf.h: Include <stdio.h>.
(c_vsnprintf): Use the standard printf format attribute.
* modules/c-snprintf (Depends-on): Add stdio.
* lib/c-snprintf.h: Include <stdio.h>.
(c_snprintf): Use the standard printf format attribute.
* modules/c-xvasprintf (Depends-on): Add stdio.
* lib/c-xvasprintf.h: Include <stdio.h>.
(c_xasprintf, c_xvasprintf): Use the standard printf format attribute.
* modules/error (Depends-on): Depend on stdio always.
* lib/error.h: Include <stdio.h>.
(_GL_ATTRIBUTE_SPEC_PRINTF): Remove macro.
(error, error_at_line): Use a printf format attribute that depends on
GNULIB_VFPRINTF_POSIX.
* lib/error.c (_GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD): Renamed from
_GL_ATTRIBUTE_FORMAT_PRINTF.
* modules/verror (Depends-on): Add stdio.
* lib/verror.h: Include <stdio.h>. Don't include "error.h".
(verror, verror_at_line): Use the standard printf format attribute.
* lib/verror.c: Include "error.h".
* modules/argp (Depends-on): Add stdio.
* lib/argp.h (argp_error, __argp_error, argp_failure, __argp_failure):
Use a printf format attribute that depends on GNULIB_VFPRINTF_POSIX.
* modules/libtextstyle-optional (Depends-on): Add stdio.
* lib/textstyle.in.h (ostream_printf, ostream_vprintf): Use the standard
printf format attribute.
* tests/test-nonblocking-misc.h (dbgfprintf): Use the standard printf
format attribute.
Pádraig Brady [Mon, 23 Nov 2020 15:14:50 +0000 (15:14 +0000)]
selinux-at, selinux-h: use const correct declarations
* lib/se-selinux.in.h: Use const for "set" functions,
to match current selinux, and support cleaner user code.
* lib/selinux-at.c: Likewise.
* lib/selinux-at.h: Likewise.
Paul Eggert [Mon, 23 Nov 2020 07:37:57 +0000 (23:37 -0800)]
canonicalize-lgpl: fix memory leak
* lib/canonicalize-lgpl.c (__realpath): Fix unlikely memory leak,
which could have occurred if BUF was so large that malloc was
called. Do this by allocating EXTRA_BUF and BUF at the same time;
this eliminates the need to free BUF separately.
Paul Eggert [Sun, 22 Nov 2020 03:04:10 +0000 (19:04 -0800)]
parse-datetime: fix printf format typo
* lib/parse-datetime.y (parse_datetime2): Fix format typo in
previous patch to this file. Problem reported by Chris Elvidge in
<https://bugs.gnu.org/44763#32>.
Paul Eggert [Sun, 22 Nov 2020 02:09:29 +0000 (18:09 -0800)]
nl_langinfo-tests: work around GCC bug 44511
* tests/test-nl_langinfo-mt.c: Ignore -Wreturn-type, to work
around a GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44511>.
Problem reported for GNU grep by Andreas Schwab
<https://bugs.gnu.org/44535>.
Paul Eggert [Sat, 21 Nov 2020 20:54:22 +0000 (12:54 -0800)]
selinux-h: add stubs for selabel_open etc.
Coreutils with --enable-gcc-warnings does not build on Ubuntu 20.10
because matchpathcon is deprecated in favor of selabel_open etc.,
so this patch adds stubs for these functions.
* lib/se-label.c, lib/se-label.in.h, m4/selinux-label-h.m4: New files.
* lib/se-selinux.in.h (struct selinux_opt): Add incomplete decl,
as it is needed for selabel_open and selinux/selinux.h declares
this type here.
* modules/selinux-h (Files): Add the new files.
(configure.ac): Add gl_HEADERS_SELINUX_LABEL_H.
(lib_SOURCES): Add se-label.in.h, se-label.c.
(BUILT_SOURCES): Add $(SELINUX_LABEL_H).
(selinux/label.h): New rule, mimicking selinux/context.h.
(MOSTLYCLEANFILES): Add selinux/label.h, selinux/label.h-t.
(Include): Add selinux/label.h.
Akim Demaille [Thu, 19 Nov 2020 05:42:58 +0000 (06:42 +0100)]
bitset: tests: exercise the stats too
* tests/test-bitset.c: Display the stats at the end of the test.
* lib/bitset/stats.c (bitset_log_histogram_print): When diplaying the
last bin, display "256-..." rather that "256-511", since the last bin
does count item greater than or equal to 256.
Akim Demaille [Wed, 18 Nov 2020 20:37:34 +0000 (21:37 +0100)]
bitset: tests: try harder to break it
bitset_list (used in bitset_first, bitset_next, bitset_count,
BITSET_FOR_EACH, etc.) uses a cache of size BITSET_LIST_SIZE (1024).
None of our tests current try bitsets bigger than this.
* tests/test-bitset.c (compare): Be ready to use bitsets larger than
BITSET_LIST_SIZE.
(main): Likewise.
While at it, also exercise super small bitsets.
Akim Demaille [Tue, 17 Nov 2020 06:29:05 +0000 (07:29 +0100)]
bitset: strengthen tests
* tests/test-bitset.c (compare): Also check count.
Deal only with random values, move the one-bit tests to...
(check_one_bit): this new function.
(check_attributes): Call it.