From 0e09571f21d41969a26e9ec73ef0da78d9371d38 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sat, 17 Oct 2015 10:33:50 -0700 Subject: Fix integer overflow detection with leading zeros Since they don't contribute to the resulting value just skip them before parsing. This matches the behavior of strtol/strtoll and results in more intuitive behavior. --- tests/test_dom_traverse.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests/test_dom_traverse.cpp') diff --git a/tests/test_dom_traverse.cpp b/tests/test_dom_traverse.cpp index c7408cb..6cebd50 100644 --- a/tests/test_dom_traverse.cpp +++ b/tests/test_dom_traverse.cpp @@ -1188,6 +1188,22 @@ TEST_XML(dom_as_uint_hex_overflow, "") +{ + xml_node node = doc.child(STR("node")); + + CHECK(node.attribute(STR("attr1")).as_int() == 1); + CHECK(node.attribute(STR("attr1")).as_uint() == 1); +} + +TEST_XML(dom_as_int_hex_many_digits, "") +{ + xml_node node = doc.child(STR("node")); + + CHECK(node.attribute(STR("attr1")).as_int() == 1); + CHECK(node.attribute(STR("attr1")).as_uint() == 1); +} + #ifdef PUGIXML_HAS_LONG_LONG TEST_XML(dom_as_llong_overflow, "") { @@ -1224,6 +1240,22 @@ TEST_XML(dom_as_ullong_hex_overflow, "") +{ + xml_node node = doc.child(STR("node")); + + CHECK(node.attribute(STR("attr1")).as_llong() == 1); + CHECK(node.attribute(STR("attr1")).as_ullong() == 1); +} + +TEST_XML(dom_as_llong_hex_many_digits, "") +{ + xml_node node = doc.child(STR("node")); + + CHECK(node.attribute(STR("attr1")).as_llong() == 1); + CHECK(node.attribute(STR("attr1")).as_ullong() == 1); +} #endif TEST_XML(dom_as_int_plus, "") -- cgit v1.2.3