diff --git a/src/parser_xml.c b/src/parser_xml.c index 0db10cae2..944d3d530 100644 --- a/src/parser_xml.c +++ b/src/parser_xml.c @@ -441,7 +441,9 @@ lydxml_get_hints_opaq(const char *name, size_t name_len, const char *value, size { struct lyd_node_opaq *opaq; char *ptr; - long num; + /* this needs to be at least 64bit, and it "should not" be an explicit int64_t + * because the code calls strtoll later on, which "might" return a bigger type */ + long long num; *hints = 0; *anchor = NULL; @@ -453,11 +455,11 @@ lydxml_get_hints_opaq(const char *name, size_t name_len, const char *value, size /* boolean value */ *hints |= LYD_VALHINT_BOOLEAN; } else { - num = strtol(value, &ptr, 10); + num = strtoll(value, &ptr, 10); if ((unsigned)(ptr - value) == value_len) { /* number value */ *hints |= LYD_VALHINT_DECNUM; - if ((num < INT32_MIN) || (num > (long)UINT32_MAX)) { + if ((num < INT32_MIN) || (num > UINT32_MAX)) { /* large number */ *hints |= LYD_VALHINT_NUM64; } diff --git a/tests/utests/data/test_parser_xml.c b/tests/utests/data/test_parser_xml.c index d5336c030..28c37709a 100644 --- a/tests/utests/data/test_parser_xml.c +++ b/tests/utests/data/test_parser_xml.c @@ -193,6 +193,18 @@ test_anyxml(void **state) free(str); CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data_expected); lyd_free_all(tree); + + data = "10-142949672954294967296-2147483648-2147483649"; + CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); + assert_non_null(tree); + tree = tree->next; + assert_int_equal(LY_SUCCESS, lyd_print_mem(&str, tree, LYD_XML, LYD_PRINT_SHRINK)); + CHECK_STRING(str, data); + free(str); + assert_int_equal(LY_SUCCESS, lyd_print_mem(&str, tree, LYD_JSON, LYD_PRINT_SHRINK)); + CHECK_STRING(str, "{\"a:anyx\":{\"x\":[1,0,-1,4294967295,\"4294967296\",-2147483648,\"-2147483649\"]}}"); + free(str); + lyd_free_all(tree); } static void