From: Francis Dupont Date: Tue, 4 Aug 2026 17:54:34 +0000 (+0200) Subject: [#4637] Fix and improvements X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0fe864d3dfcfab2a092afbf037269bdeee02c908;p=thirdparty%2Fkea.git [#4637] Fix and improvements --- diff --git a/changelog_unreleased/4637-mapelement-remove-int-has-undefined-behavior-on-out-of-range-index b/changelog_unreleased/4637-mapelement-remove-int-has-undefined-behavior-on-out-of-range-index index ce49923ebe..01c391c612 100644 --- a/changelog_unreleased/4637-mapelement-remove-int-has-undefined-behavior-on-out-of-range-index +++ b/changelog_unreleased/4637-mapelement-remove-int-has-undefined-behavior-on-out-of-range-index @@ -1,4 +1,5 @@ [bug] wlodek - Fixed MapElement::remove() undefined behavior on out-of-range - indices so it matches the documented no-op contract. + Fixed MapElement::remove() const int overload undefined + behavior on out-of-range indices so it matches the + documented no-op contract. (Gitlab #4637) diff --git a/src/lib/cc/tests/data_unittests.cc b/src/lib/cc/tests/data_unittests.cc index 6321aacadf..d44443552e 100644 --- a/src/lib/cc/tests/data_unittests.cc +++ b/src/lib/cc/tests/data_unittests.cc @@ -843,21 +843,21 @@ TEST(Element, mapElement) { // rather than invoking undefined behavior (Gitlab #4637). TEST(Element, mapElementRemoveOutOfRange) { ElementPtr el = Element::fromJSON("{ \"a\": 1, \"b\": 2 }"); - ASSERT_EQ(2, static_cast(el->size())); + ASSERT_EQ(2U, el->size()); // Index past the end should be a no-op. EXPECT_NO_THROW(el->remove(5)); - EXPECT_EQ(2, static_cast(el->size())); + EXPECT_EQ(2U, el->size()); EXPECT_EQ("{ \"a\": 1, \"b\": 2 }", el->str()); // Index equal to size should be a no-op. EXPECT_NO_THROW(el->remove(2)); - EXPECT_EQ(2, static_cast(el->size())); + EXPECT_EQ(2U, el->size()); EXPECT_EQ("{ \"a\": 1, \"b\": 2 }", el->str()); // Negative index should be a no-op. EXPECT_NO_THROW(el->remove(-1)); - EXPECT_EQ(2, static_cast(el->size())); + EXPECT_EQ(2U, el->size()); EXPECT_EQ("{ \"a\": 1, \"b\": 2 }", el->str()); // Empty map: any remove should be a no-op. @@ -867,9 +867,10 @@ TEST(Element, mapElementRemoveOutOfRange) { // In-range remove still works (ordered map: index 0 is key "a"). EXPECT_NO_THROW(el->remove(0)); - EXPECT_EQ(1, static_cast(el->size())); + EXPECT_EQ(1U, el->size()); + ASSERT_TRUE(el->get("b")); EXPECT_EQ(2, el->get("b")->intValue()); - EXPECT_TRUE(isNull(el->get("a"))); + EXPECT_FALSE(el->get("a")); } TEST(Element, toAndFromWire) {