bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/1] hamt: Fix coding errors.


From: Marc Nieper-Wißkirchen
Subject: [PATCH 1/1] hamt: Fix coding errors.
Date: Mon, 5 Apr 2021 15:25:46 +0200

From: Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de>

Reported by Bruno Haible in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-04/msg00047.html>
after a Coverity run.
* lib/hamt.c (bucket_do_while, hamt_iterator): Add missing
derefencing operator and silence a bogus warning on uninitialized
variables.
* tests/test-hamt.c (test_general): Replace two errorneous
assignment operators with comparison operators.
---
 ChangeLog         | 12 ++++++++++++
 lib/hamt.c        |  6 +++---
 tests/test-hamt.c |  4 ++--
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e8a27df73..81d3aab73 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2021-04-05  Marc Nieper-Wißkirchen  <marc@nieper-wisskirchen.de>
+
+       hamt: Fix coding errors.
+       Reported by Bruno Haible in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2021-04/msg00047.html>
+       after a Coverity run.
+       * lib/hamt.c (bucket_do_while, hamt_iterator): Add missing
+       derefencing operator and silence a bogus warning on uninitialized
+       variables.
+       * tests/test-hamt.c (test_general): Replace two errorneous
+       assignment operators with comparison operators.
+
 2021-04-05  Fabrice Fontaine  <fontaine.fabrice@gmail.com>
 
        pthread-cond: Fix compilation error.
diff --git a/lib/hamt.c b/lib/hamt.c
index 204c2f069..34880eff4 100644
--- a/lib/hamt.c
+++ b/lib/hamt.c
@@ -873,7 +873,7 @@ bucket_do_while (const struct bucket *bucket, 
Hamt_processor *proc, void *data,
   for (size_t i = 0; i < elt_count; ++i)
     {
       *success = proc (elts[i], data);
-      if (!success)
+      if (*success == false)
         return cnt;
       ++cnt;
     }
@@ -946,14 +946,14 @@ hamt_iterator (Hamt *hamt)
   Hamt_iterator iter;
   iter.hamt = hamt_copy (hamt);
   Hamt_entry *entry = hamt->root;
+  iter.path = 0;
+  iter.position = 0;
   if (entry == NULL)
     {
       iter.depth = -1;
       return iter;
     }
   iter.depth = 0;
-  iter.path = 0;
-  iter.position = 0;
   while (iter.entry[iter.depth] = entry, entry_type (entry) == subtrie_entry)
     {
       const struct subtrie *subtrie = (const struct subtrie *) entry;
diff --git a/tests/test-hamt.c b/tests/test-hamt.c
index 0cf6eb5a9..882bf0fc7 100644
--- a/tests/test-hamt.c
+++ b/tests/test-hamt.c
@@ -152,10 +152,10 @@ test_general (void)
   hamt1 = hamt_remove (hamt2, &x4);
   sum = 0;
   ASSERT (hamt_do_while (hamt2, proc, &flag) == 4);
-  ASSERT (sum = 52);
+  ASSERT (sum == 52);
   sum = 0;
   ASSERT (hamt_do_while (hamt1, proc, &flag) == 3);
-  ASSERT (sum  = 48);
+  ASSERT (sum == 48);
 
   hamt_free (hamt1);
   hamt_free (hamt2);
-- 
2.25.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]