瀏覽代碼

AK+Everywhere: Delete Variant's default constructor

This was exposed to the user by mistake, and even accumulated a bunch of
users that didn't blow up out of sheer luck.
Ali Mohammad Pur 4 年之前
父節點
當前提交
15f95220ae

+ 2 - 0
AK/Variant.h

@@ -210,6 +210,8 @@ public:
     template<typename... NewTs>
     template<typename... NewTs>
     friend struct Variant;
     friend struct Variant;
 
 
+    Variant() = delete;
+
 #ifdef AK_HAS_CONDITIONALLY_TRIVIAL
 #ifdef AK_HAS_CONDITIONALLY_TRIVIAL
     Variant(const Variant&) requires(!(IsCopyConstructible<Ts> && ...)) = delete;
     Variant(const Variant&) requires(!(IsCopyConstructible<Ts> && ...)) = delete;
     Variant(const Variant&) = default;
     Variant(const Variant&) = default;

+ 8 - 5
Userland/Libraries/LibRegex/RegexParser.cpp

@@ -1556,7 +1556,7 @@ bool ECMA262Parser::parse_atom_escape(ByteCode& stack, size_t& match_length_mini
     }
     }
 
 
     if (unicode) {
     if (unicode) {
-        PropertyEscape property {};
+        PropertyEscape property { Empty {} };
         bool negated = false;
         bool negated = false;
 
 
         if (parse_unicode_property_escape(property, negated)) {
         if (parse_unicode_property_escape(property, negated)) {
@@ -1575,7 +1575,8 @@ bool ECMA262Parser::parse_atom_escape(ByteCode& stack, size_t& match_length_mini
                         compares.empend(CompareTypeAndValuePair { CharacterCompareType::ScriptExtension, (ByteCodeValueType)script.script });
                         compares.empend(CompareTypeAndValuePair { CharacterCompareType::ScriptExtension, (ByteCodeValueType)script.script });
                     else
                     else
                         compares.empend(CompareTypeAndValuePair { CharacterCompareType::Script, (ByteCodeValueType)script.script });
                         compares.empend(CompareTypeAndValuePair { CharacterCompareType::Script, (ByteCodeValueType)script.script });
-                });
+                },
+                [](Empty&) { VERIFY_NOT_REACHED(); });
             stack.insert_bytecode_compare_values(move(compares));
             stack.insert_bytecode_compare_values(move(compares));
             match_length_minimum += 1;
             match_length_minimum += 1;
             return true;
             return true;
@@ -1818,7 +1819,7 @@ bool ECMA262Parser::parse_nonempty_class_ranges(Vector<CompareTypeAndValuePair>&
                 if (try_skip("-"))
                 if (try_skip("-"))
                     return { CharClassRangeElement { .code_point = '-', .is_character_class = false } };
                     return { CharClassRangeElement { .code_point = '-', .is_character_class = false } };
 
 
-                PropertyEscape property {};
+                PropertyEscape property { Empty {} };
                 bool negated = false;
                 bool negated = false;
                 if (parse_unicode_property_escape(property, negated)) {
                 if (parse_unicode_property_escape(property, negated)) {
                     return property.visit(
                     return property.visit(
@@ -1833,7 +1834,8 @@ bool ECMA262Parser::parse_nonempty_class_ranges(Vector<CompareTypeAndValuePair>&
                                 return CharClassRangeElement { .script = script.script, .is_negated = negated, .is_character_class = true, .is_script_extension = true };
                                 return CharClassRangeElement { .script = script.script, .is_negated = negated, .is_character_class = true, .is_script_extension = true };
                             else
                             else
                                 return CharClassRangeElement { .script = script.script, .is_negated = negated, .is_character_class = true, .is_script = true };
                                 return CharClassRangeElement { .script = script.script, .is_negated = negated, .is_character_class = true, .is_script = true };
-                        });
+                        },
+                        [](Empty&) -> CharClassRangeElement { VERIFY_NOT_REACHED(); });
                 }
                 }
             }
             }
 
 
@@ -1983,7 +1985,8 @@ bool ECMA262Parser::parse_unicode_property_escape(PropertyEscape& property, bool
             return true;
             return true;
         },
         },
         [](Unicode::GeneralCategory) { return true; },
         [](Unicode::GeneralCategory) { return true; },
-        [](Script) { return true; });
+        [](Script) { return true; },
+        [](Empty&) -> bool { VERIFY_NOT_REACHED(); });
 }
 }
 
 
 StringView ECMA262Parser::read_capture_group_specifier(bool take_starting_angle_bracket)
 StringView ECMA262Parser::read_capture_group_specifier(bool take_starting_angle_bracket)

+ 1 - 1
Userland/Libraries/LibRegex/RegexParser.h

@@ -218,7 +218,7 @@ private:
         Unicode::Script script {};
         Unicode::Script script {};
         bool is_extension { false };
         bool is_extension { false };
     };
     };
-    using PropertyEscape = Variant<Unicode::Property, Unicode::GeneralCategory, Script>;
+    using PropertyEscape = Variant<Unicode::Property, Unicode::GeneralCategory, Script, Empty>;
     Optional<PropertyEscape> read_unicode_property_escape();
     Optional<PropertyEscape> read_unicode_property_escape();
 
 
     bool parse_pattern(ByteCode&, size_t&, bool unicode, bool named);
     bool parse_pattern(ByteCode&, size_t&, bool unicode, bool named);

+ 3 - 0
Userland/Libraries/LibSQL/Value.cpp

@@ -10,11 +10,13 @@
 namespace SQL {
 namespace SQL {
 
 
 Value::Value(SQLType sql_type)
 Value::Value(SQLType sql_type)
+    : m_impl(0)
 {
 {
     setup(sql_type);
     setup(sql_type);
 }
 }
 
 
 Value::Value(SQLType sql_type, ByteBuffer& buffer, size_t& offset)
 Value::Value(SQLType sql_type, ByteBuffer& buffer, size_t& offset)
+    : m_impl(0)
 {
 {
     setup(sql_type);
     setup(sql_type);
     m_deserialize(buffer, offset);
     m_deserialize(buffer, offset);
@@ -22,6 +24,7 @@ Value::Value(SQLType sql_type, ByteBuffer& buffer, size_t& offset)
 }
 }
 
 
 Value::Value(Value const& other)
 Value::Value(Value const& other)
+    : m_impl(0)
 {
 {
     setup(other.type());
     setup(other.type());
     m_is_null = other.is_null();
     m_is_null = other.is_null();

+ 1 - 1
Userland/Libraries/LibSQL/Value.h

@@ -102,7 +102,7 @@ private:
     SQLType m_type { SQLType::Text };
     SQLType m_type { SQLType::Text };
     bool m_is_null { true };
     bool m_is_null { true };
 
 
-    Variant<String, int, double> m_impl {};
+    Variant<String, int, double> m_impl;
 };
 };
 
 
 }
 }

+ 14 - 4
Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

@@ -2197,7 +2197,10 @@ Optional<CalculatedStyleValue::CalcValue> Parser::parse_calc_value(ParsingContex
 
 
 OwnPtr<CalculatedStyleValue::CalcProductPartWithOperator> Parser::parse_calc_product_part_with_operator(ParsingContext const& context, TokenStream<StyleComponentValueRule>& tokens)
 OwnPtr<CalculatedStyleValue::CalcProductPartWithOperator> Parser::parse_calc_product_part_with_operator(ParsingContext const& context, TokenStream<StyleComponentValueRule>& tokens)
 {
 {
-    auto product_with_operator = make<CalculatedStyleValue::CalcProductPartWithOperator>();
+    // Note: The default value is not used or passed around.
+    auto product_with_operator = make<CalculatedStyleValue::CalcProductPartWithOperator>(
+        CalculatedStyleValue::CalcProductPartWithOperator::Multiply,
+        CalculatedStyleValue::CalcNumberValue(0));
 
 
     tokens.skip_whitespace();
     tokens.skip_whitespace();
 
 
@@ -2232,7 +2235,10 @@ OwnPtr<CalculatedStyleValue::CalcProductPartWithOperator> Parser::parse_calc_pro
 
 
 OwnPtr<CalculatedStyleValue::CalcNumberProductPartWithOperator> Parser::parse_calc_number_product_part_with_operator(ParsingContext const& context, TokenStream<StyleComponentValueRule>& tokens)
 OwnPtr<CalculatedStyleValue::CalcNumberProductPartWithOperator> Parser::parse_calc_number_product_part_with_operator(ParsingContext const& context, TokenStream<StyleComponentValueRule>& tokens)
 {
 {
-    auto number_product_with_operator = make<CalculatedStyleValue::CalcNumberProductPartWithOperator>();
+    // Note: The default value is not used or passed around.
+    auto number_product_with_operator = make<CalculatedStyleValue::CalcNumberProductPartWithOperator>(
+        CalculatedStyleValue::CalcNumberProductPartWithOperator::Multiply,
+        CalculatedStyleValue::CalcNumberValue(0));
 
 
     tokens.skip_whitespace();
     tokens.skip_whitespace();
 
 
@@ -2263,7 +2269,9 @@ OwnPtr<CalculatedStyleValue::CalcNumberProductPartWithOperator> Parser::parse_ca
 
 
 OwnPtr<CalculatedStyleValue::CalcNumberProduct> Parser::parse_calc_number_product(ParsingContext const& context, TokenStream<StyleComponentValueRule>& tokens)
 OwnPtr<CalculatedStyleValue::CalcNumberProduct> Parser::parse_calc_number_product(ParsingContext const& context, TokenStream<StyleComponentValueRule>& tokens)
 {
 {
-    auto calc_number_product = make<CalculatedStyleValue::CalcNumberProduct>();
+    auto calc_number_product = make<CalculatedStyleValue::CalcNumberProduct>(
+        CalculatedStyleValue::CalcNumberValue(0),
+        NonnullOwnPtrVector<CalculatedStyleValue::CalcNumberProductPartWithOperator> {});
 
 
     auto first_calc_number_value_or_error = parse_calc_number_value(context, tokens);
     auto first_calc_number_value_or_error = parse_calc_number_value(context, tokens);
     if (!first_calc_number_value_or_error.has_value())
     if (!first_calc_number_value_or_error.has_value())
@@ -2348,7 +2356,9 @@ Optional<CalculatedStyleValue::CalcNumberValue> Parser::parse_calc_number_value(
 
 
 OwnPtr<CalculatedStyleValue::CalcProduct> Parser::parse_calc_product(ParsingContext const& context, TokenStream<StyleComponentValueRule>& tokens)
 OwnPtr<CalculatedStyleValue::CalcProduct> Parser::parse_calc_product(ParsingContext const& context, TokenStream<StyleComponentValueRule>& tokens)
 {
 {
-    auto calc_product = make<CalculatedStyleValue::CalcProduct>();
+    auto calc_product = make<CalculatedStyleValue::CalcProduct>(
+        CalculatedStyleValue::CalcValue(0),
+        NonnullOwnPtrVector<CalculatedStyleValue::CalcProductPartWithOperator> {});
 
 
     auto first_calc_value_or_error = parse_calc_value(context, tokens);
     auto first_calc_value_or_error = parse_calc_value(context, tokens);
     if (!first_calc_value_or_error.has_value())
     if (!first_calc_value_or_error.has_value())