Paul Eggert [Thu, 17 Sep 2020 19:17:15 +0000 (12:17 -0700)]
intprops, xalloc: avoid __builtin_mul_overflow_p with Clang
Problem reported by Nelson H. F. Beebe for clang 9.0.1 in:
https://lists.gnu.org/r/grep-devel/2020-09/msg00028.html
* lib/intprops.h (_GL_HAS_BUILTIN_OVERFLOW_P) [__clang__]:
Define to 0.
* lib/xalloc-oversized.h (xalloc_oversized) [__clang__]:
Do not use __builtin_mul_overflow_p.
Paul Eggert [Thu, 17 Sep 2020 16:45:21 +0000 (09:45 -0700)]
libc-config: port __THROW to Ubuntu 4
* lib/cdefs.h (__THROW): Do not use __attribute__ ((__nothrow__))
for GCC 3.3. Problem reported by Jeffrey Walton in:
https://lists.gnu.org/r/bug-gnulib/2019-07/msg00058.html
The GCC 3.3.4 documentation says the attribute should work, but
apparently it does not work on Ubuntu 4’s GCC 3.3. There seems
little point or desire to research this circa-2004 platform further,
so just avoid the attribute there.
Paul Eggert [Wed, 16 Sep 2020 22:40:20 +0000 (15:40 -0700)]
fnmatch: adjust to match glibc fix
This fixes handling of collating symbols in fnmatch (glibc bug 26620).
This does not affect Gnulib; it merely keeps Gnulib and glibc
closer together, to help with any eventual merge, by incorporating
a recent glibc patch. The patch and the following commentary is
by Andreas Schwab.
* lib/fnmatch_loop.c (FCT) [WIDE_CHAR_VERSION]: The variable idx
contains the index into the extra array, whereas wextra points
into the extra array at this index, containing the length of the
following collating sequence in the wide character representation.
Bruno Haible [Wed, 16 Sep 2020 21:51:52 +0000 (23:51 +0200)]
stat, fstat: Fix when compiling for versions older than Windows Vista.
Reported by Eli Zaretskii <eliz@gnu.org> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-09/msg00027.html>.
* lib/stat-w32.c: Include <sdkddkver.h>. Test the value of _WIN32_WINNT
that was originally set before we redefined it.
* m4/stat.m4 (gl_PREREQ_STAT_W32): New macro.
(gl_PREREQ_STAT): Require it.
* m4/fstat.m4 (gl_PREREQ_FSTAT): Likewise.
Paul Eggert [Tue, 15 Sep 2020 20:44:34 +0000 (13:44 -0700)]
dfa: remove dfa-heap-overrun workaround
* lib/dfa.c (reorder_tokens): Go back to a single pass that
both sets map[*] and does other things. This reverts
2020-09-14T01:20:01Z!eggert@cs.ucla.edu, which is no longer
needed now that 2020-09-14T13:21:05Z!noritnk@kcn.ne.jp
fixed the underlying problem.
If there are a espilon in a branch and the closure is iterated, maybe fails
in removal of the node. The bug is introduced in
commit da0e8454a8e68035ef4b87dbb9097f85df6ece27.
* lib/dfa.c (dfaanalyze): Calculate backward transition for not only
concatenation but closure.
Paul Eggert [Mon, 14 Sep 2020 01:40:08 +0000 (18:40 -0700)]
dfa: avoid use of uninitialized constraint
* lib/dfa.c (merge_nfa_state): Do not initialize the constraint
to zero here.
(dfaoptimize): Do it here instead, via xcalloc. This prevents the
use of an uninitialized constraint by later code when ! (flags[i]
& OPT_QUEUED) means merge_nfa_state was not called to initialize
the constraint. Problem found by running 'valgrind src/grep -E
'(^| )*(a|b)*(c|d)*( |$)' < /dev/null' on Ubuntu 18.04.5 x86-64.
Paul Eggert [Mon, 14 Sep 2020 01:20:01 +0000 (18:20 -0700)]
dfa: fix dfa-heap-overrun failure
* lib/dfa.c (reorder_tokens): When setting
map[d->follows[i].elems[j].index], instead of incorrectly assuming
that (i < d->follows[i].elems[j].index), use two loops, one to set
the map array and the other to use it. The incorrect assumption
caused some elements to be missed, and this in turn caused grep's
dfa-heap-overrun test to fail on Solaris 10 sparc when compiled
with GCC. I found this bug while investigating
https://buildfarm.opencsw.org/buildbot/builders/ggrep-solaris10-sparc/builds/183
and I think the bug also occurs on GNU/Linux but with more-subtle
symptoms. The bug predates the recent dfa.c changes; perhaps the
recent changes make the bug more likely.
Ben Pfaff [Sun, 13 Sep 2020 18:59:53 +0000 (20:59 +0200)]
getpass: Check for nonnull prompt argument while avoiding warnings.
The prompt parameter to getpass() is declared as nonnull (using a GCC
nonnull attribute). Gnulib contains two implementations of this function,
one for POSIX, one for Windows. The Windows implementation checked for
a nonnull prompt, which caused a GCC warning. This commit fixes that by
avoiding the nonnull attribute when building getpass.c. The POSIX
implementation did not check for a nonnull prompt. This commit increases
the robustness by adding such a check.
* lib/getpass.c (_GL_ARG_NONNULL): Define to empty.
(getpass) [!_WIN32]: Print prompt only if nonnull.
Paul Eggert [Sun, 13 Sep 2020 01:51:55 +0000 (18:51 -0700)]
dfa: epsilon-closure tweaks (Bug#40634)
Rename BACKWORD to BACKWARD consistently.
* lib/dfa.c (struct dfa): Reorder members to reduce fragmentation.
(addtok_mb): Redo slightly to make it act more like a state machine.
Check depth only when it increases.
(epsclosure): Let the switch test the tokens.
(dfaanalyze): Cache tindex. Simplify position loops.
Prefer xcalloc to xnmalloc + explicit zeroing. Free BACKWARD
only if it is not null, since we're testing that anyway.
(dfaanalyze, build_state): Use merge2 instead of doing it by hand.
dfa: use backward set in removal of epsilon closure
When removing in epsilon closure, the code searched all nodes
sequentially, and this was slow for some cases. Build a backward
set before search, and only check previous position with the set.
Problem reported in <https://bugs.gnu.org/40634>.
* lib/dfa.c (struct dfa): New member 'epsilon'.
(addtok_mb): Check whether a pattern has epsilon node or not.
(epsclosure): New arg BACKWORD; caller changed. When removing
epsilon node and reconnecting, check only previous positions.
Treat BEG as if it were character.
(dfaanalyze): Build backward set.
Paul Eggert [Thu, 10 Sep 2020 21:25:51 +0000 (14:25 -0700)]
canonicalize: fix pointer indexing bugs
Problem reported by Florian Weimer in:
https://lists.gnu.org/r/bug-gnulib/2020-09/msg00025.html
* lib/canonicalize-lgpl.c (__realpath):
* lib/canonicalize.c (canonicalize_filename_mode):
Do not generate a pointer past the end of the array.
* lib/canonicalize.c (canonicalize_filename_mode):
Do not use a pointer after passing it to realloc.
Paul Eggert [Thu, 10 Sep 2020 06:59:18 +0000 (23:59 -0700)]
tempname: help merge with glibc
Inspired by draft patches by Adhemerval Zanella in:
https://sourceware.org/pipermail/libc-alpha/2020-September/117501.html
https://sourceware.org/pipermail/libc-alpha/2020-September/117502.html
* lib/tempname.c: Include stdalign.h, time.h.
If _LIBC, do not include random-bits.h.
(__getrandom, __clock_gettime64, __timespec64) [!_LIBC]: New macros.
(RANDOM_BITS): Remove, replacing with ...
(random_bits): ... this new static function. All uses changed.
Add entropy each time if getrandom is not supported.
(RANDOM_VALUE, BASE_62_DIGITS, BASE_62_POWER):
Assume 64-bit support a la C99.
(try_tempname_len): Take advantage of ASLR when initializing
random value.
* modules/tempname (Depends-on): Add clock-time, stdalign, time.
Paul Eggert [Sun, 6 Sep 2020 00:40:22 +0000 (17:40 -0700)]
verify: avoid __builtin_assume
Our latest attempt to use Clang’s __builtin_assume caused a crash
in GNU Emacs that we spent quite some time tracking down as being
caused by the switch to __builtin_assume. It’s not known whether
the crash is due is a Clang bug or a portability bug in GNU Emacs.
For now, play it safe and avoid __builtin_assume.
* lib/verify.h (_GL_HAS_BUILTIN_ASSUME): Remove.
(assume): Simplify by not trying to use Clang’s __builtin_assume.
Bruno Haible [Sat, 5 Sep 2020 21:50:09 +0000 (23:50 +0200)]
Fix several "warning: no previous prototype for function".
* modules/unicase/locale-language (Makefile.am): Add a 'static' keyword
in front of the declaration of the lookup function in
unicase/locale-languages.h.
* modules/unictype/bidiclass-byname (Makefile.am): Likewise in
unictype/bidi_byname.h.
* modules/unictype/category-byname (Makefile.am): Likewise in
unictype/categ_byname.h.
* modules/unictype/combining-class-byname (Makefile.am): Likewise in
unictype/combiningclass_byname.h.
* modules/unictype/joininggroup-byname (Makefile.am): Likewise in
unictype/joininggroup_byname.h.
* modules/unictype/joiningtype-byname (Makefile.am): Likewise in
unictype/joiningtype_byname.h.
* modules/unictype/property-byname (Makefile.am): Likewise in
unictype/pr_byname.h.
* modules/unictype/scripts (Makefile.am): Likewise in
unictype/scripts_byname.h.
* modules/uninorm/composition (Makefile.am): Likewise in
uninorm/composition-table.h.
Bruno Haible [Sat, 5 Sep 2020 13:44:29 +0000 (15:44 +0200)]
uniname/uniname: Fix -Wshorten-64-to-32 warnings.
* lib/uniname/uniname.c (unicode_name_word_lookup): Change type of last
argument to size_t.
(unicode_name_character): Change type of len, n1, n2, n3, words_length,
n to size_t.
Paul Eggert [Tue, 1 Sep 2020 18:14:33 +0000 (11:14 -0700)]
manywarnings: remove -Wchkp and -Wabi from C++ too
Suggested by Reuben Thomas in:
https://lists.gnu.org/r/bug-gnulib/2020-09/msg00001.html
At some point somebody should merge the many other manywarnings-c.m4
changes into manywarnings-c++.m4 too, e.g.,
2020-07-02T00:00:51Z!eggert@cs.ucla.edu.
* m4/manywarnings-c++.m4 (gl_MANYWARN_ALL_GCC_CXX_IMPL):
Remove -Wchkp, -Wabi.
Bruno Haible [Sun, 30 Aug 2020 20:19:05 +0000 (22:19 +0200)]
strerrorname_np: New module.
* lib/string.in.h (strerrorname_np): New declaration.
* lib/strerrorname_np.c: New file.
* m4/strerrorname_np.m4: New file.
* m4/string_h.m4 (gl_HEADER_STRING_H_BODY): Test whether strerrorname_np
is declared.
(gl_HEADER_STRING_H_DEFAULTS): Initialize GNULIB_STRERRORNAME_NP,
HAVE_STRERRORNAME_NP, REPLACE_STRERRORNAME_NP.
* modules/string (Makefile.am): Substitute GNULIB_STRERRORNAME_NP,
HAVE_STRERRORNAME_NP, REPLACE_STRERRORNAME_NP.
* modules/strerrorname_np: New file.
* tests/test-string-c++.cc: Verify the signature of strerrorname_np.
* doc/glibc-functions/strerrorname_np.texi: Mention the new module and
the glibc 2.32 bug.
Bruno Haible [Wed, 26 Aug 2020 23:23:55 +0000 (01:23 +0200)]
time_rz: Change configure message.
* m4/time_rz.m4 (gl_TIME_RZ): Say "checking whether localtime works even
near extrema..." instead of "checking whether localtime loops forever
near extrema...".
Bruno Haible [Wed, 26 Aug 2020 23:21:27 +0000 (01:21 +0200)]
stdint: Change configure message.
* m4/stdint.m4 (gl_STDINT_H): Say "checking whether stdint.h works
without ISO C predefines..." instead of "checking whether stdint.h
predates C++11...".
Bruno Haible [Wed, 26 Aug 2020 23:04:36 +0000 (01:04 +0200)]
include_next: Change configure message.
* m4/include_next.m4 (gl_INCLUDE_NEXT): Say "checking whether source
code line length is unlimited..." instead of "checking whether system
header files limit the line length...".
Bruno Haible [Wed, 26 Aug 2020 22:49:28 +0000 (00:49 +0200)]
chdir-long: Change configure message.
* m4/chdir-long.m4 (gl_FUNC_CHDIR_LONG): Say "checking whether this
system supports file names of any length..." instead of "checking
whether this system has an arbitrary file name length limit...".
Set gl_cv_have_unlimited_file_name_length instead of
gl_cv_have_arbitrary_file_name_length_limit.
* modules/chdir-long (Depends-on, configure.ac): Update accordingly.
Bruno Haible [Wed, 26 Aug 2020 22:42:22 +0000 (00:42 +0200)]
iconv: Change configure message.
* m4/iconv.m4 (AM_ICONV): Say "checking whether iconv is compatible
with its POSIX signature..." instead of "checking for iconv
declaration...". Remove K&R C support.
Paul Eggert [Wed, 26 Aug 2020 22:30:53 +0000 (15:30 -0700)]
getcwd: help the merge back into glibc
This patch was inspired by Adhemerval Zanella’s proposed glibc patches:
https://sourceware.org/pipermail/libc-alpha/2020-August/117294.html
The idea is to make it easier for Gnulib lib/getcwd.c to match
glibc io/getcwd-generic.c.
* lib/getcwd.c [_LIBC]: Do not include pathmax.h.
Include not-cancel.h.
(HAVE_OPENAT, D_INO_IN_DIRENT, HAVE_MSVC_INVALID_PARAMETER_HANDLER)
(HAVE_MINIMALLY_WORKING_GETCWD): Define for the _LIBC case.
(__getcwd, __lstat, __readdir) [!_LIBC]: Remove these macros.
(__close_nocancel_nostatus, __getcwd_generic, stat64, __fstat64)
(__fstatat64, __lstat64, __readdir64, __fdopendir, __openat)
(__rewinddir, __openat64, dirent64) [_LIBC]: New macros.
(__getcwd_generic): Rename from __getcwd.
Use the abovementioned macros for consistency with glibc.
(weak_alias): Remove.
Bruno Haible [Tue, 25 Aug 2020 23:45:49 +0000 (01:45 +0200)]
verify: Avoid warnings when assume(0) is used.
Reported by Mattias Engdegård <mattiase@acm.org> via Paul Eggert in
<https://lists.gnu.org/archive/html/emacs-devel/2020-08/msg00838.html>.
* lib/verify.h (assume): Use __builtin_unreachable if the argument is
the constant 0.
* tests/test-verify.c (f): New function.
(state): New type.
(test_assume_expressions, test_assume_optimization,
test_assume_noreturn): New functions.
Paul Eggert [Mon, 24 Aug 2020 22:19:27 +0000 (15:19 -0700)]
diffseq: new option NOTE_ORDERED
Problem reported by Phil Sainty <https://bugs.gnu.org/42931>.
* NEWS: Mention this.
* lib/diffseq.h (NOTE_ORDERED): New macro.
(IF_LINT2): Remove; no longer needed.
(compareseq): If (!NOTE_ORDERED), recurse on the smaller
subproblem and iterate to do the larger.
Paul Eggert [Sun, 23 Aug 2020 20:14:13 +0000 (13:14 -0700)]
intprops: fix INT_MULTIPLY_WRAPV bit-field bug
The bug occurs when using INT_MULTIPLY_WRAPV (a, b, c) where B
is a bit-field, on older GCC or non-GCC compilers where we do
things ourselves instead of using __builtin_mul_overflow.
Without this fix, INT_MULTIPLY_WRAPV would not compile, due
to applying sizeof to a bit-field.
* lib/intprops.h (_GL_INT_MULTIPLY_RANGE_OVERFLOW):
Promote B before giving it to TYPE_WIDTH, in case B is a bit-field.
Bruno Haible [Sun, 23 Aug 2020 17:37:17 +0000 (19:37 +0200)]
supersede: Avoid a failure when writing to /dev/null in Solaris zones.
Reported by Jörg Sonnenberger <joerg@netbsd.org>
via Thomas Klausner <tk@giga.or.at> in
<https://pkgsrc.se/files.php?messageId=20200812233110.30230FB28@cvs.NetBSD.org>.
* lib/supersede.c (open_supersede): When opening an existing non-regular
file on Solaris, use O_CREAT although it should not be necessary.
Bruno Haible [Sat, 22 Aug 2020 00:22:05 +0000 (02:22 +0200)]
sigdescr_np: New module.
* lib/string.in.h (sigdescr_np): New declaration.
* lib/sigdescr_np.c: New file.
* m4/sigdescr_np.m4: New file.
* m4/string_h.m4 (gl_HEADER_STRING_H_BODY): Test whether sigdescr_np is
declared.
(gl_HEADER_STRING_H_DEFAULTS): Initialize GNULIB_SIGDESCR_NP,
HAVE_SIGDESCR_NP.
* modules/string (Makefile.am): Substitute GNULIB_SIGDESCR_NP,
HAVE_SIGDESCR_NP.
* modules/sigdescr_np: New file.
* tests/test-string-c++.cc: Verify the signature of sigdescr_np.
* doc/glibc-functions/sigdescr_np.texi: Mention the new module.
Bruno Haible [Thu, 20 Aug 2020 22:54:18 +0000 (00:54 +0200)]
sigabbrev_np: New module.
* lib/string.in.h (sigabbrev_np): New declaration.
* lib/sigabbrev_np.c: New file.
* m4/sigabbrev_np.m4: New file.
* m4/string_h.m4 (gl_HEADER_STRING_H_BODY): Test whether sigabbrev_np is
declared.
(gl_HEADER_STRING_H_DEFAULTS): Initialize GNULIB_SIGABBREV_NP,
HAVE_SIGABBREV_NP.
* modules/string (Makefile.am): Substitute GNULIB_SIGABBREV_NP,
HAVE_SIGABBREV_NP.
* modules/sigabbrev_np: New file.
* tests/test-string-c++.cc: Verify the signature of sigabbrev_np.
* doc/glibc-functions/sigabbrev_np.texi: Mention the new module.
Transform the ProjectQuirks comments into a docstring so that it can
be accessed from python as ProjectQuirks.__doc__ and harmonize
descriptions with the documentation.
* build-aux/vcstocl/projectquirks.py (ProjectQuirks):
Transform comments into a docstring.
* doc/vcs-to-changelog.texi: Sync up description with
comments.
ProjectQuirks is used by external quirks files and importing it from
vcs-to-changelog.py is broken since it was renamed to use hyphens. It
is cleaner to put it in its own file anyway.
* build-aux/vcstocl/projectquirks.py: A new file...
* build-aux/vcs-to-changelog.py (ProjectQuirks): ...to which
we move ProjectQuirks and import the file.
Bruno Haible [Wed, 19 Aug 2020 18:40:20 +0000 (20:40 +0200)]
uchar: Fix compilation errors in C++ mode on OpenBSD.
* lib/uchar.in.h (char16_t, char32_t): Don't define in C++ mode if
CXX_HAS_UCHAR_TYPES is 1.
* m4/uchar.m4 (gl_UCHAR_H): Determine whether the C++ compiler
predefines char16_t and char32_t. Substitute CXX_HAS_UCHAR_TYPES.
* modules/uchar (Makefile.am): Substitute CXX_HAS_UCHAR_TYPES.
Paul Eggert [Mon, 17 Aug 2020 21:47:45 +0000 (14:47 -0700)]
verify: avoid __built_assume on Clang
* lib/verify.h (assume): Do not use Clang’s __builtin_assume, as
Clang 9 incorrectly diagnoses arguments as having side effects
even when they do not. I guess Clang 9 considers any function
call as if it had a side effect here.
Paul Eggert [Mon, 17 Aug 2020 21:45:38 +0000 (14:45 -0700)]
libc-config: avoid Clang’s __diagnose_if__
* lib/cdefs.h (__warndecl, __warnattr, __errordecl):
For now, do not use __diagnose_if__ here, as this fails
on Fedora 31 with Clang 9.0.1, with diagnostic
"/usr/include/bits/stdio2.h:263:9: error: fgets called with bigger
size than length of destination buffer
[-Werror,-Wuser-defined-warnings]". I guess Clang 9 warns even
for functions that are not called?
Paul Eggert [Mon, 17 Aug 2020 19:39:48 +0000 (12:39 -0700)]
careadlinkat: speedup for GCC 10 with GCC_LINT
Inspired by a suggestion by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2020-08/msg00155.html
* lib/careadlinkat.c (STACK_BUF_SIZE): New constant.
(readlink_stk): New function, with most of the old careadlinkat
contents and with a new STACK_BUF arg. Inline it in GCC 10
if GCC_LINT.
(careadlinkat): Use the new function for everything but the
stack buffer.
Bruno Haible [Mon, 17 Aug 2020 08:39:03 +0000 (10:39 +0200)]
uchar C++ tests: Fix build error on FreeBSD 12.
* modules/uchar-c++-tests (configure.ac): Test whether <cuchar> exists.
(Makefile.am): Don't include test-uchar-c++2.cc in the compilation if
<cuchar> does not exist.