bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* [PATCH 1/1] hamt: Fix coding errors.
@ 2021-04-05 13:25 Marc Nieper-Wißkirchen
  0 siblings, 0 replies; only message in thread
From: Marc Nieper-Wißkirchen @ 2021-04-05 13:25 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Marc Nieper-Wißkirchen

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



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-05 13:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-05 13:25 [PATCH 1/1] hamt: Fix coding errors Marc Nieper-Wißkirchen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).