To silence these warnings:

 * -O0 only:
 ../../gllib/nstrftime.c:148:31: warning: 'memset' specified size 
18446744073709551615 exceeds maximum object size 9223372036854775807 
[-Wstringop-overflow=]
 ../../gllib/nstrftime.c:147:32: warning: 'memset' specified size 
18446744073709551615 exceeds maximum object size 9223372036854775807 
[-Wstringop-overflow=]
 
 * -O1, -O2, -O3 only:
 ../../gllib/vasnprintf.c:945:26: warning: argument 1 value 
'18446744073709551615' exceeds maximum object size 9223372036854775807 
[-Walloc-size-larger-than=]
 
 * -O2, -O3, -Os only:
 ../../gllib/astrxfrm.c:177:1: warning: function may return address of local 
variable [-Wreturn-local-addr]

I am applying these patches. The warning in vasnprintf.c is a consequence of
the use of SIZE_MAX (by xsize.h) to make malloc() fail. The warnings in
nstrftime.c and astrxfrm.c are false positives, due to insufficient data
flow analysis by gcc.


2023-05-18  Bruno Haible  <br...@clisp.org>

        vasnprintf, c-vasnprintf: Silence gcc warning.
        * lib/vasnprintf.c: Add #pragma GCC diagnostic.

2023-05-18  Bruno Haible  <br...@clisp.org>

        nstrftime: Silence gcc warning.
        * lib/nstrftime.c: Add #pragma GCC diagnostic.

2023-05-18  Bruno Haible  <br...@clisp.org>

        astrxfrm: Silence gcc warning.
        * lib/astrxfrm.c: Add #pragma GCC diagnostic.

>From 85a42d4dbb49735056c519f8da58d44e22ebc1c4 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Thu, 18 May 2023 22:37:20 +0200
Subject: [PATCH 1/5] astrxfrm: Silence gcc warning.

* lib/astrxfrm.c: Add #pragma GCC diagnostic.
---
 ChangeLog      | 5 +++++
 lib/astrxfrm.c | 6 ++++++
 2 files changed, 11 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index ee9a35da35..c32b7f5b63 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-05-18  Bruno Haible  <br...@clisp.org>
+
+	astrxfrm: Silence gcc warning.
+	* lib/astrxfrm.c: Add #pragma GCC diagnostic.
+
 2023-05-18  Bruno Haible  <br...@clisp.org>
 
 	vasnprintf, c-vasnprintf: Silence gcc warnings.
diff --git a/lib/astrxfrm.c b/lib/astrxfrm.c
index 845f0a0711..c3e69c7cee 100644
--- a/lib/astrxfrm.c
+++ b/lib/astrxfrm.c
@@ -24,6 +24,12 @@
 #include <stdlib.h>
 #include <string.h>
 
+/* Avoid false GCC warning "function may return address of local variable"
+   regarding result and tmpbuf.  */
+#if __GNUC__ + (__GNUC_MINOR__ >= 8) > 4
+# pragma GCC diagnostic ignored "-Wreturn-local-addr"
+#endif
+
 char *
 astrxfrm (const char *s, char *resultbuf, size_t *lengthp)
 {
-- 
2.34.1

>From 2e99a1af3bfd691462ee6525f16d620a9a82d813 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Thu, 18 May 2023 22:46:47 +0200
Subject: [PATCH 2/5] nstrftime: Silence gcc warning.

* lib/nstrftime.c: Add #pragma GCC diagnostic.
---
 ChangeLog       | 5 +++++
 lib/nstrftime.c | 8 ++++++++
 2 files changed, 13 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index c32b7f5b63..67100daa91 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-05-18  Bruno Haible  <br...@clisp.org>
+
+	nstrftime: Silence gcc warning.
+	* lib/nstrftime.c: Add #pragma GCC diagnostic.
+
 2023-05-18  Bruno Haible  <br...@clisp.org>
 
 	astrxfrm: Silence gcc warning.
diff --git a/lib/nstrftime.c b/lib/nstrftime.c
index 2a1dd8d88d..869c97f67d 100644
--- a/lib/nstrftime.c
+++ b/lib/nstrftime.c
@@ -276,6 +276,14 @@ extern char *tzname[];
    more reliable way to accept other sets of digits.  */
 #define ISDIGIT(Ch) ((unsigned int) (Ch) - L_('0') <= 9)
 
+/* Avoid false GCC warning "'memset' specified size 18446744073709551615 exceeds
+   maximum object size 9223372036854775807", caused by insufficient data flow
+   analysis and value propagation of the 'width_add' expansion when GCC is not
+   optimizing.  Cf. <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88443>.  */
+#if __GNUC__ >= 7 && !__OPTIMIZE__
+# pragma GCC diagnostic ignored "-Wstringop-overflow"
+#endif
+
 #if FPRINTFTIME
 static void
 fwrite_lowcase (FILE *fp, const CHAR_T *src, size_t len)
-- 
2.34.1

>From 52cd8f06753acc038bd900fe2c34d5598de1d6a3 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Thu, 18 May 2023 22:58:23 +0200
Subject: [PATCH 3/5] vasnprintf, c-vasnprintf: Silence gcc warning.

* lib/vasnprintf.c: Add #pragma GCC diagnostic.
---
 ChangeLog        |  5 +++++
 lib/vasnprintf.c | 12 ++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 67100daa91..50a9cef230 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-05-18  Bruno Haible  <br...@clisp.org>
+
+	vasnprintf, c-vasnprintf: Silence gcc warning.
+	* lib/vasnprintf.c: Add #pragma GCC diagnostic.
+
 2023-05-18  Bruno Haible  <br...@clisp.org>
 
 	nstrftime: Silence gcc warning.
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 007d280980..63a6cd60f3 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -927,6 +927,14 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
   return roomptr;
 }
 
+/* Avoid pointless GCC warning "argument 1 value '18446744073709551615' exceeds
+   maximum object size 9223372036854775807", triggered by the use of xsum as
+   argument of malloc.  */
+# if __GNUC__ >= 7
+#  pragma GCC diagnostic push
+#  pragma GCC diagnostic ignored "-Walloc-size-larger-than="
+# endif
+
 /* Convert a bignum a >= 0, multiplied with 10^extra_zeroes, to decimal
    representation.
    Destroys the contents of a.
@@ -983,6 +991,10 @@ convert_to_decimal (mpn_t a, size_t extra_zeroes)
   return c_ptr;
 }
 
+# if __GNUC__ >= 7
+#  pragma GCC diagnostic pop
+# endif
+
 # if NEED_PRINTF_LONG_DOUBLE
 
 /* Assuming x is finite and >= 0:
-- 
2.34.1

Reply via email to