In order to silence these warnings:

> * -O1, -O2, -O3, -Os only:
> ../../gllib/vasnprintf.c:1392:10: warning: 'e' may be used uninitialized 
> [-Wmaybe-uninitialized]
> ../../gllib/vasnprintf.c:1410:10: warning: 'e' may be used uninitialized 
> [-Wmaybe-uninitialized]
> 
> * -Og only:
> ../../gllib/bitset/list.c:458:22: warning: 'tmp' may be used uninitialized 
> [-Wmaybe-uninitialized]

I'm applying small code changes.

- In vasnprintf.c, gcc is right that the variable e is used unitialized; the
  value is passed to a function that then ignores it.
- In bitset/list.c, gcc is fooled by a loop entry test that can never fail,
  but gcc happens to not notice it. As an optimization of the code, let me
  remove this loop entry test (i.e. transform it to a loop end test).


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

        vasnprintf, c-vasnprintf: Silence gcc warnings.
        * lib/vasnprintf.c (scale10_round_decimal_decoded): Remove memory==NULL
        test.
        (scale10_round_decimal_long_double, scale10_round_decimal_double): Test
        for memory==NULL here. Remove use of IF_LINT.

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

        bitset: Silence gcc warning.
        * lib/bitset/list.c (lbitset_copy_): Remove redundant test from the
        loop's first iteration.

>From bcab9f794d04477fdbedc82961510c80f8cbab05 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Thu, 18 May 2023 22:40:12 +0200
Subject: [PATCH 1/7] bitset: Silence gcc warning.

* lib/bitset/list.c (lbitset_copy_): Remove redundant test from the
loop's first iteration.
---
 ChangeLog         | 6 ++++++
 lib/bitset/list.c | 6 +++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 0216321fc6..1796c625ee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-05-18  Bruno Haible  <br...@clisp.org>
+
+	bitset: Silence gcc warning.
+	* lib/bitset/list.c (lbitset_copy_): Remove redundant test from the
+	loop's first iteration.
+
 2023-05-18  Bruno Haible  <br...@clisp.org>
 
 	stack: Silence gcc warning in tests.
diff --git a/lib/bitset/list.c b/lib/bitset/list.c
index f73ea70fee..eee7fefeeb 100644
--- a/lib/bitset/list.c
+++ b/lib/bitset/list.c
@@ -441,7 +441,8 @@ lbitset_copy_ (bitset dst, bitset src)
 
   lbitset_elt *prev = 0;
   lbitset_elt *tmp;
-  for (lbitset_elt *elt = head; elt; elt = elt->next)
+  lbitset_elt *elt = head;
+  do
     {
       tmp = lbitset_elt_alloc ();
       tmp->index = elt->index;
@@ -454,7 +455,10 @@ lbitset_copy_ (bitset dst, bitset src)
       prev = tmp;
 
       memcpy (tmp->words, elt->words, sizeof (elt->words));
+
+      elt = elt->next;
     }
+  while (elt);
   LBITSET_TAIL (dst) = tmp;
 
   dst->b.csize = LBITSET_ELT_WORDS;
-- 
2.34.1

>From a654869530ca6fd6cf45f9e1f8257362b1100f7e Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Thu, 18 May 2023 22:51:17 +0200
Subject: [PATCH 2/7] vasnprintf, c-vasnprintf: Silence gcc warnings.

* lib/vasnprintf.c (scale10_round_decimal_decoded): Remove memory==NULL
test.
(scale10_round_decimal_long_double, scale10_round_decimal_double): Test
for memory==NULL here. Remove use of IF_LINT.
---
 ChangeLog        |  8 ++++++++
 lib/vasnprintf.c | 16 ++++++++++------
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1796c625ee..ee9a35da35 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-05-18  Bruno Haible  <br...@clisp.org>
+
+	vasnprintf, c-vasnprintf: Silence gcc warnings.
+	* lib/vasnprintf.c (scale10_round_decimal_decoded): Remove memory==NULL
+	test.
+	(scale10_round_decimal_long_double, scale10_round_decimal_double): Test
+	for memory==NULL here. Remove use of IF_LINT.
+
 2023-05-18  Bruno Haible  <br...@clisp.org>
 
 	bitset: Silence gcc warning.
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 802790e14e..007d280980 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -1177,8 +1177,6 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
   void *z_memory;
   char *digits;
 
-  if (memory == NULL)
-    return NULL;
   /* x = 2^e * m, hence
      y = round (2^e * 10^n * m) = round (2^(e+n) * 5^n * m)
        = round (2^s * 5^n * m).  */
@@ -1386,10 +1384,13 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
 static char *
 scale10_round_decimal_long_double (long double x, int n)
 {
-  int e IF_LINT(= 0);
+  int e;
   mpn_t m;
   void *memory = decode_long_double (x, &e, &m);
-  return scale10_round_decimal_decoded (e, m, memory, n);
+  if (memory != NULL)
+    return scale10_round_decimal_decoded (e, m, memory, n);
+  else
+    return NULL;
 }
 
 # endif
@@ -1404,10 +1405,13 @@ scale10_round_decimal_long_double (long double x, int n)
 static char *
 scale10_round_decimal_double (double x, int n)
 {
-  int e IF_LINT(= 0);
+  int e;
   mpn_t m;
   void *memory = decode_double (x, &e, &m);
-  return scale10_round_decimal_decoded (e, m, memory, n);
+  if (memory != NULL)
+    return scale10_round_decimal_decoded (e, m, memory, n);
+  else
+    return NULL;
 }
 
 # endif
-- 
2.34.1

Reply via email to