From 5d170810dbae64fff46bd581668e4b0bcd92b6f4 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Thu, 15 Jul 2021 03:31:08 +0430 Subject: 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. --- AK/JsonParser.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'AK') 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 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(); if (to_unsigned_result.has_value()) { - value = JsonValue(to_unsigned_result.value()); + auto number = *to_unsigned_result; + if (number <= NumericLimits::max()) + value = JsonValue((u32)number); + else + value = JsonValue(number); } else { auto number = number_string.to_int(); if (!number.has_value()) -- cgit v1.2.3