summaryrefslogtreecommitdiff
path: root/AK/JsonParser.cpp
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-07-15 03:31:08 +0430
committerAndreas Kling <kling@serenityos.org>2021-07-15 01:47:35 +0200
commit5d170810dbae64fff46bd581668e4b0bcd92b6f4 (patch)
treeee02c35db5dfd17581fd8d2ff24080cf6349035f /AK/JsonParser.cpp
parent2404ad689729902fd27fe37f8ecbab935a6394e5 (diff)
downloadserenity-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/JsonParser.cpp')
-rw-r--r--AK/JsonParser.cpp8
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())