]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4637] Fix and improvements
authorFrancis Dupont <fdupont@isc.org>
Tue, 4 Aug 2026 17:54:34 +0000 (19:54 +0200)
committerFrancis Dupont <fdupont@isc.org>
Tue, 4 Aug 2026 19:13:38 +0000 (21:13 +0200)
changelog_unreleased/4637-mapelement-remove-int-has-undefined-behavior-on-out-of-range-index
src/lib/cc/tests/data_unittests.cc

index ce49923ebea0d9f7be6b6e454f8bc63b515ea7a3..01c391c6125b3d987b3d936d96cc09ee4082cd5f 100644 (file)
@@ -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)
index 6321aacadfe4d1b91bf481e7934745d193de6d0c..d44443552ef92024f89834aacb85b06a149849c9 100644 (file)
@@ -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<int>(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<int>(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<int>(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<int>(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<int>(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) {