From 63e2aa962da65977811d1c835fc803c3fb92ba1b Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 8 Dec 2022 11:03:39 -0500 Subject: [PATCH] AK: Disallow implicit pointer-to-boolean conversion in JsonValue Similar to how LibJS and LibSQL used to behave, the boolean constructor of JsonValue is currently allowing pointers to be used to construct a boolean value. Explicitly disallow such construction. --- AK/JsonValue.cpp | 6 ------ AK/JsonValue.h | 10 +++++++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/AK/JsonValue.cpp b/AK/JsonValue.cpp index d3438e2dee6..725399356f5 100644 --- a/AK/JsonValue.cpp +++ b/AK/JsonValue.cpp @@ -168,12 +168,6 @@ JsonValue::JsonValue(double value) } #endif -JsonValue::JsonValue(bool value) - : m_type(Type::Bool) -{ - m_value.as_bool = value; -} - JsonValue::JsonValue(DeprecatedString const& value) { if (value.is_null()) { diff --git a/AK/JsonValue.h b/AK/JsonValue.h index 8f5dd904ad3..905483ee23c 100644 --- a/AK/JsonValue.h +++ b/AK/JsonValue.h @@ -55,12 +55,20 @@ public: #if !defined(KERNEL) JsonValue(double); #endif - JsonValue(bool); JsonValue(char const*); #ifndef KERNEL JsonValue(DeprecatedString const&); #endif JsonValue(StringView); + + template + requires(SameAs, bool>) + JsonValue(T value) + : m_type(Type::Bool) + , m_value { .as_bool = value } + { + } + JsonValue(JsonArray const&); JsonValue(JsonObject const&);