diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-07-15 03:31:08 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-15 01:47:35 +0200 |
commit | 5d170810dbae64fff46bd581668e4b0bcd92b6f4 (patch) | |
tree | ee02c35db5dfd17581fd8d2ff24080cf6349035f /AK | |
parent | 2404ad689729902fd27fe37f8ecbab935a6394e5 (diff) | |
download | serenity-5d170810dbae64fff46bd581668e4b0bcd92b6f4.zip |
AK: Make JsonParser correctly parse unsigned values larger than u32
Prior to this, it'd try to stuff them into an i64, which could fail and
give us nothing.
Even though this is an extension we've made to JSON, the parser should
be able to correctly round-trip from whatever our serialiser has
generated.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/JsonParser.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/AK/JsonParser.cpp b/AK/JsonParser.cpp index 3beda694dd..4d497cb1b5 100644 --- a/AK/JsonParser.cpp +++ b/AK/JsonParser.cpp @@ -263,9 +263,13 @@ Optional<JsonValue> JsonParser::parse_number() value = JsonValue((double)whole + ((double)fraction / divider)); } else { #endif - auto to_unsigned_result = number_string.to_uint(); + auto to_unsigned_result = number_string.to_uint<u64>(); if (to_unsigned_result.has_value()) { - value = JsonValue(to_unsigned_result.value()); + auto number = *to_unsigned_result; + if (number <= NumericLimits<u32>::max()) + value = JsonValue((u32)number); + else + value = JsonValue(number); } else { auto number = number_string.to_int<i64>(); if (!number.has_value()) |