From 5ccd7e60ad475b481144437c8e4037a56f32e4a0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marc=20Nieper-Wi=C3=9Fkirchen?= Date: Mon, 5 Apr 2021 15:24:32 +0200 Subject: [PATCH] hamt: Fix coding errors. Reported by Bruno Haible in 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 e8a27df73b..81d3aab73c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2021-04-05 Marc Nieper-Wißkirchen + + hamt: Fix coding errors. + Reported by Bruno Haible in + + 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 pthread-cond: Fix compilation error. diff --git a/lib/hamt.c b/lib/hamt.c index 204c2f0690..34880eff48 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 0cf6eb5a96..882bf0fc76 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.39.5