Re: announce-gen: Fix copyright year in --version output.

2024-07-14 Thread Simon Josefsson via Gnulib discussion list
Collin Funk  writes:

> Hi Bruno,
>
> Bruno Haible  writes:
>
>> Can this be rewritten in a simpler way, that does not use idioms
>> from perl's bag of tricks? Something like
>>
>>   my $copyright_year = ;
>>
>> like one would do it in every other programming language?
>
> Not sure. I'm not the most knowledgeable perl programmer. Maybe
> something like this is more clear?
>
> my $copyright_year = (split ("-", $VERSION))[0];
>
> or perhaps someone else has a better idea.

That's better, but doesn't all this just hides the problem that 'make
update-copyright' doesn't bump the copyright for these two files?  I
think the policy is to bump copyright year to 2025 as soon as possible
after 2025-01-01 even if there are no other changes (which would bump
$VERSION) since we publish the file via git.  If we use your patch here,
that wouldn't happen until some change is made that bumps $VERSION,
which seems wrong.

I think this patch should be reverted, and gnulib's 'make
update-copyright' should be teached to update this file too.  What do
you think?  Do you want to propose a patch to it?

/Simon


signature.asc
Description: PGP signature


strtold: Work around major mingw bugs

2024-07-14 Thread Bruno Haible
On mingw-w64 5.0, I see a MT unit test go havoc when given enough time:

LC_ALL=French_France.1252 ./test-c-strtof-mt.exe 600 => OK
LC_ALL=French_France.1252 ./test-c-strtod-mt.exe 600 => OK
LC_ALL=French_France.1252 ./test-c-strtold-mt.exe 600 => Segmentation fault or 
Windows bluescreen

The cause is a malloc() without a free(), at *every* invocation
of strtold(), and without checking the result of malloc() against NULL.
And when the mingw people got notified about the memory leak,
the replaced the bug with another bug.


There is no problem on MSVC, because on MSVC 'long double' is the same as
'double':

LC_ALL=French_France.1252 ./test-c-strtof-mt.exe 600 => OK
LC_ALL=French_France.65001 ./test-c-strtof-mt.exe 600 => OK
LC_ALL=French_France.1252 ./test-c-strtod-mt.exe 600 => OK
LC_ALL=French_France.65001 ./test-c-strtod-mt.exe 600 => OK
LC_ALL=French_France.1252 ./test-c-strtold-mt.exe 600 => OK
LC_ALL=French_France.65001 ./test-c-strtold-mt.exe 600 => OK


These two patches provide workarounds.


2024-07-14  Bruno Haible  

Activate strtold workarounds.
* modules/c-strtold-tests (Depends-on): Add strtold.
* modules/ldtoastr (Depends-on): Add strtold.

2024-07-14  Bruno Haible  

strtold: Work around major mingw bugs.
* lib/strtod.c (HAVE_UNDERLYING_STRTOD) [USE_LONG_DOUBLE]: Set to 0 on
mingw versions before 10.0.
* doc/posix-functions/strtold.texi: Mention the mingw bugs.

>From 68432dda5e8ec389bd929057423af32c86827822 Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Sun, 14 Jul 2024 18:38:16 +0200
Subject: [PATCH 1/2] strtold: Work around major mingw bugs.

* lib/strtod.c (HAVE_UNDERLYING_STRTOD) [USE_LONG_DOUBLE]: Set to 0 on
mingw versions before 10.0.
* doc/posix-functions/strtold.texi: Mention the mingw bugs.
---
 ChangeLog| 7 +++
 doc/posix-functions/strtold.texi | 4 
 lib/strtod.c | 7 +++
 3 files changed, 18 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 56c0253f7a..44977a92fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-07-14  Bruno Haible  
+
+	strtold: Work around major mingw bugs.
+	* lib/strtod.c (HAVE_UNDERLYING_STRTOD) [USE_LONG_DOUBLE]: Set to 0 on
+	mingw versions before 10.0.
+	* doc/posix-functions/strtold.texi: Mention the mingw bugs.
+
 2024-07-13  Collin Funk  
 
 	useless-if-before-free: Fix copyright year in --version output.
diff --git a/doc/posix-functions/strtold.texi b/doc/posix-functions/strtold.texi
index 3fc1136ecb..5dbe158464 100644
--- a/doc/posix-functions/strtold.texi
+++ b/doc/posix-functions/strtold.texi
@@ -53,6 +53,10 @@
 This function fails to set @code{errno} upon underflow on some platforms:
 @c https://cygwin.com/ml/cygwin/2019-12/msg00072.html
 Cygwin 2.9.
+
+@item
+This function leaks memory on mingw 5.0
+and allocates an unbounded amount of stack on mingw 9.0.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/lib/strtod.c b/lib/strtod.c
index a545be09a4..e218a46f71 100644
--- a/lib/strtod.c
+++ b/lib/strtod.c
@@ -60,6 +60,13 @@
 # elif STRTOLD_HAS_UNDERFLOW_BUG
/* strtold would not set errno=ERANGE upon underflow.  */
 #  define HAVE_UNDERLYING_STRTOD 0
+# elif defined __MINGW32__ && __MINGW64_VERSION_MAJOR < 10
+   /* strtold is broken in mingw versions before 10.0:
+  - Up to mingw 5.0.x, it leaks memory at every invocation.
+  - Up to mingw 9.0.x, it allocates an unbounded amount of stack.
+  See 
+  and .  */
+#  define HAVE_UNDERLYING_STRTOD 0
 # else
 #  define HAVE_UNDERLYING_STRTOD HAVE_STRTOLD
 # endif
-- 
2.34.1

>From 51bcbc95b5955ca8a6c127fe2117647fd0c6a914 Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Sun, 14 Jul 2024 18:39:29 +0200
Subject: [PATCH 2/2] Activate strtold workarounds.

* modules/c-strtold-tests (Depends-on): Add strtold.
* modules/ldtoastr (Depends-on): Add strtold.
---
 ChangeLog   | 6 ++
 modules/c-strtold-tests | 1 +
 modules/ldtoastr| 1 +
 3 files changed, 8 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 44977a92fa..6bca856db2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-07-14  Bruno Haible  
+
+	Activate strtold workarounds.
+	* modules/c-strtold-tests (Depends-on): Add strtold.
+	* modules/ldtoastr (Depends-on): Add strtold.
+
 2024-07-14  Bruno Haible  
 
 	strtold: Work around major mingw bugs.
diff --git a/modules/c-strtold-tests b/modules/c-strtold-tests
index 7686da9755..fb1b6a80e0 100644
--- a/modules/c-strtold-tests
+++ b/modules/c-strtold-tests
@@ -17,6 +17,7 @@ signbit
 setlocale
 thread
 nanosleep
+strtold
 
 configure.ac:
 gt_LOCALE_FR
diff --git a/modules/ldtoastr b/modules/ldtoastr
index 40d69f3d6c..15d39162cd 100644
--- a/modules/ldtoastr
+++ b/modules/ldtoastr
@@ -9,6 +9,7 @@ lib/ldtoastr.c
 Depends-on:

Re: announce-gen: Fix copyright year in --version output.

2024-07-14 Thread Collin Funk
Hi Simon,

Simon Josefsson  writes:

> That's better, but doesn't all this just hides the problem that 'make
> update-copyright' doesn't bump the copyright for these two files?  I
> think the policy is to bump copyright year to 2025 as soon as possible
> after 2025-01-01 even if there are no other changes (which would bump
> $VERSION) since we publish the file via git.  If we use your patch here,
> that wouldn't happen until some change is made that bumps $VERSION,
> which seems wrong.
>
> I think this patch should be reverted, and gnulib's 'make
> update-copyright' should be teached to update this file too.  What do
> you think?  Do you want to propose a patch to it?

Maybe, I am misreading but I think using $VERSION makes more sense
according to the GNU Coding Standards [1]:

This copyright notice only needs to mention the most recent year in
which changes were made—there’s no need to list the years for previous
versions’ changes.

The useless-if-before-free script I updated recently to account for
nullptr in C23. And I know that announce-gen has been updated since
2022. Does updating the copyright header count as a change?

If your method is preferred then maybe I can add a second pass to
update-copyright to check for variables named COPYRIGHT_YEAR:

# Perl
my $COPYRIGHT_YEAR = '2024';
our $COPYRIGHT_YEAR = '2024';
# Shell
COPYRIGHT_YEAR='2024'

Thoughts?

P.S. Also does pushing to git update the $VERSION variable for you? I
thought that was done through saving the file in Emacs. Or manually for
non-Emacs users.

Collin

[1] https://www.gnu.org/prep/standards/standards.html#g_t_002d_002dversion



stdlib: Avoid syntax errors in libstdc++ header files

2024-07-14 Thread Bruno Haible
After yesterday's correction of stdlib.h in C++ mode, the CI reports a
compilation error on Solaris 11 OmniOS:

g++ -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -I. -I../../gltests -I..  
-DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. 
-I../../gltests/.. -I../gllib -I../../gltests/../gllib 
-I/home/bruno/prefix64/include -I/opt/ooce/include -Wall -D_REENTRANT  
-Wno-error -g -O2 -MT test-nullptr-c++.o -MD -MP -MF $depbase.Tpo -c -o 
test-nullptr-c++.o ../../gltests/test-nullptr-c++.cc &&\
mv -f $depbase.Tpo $depbase.Po
In file included from ../gllib/pthread.h:62,
 from 
/opt/gcc-9/include/c++/9.3.0/x86_64-pc-solaris2.11/bits/gthr-default.h:35,
 from 
/opt/gcc-9/include/c++/9.3.0/x86_64-pc-solaris2.11/bits/gthr.h:148,
 from /opt/gcc-9/include/c++/9.3.0/ext/atomicity.h:35,
 from /opt/gcc-9/include/c++/9.3.0/bits/ios_base.h:39,
 from /opt/gcc-9/include/c++/9.3.0/ios:42,
 from /opt/gcc-9/include/c++/9.3.0/ostream:38,
 from /opt/gcc-9/include/c++/9.3.0/iostream:39,
 from ../../gltests/test-nullptr-c++.cc:25:
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h: In function 'int 
std::__cxx11::stoi(const string&, std::size_t*, int)':
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h:6504:47: error: 'rpl_strtol' 
is not a member of 'std'; did you mean 'strtol'?
 6504 |   { return __gnu_cxx::__stoa(&std::strtol, "stoi", 
__str.c_str(),
  |   ^~
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h: In function 'long int 
std::__cxx11::stol(const string&, std::size_t*, int)':
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h:6509:36: error: 'rpl_strtol' 
is not a member of 'std'; did you mean 'strtol'?
 6509 |   { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
  |^~
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h: In function 'long unsigned 
int std::__cxx11::stoul(const string&, std::size_t*, int)':
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h:6514:36: error: 'rpl_strtoul' 
is not a member of 'std'; did you mean 'strtoul'?
 6514 |   { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
  |^~~
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h: In function 'long long int 
std::__cxx11::stoll(const string&, std::size_t*, int)':
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h:6519:36: error: 'rpl_strtoll' 
is not a member of 'std'; did you mean 'rpl_strtoll'?
 6519 |   { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
  |^~~
In file included from /usr/include/sys/time.h:489,
 from ../gllib/sys/time.h:46,
 from /usr/include/sys/select.h:53,
 from ../gllib/sys/select.h:43,
 from /usr/include/sys/types.h:640,
 from ../gllib/sys/types.h:46,
 from ../gllib/stdio.h:83,
 from /usr/include/iso/wchar_iso.h:54,
 from 
/opt/gcc-9/lib/gcc/x86_64-pc-solaris2.11/9.3.0/include-fixed/wchar.h:40,
 from ../gllib/wchar.h:80,
 from /opt/gcc-9/include/c++/9.3.0/cwchar:44,
 from /opt/gcc-9/include/c++/9.3.0/bits/postypes.h:40,
 from /opt/gcc-9/include/c++/9.3.0/iosfwd:40,
 from /opt/gcc-9/include/c++/9.3.0/ios:38,
 from /opt/gcc-9/include/c++/9.3.0/ostream:38,
 from /opt/gcc-9/include/c++/9.3.0/iostream:39,
 from ../../gltests/test-nullptr-c++.cc:25:
../gllib/stdlib.h:2309:1: note: 'rpl_strtoll' declared here
 2309 | _GL_FUNCDECL_RPL (strtoll, long long,
  | ^~~~
In file included from ../gllib/pthread.h:62,
 from 
/opt/gcc-9/include/c++/9.3.0/x86_64-pc-solaris2.11/bits/gthr-default.h:35,
 from 
/opt/gcc-9/include/c++/9.3.0/x86_64-pc-solaris2.11/bits/gthr.h:148,
 from /opt/gcc-9/include/c++/9.3.0/ext/atomicity.h:35,
 from /opt/gcc-9/include/c++/9.3.0/bits/ios_base.h:39,
 from /opt/gcc-9/include/c++/9.3.0/ios:42,
 from /opt/gcc-9/include/c++/9.3.0/ostream:38,
 from /opt/gcc-9/include/c++/9.3.0/iostream:39,
 from ../../gltests/test-nullptr-c++.cc:25:
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h: In function 'long long 
unsigned int std::__cxx11::stoull(const string&, std::size_t*, int)':
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h:6524:36: error: 'rpl_strtoull' 
is not a member of 'std'; did you mean 'rpl_strtoull'?
 6524 |   { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
  |^~~~
In file included from /usr/include/sys/time.h:489,
 from ../gllib/sys/time.h:46,
 from /usr/include/sy

Re: stdlib: Avoid syntax errors in libstdc++ header files

2024-07-14 Thread Bruno Haible
I did:
> 2024-07-14  Bruno Haible  
> 
>   stdlib: Avoid syntax errors in libstdc++ header files.
>   * lib/stdlib.in.h: Include  before strtol, strtoll, strtoul, or
>   strtoull gets defined as a macro.

Oops, this causes other compilation errors on macOS 13, 14 and OpenBSD
(since the libstdc++ there is not the GNU one) and on mingw 10.0. I don't
understand why, but this '#include ' is causing other compilation
errors on mingw:


x86_64-w64-mingw32-g++ -DHAVE_CONFIG_H -DEXEEXT=\".exe\" -DEXEEXT=\".exe\" -I. 
-I../../gltests -I..  -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. 
-I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib 
-D_WIN32_WINNT=_WIN32_WINNT_WINXP -I/usr/local/mingw64/include -Wall  
-Wno-error -g -O2 -MT test-nullptr-c++.o -MD -MP -MF $depbase.Tpo -c -o 
test-nullptr-c++.o ../../gltests/test-nullptr-c++.cc &&\
mv -f $depbase.Tpo $depbase.Po
In file included from /usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/string:55,
 from ../gllib/stdlib.h:128,
 from 
/usr/x86_64-w64-mingw32/sys-root/mingw/include/sec_api/stdlib_s.h:9,
 from 
/usr/x86_64-w64-mingw32/sys-root/mingw/include/stdlib.h:765,
 from /usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/cstdlib:75,
 from 
/usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/stdlib.h:36,
 from ../gllib/stdlib.h:49,
 from ../gllib/stdio.h:105,
 from 
/usr/x86_64-w64-mingw32/sys-root/mingw/include/locale.h:12,
 from ../gllib/locale.h:41,
 from /usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/clocale:42,
 from 
/usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/x86_64-w64-mingw32/bits/c++locale.h:41,
 from 
/usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/bits/localefwd.h:40,
 from /usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/ios:41,
 from /usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/ostream:38,
 from 
/usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/iostream:39,
 from ../../gltests/test-nullptr-c++.cc:25:
/usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/bits/basic_string.h: In function 
'int std::__cxx11::stoi(const string&, std::size_t*, int)':
/usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/bits/basic_string.h:6620:47: 
error: 'strtol' is not a member of 'std'; did you mean 'strtol'?
 6620 |   { return __gnu_cxx::__stoa(&std::strtol, "stoi", 
__str.c_str(),
  |   ^~
In file included from /usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/cstdlib:75,
 from 
/usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/stdlib.h:36,
 from ../gllib/stdlib.h:49,
 from ../gllib/stdio.h:105,
 from 
/usr/x86_64-w64-mingw32/sys-root/mingw/include/locale.h:12,
 from ../gllib/locale.h:41,
 from /usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/clocale:42,
 from 
/usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/x86_64-w64-mingw32/bits/c++locale.h:41,
 from 
/usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/bits/localefwd.h:40,
 from /usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/ios:41,
 from /usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/ostream:38,
 from 
/usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/iostream:39,
 from ../../gltests/test-nullptr-c++.cc:25:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/stdlib.h:519:16: note: 'strtol' 
declared here
  519 |   long __cdecl strtol(const char * __restrict__ _Str,char ** 
__restrict__ _EndPtr,int _Radix);
  |^~
In file included from /usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/string:55,
 from ../gllib/stdlib.h:128,
 from 
/usr/x86_64-w64-mingw32/sys-root/mingw/include/sec_api/stdlib_s.h:9,
 from 
/usr/x86_64-w64-mingw32/sys-root/mingw/include/stdlib.h:765,
 from /usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/cstdlib:75,
 from 
/usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/stdlib.h:36,
 from ../gllib/stdlib.h:49,
 from ../gllib/stdio.h:105,
 from 
/usr/x86_64-w64-mingw32/sys-root/mingw/include/locale.h:12,
 from ../gllib/locale.h:41,
 from /usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/clocale:42,
 from 
/usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/x86_64-w64-mingw32/bits/c++locale.h:41,
 from 
/usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/bits/localefwd.h:40,
 from /usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/ios:41,
 from /usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/ostream:38,
 from 
/usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/iostream:39,
  

Re: Integer overflows in memchr

2024-07-14 Thread Po Lu
Paul Eggert  writes:

> On 6/30/24 13:14, Po Lu wrote:
>> I think there should be a trivial test for a functional strnlen in
>> strnlen.m4, since it would be terrible to duplicate what ought to be the
>> responsibility of Gnulib in Emacs's configure.ac.
>
> Here's a first cut at doing that, as a patch to Emacs master that I
> have not installed. Could you please give it a try? If it works I can
> migrate it into Gnulib and Autoconf.

It appears to work as intended.  Thanks.