bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: "Marc Nieper-Wißkirchen" <marc.nieper+gnu@gmail.com>
To: bug-gnulib@gnu.org
Cc: "Marc Nieper-Wißkirchen" <marc@nieper-wisskirchen.de>
Subject: [PATCH 1/1] hamt: Fix coding errors.
Date: Mon,  5 Apr 2021 15:25:46 +0200	[thread overview]
Message-ID: <20210405132546.1625039-1-marc.nieper+gnu@gmail.com> (raw)

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	other threads:[~2021-04-05 13:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210405132546.1625039-1-marc.nieper+gnu@gmail.com \
    --to=marc.nieper+gnu@gmail.com \
    --cc=bug-gnulib@gnu.org \
    --cc=marc@nieper-wisskirchen.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).