1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:54:58 +00:00

AK+LibJS: Remove error-prone JsonValue constructor

Consider the following:

    JsonValue value { JsonValue::Type::Object };
    value.as_object().set("foo"sv, "bar"sv);

The JsonValue(Type) constructor does not initialize the underlying union
that stores its value. Thus JsonValue::as_object() will A) refer to an
uninitialized union member, B) deference that member.

This constructor only has 2 users, both of which initialize the type to
Type::Null. Rather than implementing unused functionality here, replace
those uses with the default JsonValue constructor, and remove the faulty
constructor.
This commit is contained in:
Timothy Flynn 2023-10-31 16:02:26 -04:00 committed by Tim Flynn
parent 53d73b95ce
commit f630a5ca71
4 changed files with 3 additions and 9 deletions

View file

@ -304,7 +304,7 @@ ErrorOr<JsonValue> JsonParser::parse_null()
{
if (!consume_specific("null"))
return Error::from_string_literal("JsonParser: Expected 'null'");
return JsonValue(JsonValue::Type::Null);
return JsonValue {};
}
ErrorOr<JsonValue> JsonParser::parse_helper()