summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2021-09-03 19:11:51 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-03 23:20:23 +0200
commitd7b6cc6421c48185f4dfafb24d2b093b86305860 (patch)
tree7e5ace9318b73d4efe095c43605cd514db1cccaa /Userland
parentbad23e3f8cc9c66d818ddb2f7bbe7bddce5c09e2 (diff)
downloadserenity-d7b6cc6421c48185f4dfafb24d2b093b86305860.zip
Everywhere: Prevent risky implicit casts of (Nonnull)RefPtr
Our existing implementation did not check the element type of the other pointer in the constructors and move assignment operators. This meant that some operations that would require explicit casting on raw pointers were done implicitly, such as: - downcasting a base class to a derived class (e.g. `Kernel::Inode` => `Kernel::ProcFSDirectoryInode` in Kernel/ProcFS.cpp), - casting to an unrelated type (e.g. `Promise<bool>` => `Promise<Empty>` in LibIMAP/Client.cpp) This, of course, allows gross violations of the type system, and makes the need to type-check less obvious before downcasting. Luckily, while adding the `static_ptr_cast`s, only two truly incorrect usages were found; in the other instances, our casts just needed to be made explicit.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp2
-rw-r--r--Userland/Libraries/LibGL/Tex/TextureUnit.cpp2
-rw-r--r--Userland/Libraries/LibIMAP/Client.cpp2
-rw-r--r--Userland/Libraries/LibIMAP/Client.h2
-rw-r--r--Userland/Libraries/LibJS/Parser.cpp2
-rw-r--r--Userland/Libraries/LibJS/Parser.h2
-rw-r--r--Userland/Libraries/LibPDF/Document.cpp2
-rw-r--r--Userland/Libraries/LibPDF/Object.h2
-rw-r--r--Userland/Libraries/LibSQL/AST/Parser.cpp2
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp10
-rw-r--r--Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp2
-rw-r--r--Userland/Shell/Parser.cpp2
-rw-r--r--Userland/Shell/Parser.h2
13 files changed, 17 insertions, 17 deletions
diff --git a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp
index 5d2abc435e..fcad4a05e3 100644
--- a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp
+++ b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp
@@ -220,7 +220,7 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
};
m_tab_widget->on_context_menu_request = [&](auto& widget, auto& event) {
- m_tab_context_menu_sheet_view = widget;
+ m_tab_context_menu_sheet_view = static_cast<SpreadsheetView&>(widget);
m_tab_context_menu->popup(event.screen_position());
};
}
diff --git a/Userland/Libraries/LibGL/Tex/TextureUnit.cpp b/Userland/Libraries/LibGL/Tex/TextureUnit.cpp
index 8b4f487045..b8a180c447 100644
--- a/Userland/Libraries/LibGL/Tex/TextureUnit.cpp
+++ b/Userland/Libraries/LibGL/Tex/TextureUnit.cpp
@@ -13,7 +13,7 @@ void TextureUnit::bind_texture_to_target(GLenum texture_target, const RefPtr<Tex
{
switch (texture_target) {
case GL_TEXTURE_2D:
- m_texture_target_2d = texture;
+ m_texture_target_2d = static_ptr_cast<Texture2D>(texture);
m_currently_bound_texture = texture;
m_currently_bound_target = GL_TEXTURE_2D;
break;
diff --git a/Userland/Libraries/LibIMAP/Client.cpp b/Userland/Libraries/LibIMAP/Client.cpp
index 9b63733e14..7b1bef5a8e 100644
--- a/Userland/Libraries/LibIMAP/Client.cpp
+++ b/Userland/Libraries/LibIMAP/Client.cpp
@@ -31,7 +31,7 @@ RefPtr<Promise<Empty>> Client::connect()
}
if (!success)
return {};
- m_connect_pending = Promise<bool>::construct();
+ m_connect_pending = Promise<Empty>::construct();
return m_connect_pending;
}
diff --git a/Userland/Libraries/LibIMAP/Client.h b/Userland/Libraries/LibIMAP/Client.h
index 3fb9095dbd..cea34fe37c 100644
--- a/Userland/Libraries/LibIMAP/Client.h
+++ b/Userland/Libraries/LibIMAP/Client.h
@@ -69,7 +69,7 @@ private:
// Not yet sent
Vector<Command> m_command_queue {};
- RefPtr<Promise<bool>> m_connect_pending {};
+ RefPtr<Promise<Empty>> m_connect_pending {};
ByteBuffer m_buffer;
Parser m_parser;
diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp
index c2cf37f9dc..7a3437915f 100644
--- a/Userland/Libraries/LibJS/Parser.cpp
+++ b/Userland/Libraries/LibJS/Parser.cpp
@@ -1606,7 +1606,7 @@ NonnullRefPtr<Identifier> Parser::parse_identifier()
token.value());
}
-NonnullRefPtr<CallExpression> Parser::parse_call_expression(NonnullRefPtr<Expression> lhs)
+NonnullRefPtr<Expression> Parser::parse_call_expression(NonnullRefPtr<Expression> lhs)
{
auto rule_start = push_start();
if (!m_state.allow_super_constructor_call && is<SuperExpression>(*lhs))
diff --git a/Userland/Libraries/LibJS/Parser.h b/Userland/Libraries/LibJS/Parser.h
index 41b6cef2c8..b594b64040 100644
--- a/Userland/Libraries/LibJS/Parser.h
+++ b/Userland/Libraries/LibJS/Parser.h
@@ -85,7 +85,7 @@ public:
NonnullRefPtr<StringLiteral> parse_string_literal(const Token& token, bool in_template_literal = false);
NonnullRefPtr<TemplateLiteral> parse_template_literal(bool is_tagged);
NonnullRefPtr<Expression> parse_secondary_expression(NonnullRefPtr<Expression>, int min_precedence, Associativity associate = Associativity::Right);
- NonnullRefPtr<CallExpression> parse_call_expression(NonnullRefPtr<Expression>);
+ NonnullRefPtr<Expression> parse_call_expression(NonnullRefPtr<Expression>);
NonnullRefPtr<NewExpression> parse_new_expression();
NonnullRefPtr<ClassDeclaration> parse_class_declaration();
NonnullRefPtr<ClassExpression> parse_class_expression(bool expect_class_name);
diff --git a/Userland/Libraries/LibPDF/Document.cpp b/Userland/Libraries/LibPDF/Document.cpp
index 473b5f5a20..582a1c90f9 100644
--- a/Userland/Libraries/LibPDF/Document.cpp
+++ b/Userland/Libraries/LibPDF/Document.cpp
@@ -146,7 +146,7 @@ Value Document::resolve(Value const& value)
auto obj = value.as_object();
if (obj->is_indirect_value())
- return static_cast<NonnullRefPtr<IndirectValue>>(obj)->value();
+ return static_ptr_cast<IndirectValue>(obj)->value();
return obj;
}
diff --git a/Userland/Libraries/LibPDF/Object.h b/Userland/Libraries/LibPDF/Object.h
index 47d0794de6..d7673e8ca5 100644
--- a/Userland/Libraries/LibPDF/Object.h
+++ b/Userland/Libraries/LibPDF/Object.h
@@ -248,7 +248,7 @@ template<IsObject To, IsObject From>
# undef ENUMERATE_TYPES
#endif
- return static_cast<NonnullRefPtr<To>>(obj);
+ return static_ptr_cast<To>(obj);
}
}
diff --git a/Userland/Libraries/LibSQL/AST/Parser.cpp b/Userland/Libraries/LibSQL/AST/Parser.cpp
index 6230a0f91c..d7c728a9ff 100644
--- a/Userland/Libraries/LibSQL/AST/Parser.cpp
+++ b/Userland/Libraries/LibSQL/AST/Parser.cpp
@@ -210,7 +210,7 @@ NonnullRefPtr<Insert> Parser::parse_insert_statement(RefPtr<CommonTableExpressio
if ((column_names.size() > 0) && (chained_expr->expressions().size() != column_names.size())) {
syntax_error("Number of expressions does not match number of columns");
} else {
- chained_expressions.append(chained_expression.release_nonnull());
+ chained_expressions.append(static_ptr_cast<ChainedExpression>(chained_expression.release_nonnull()));
}
} else {
expected("Chained expression");
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp
index 93bc19b5bf..f84057cbec 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp
@@ -72,7 +72,7 @@ NonnullRefPtr<HTMLTableCaptionElement> HTMLTableElement::create_caption()
auto caption = DOM::create_element(document(), TagNames::caption, Namespace::HTML);
pre_insert(caption, first_child());
- return caption;
+ return static_ptr_cast<HTMLTableCaptionElement>(caption);
}
void HTMLTableElement::delete_caption()
@@ -159,7 +159,7 @@ NonnullRefPtr<HTMLTableSectionElement> HTMLTableElement::create_t_head()
pre_insert(thead, child_to_append_after);
- return thead;
+ return static_ptr_cast<HTMLTableSectionElement>(thead);
}
void HTMLTableElement::delete_t_head()
@@ -209,7 +209,7 @@ NonnullRefPtr<HTMLTableSectionElement> HTMLTableElement::create_t_foot()
auto tfoot = DOM::create_element(document(), TagNames::tfoot, Namespace::HTML);
append_child(tfoot);
- return tfoot;
+ return static_ptr_cast<HTMLTableSectionElement>(tfoot);
}
void HTMLTableElement::delete_t_foot()
@@ -248,7 +248,7 @@ NonnullRefPtr<HTMLTableSectionElement> HTMLTableElement::create_t_body()
pre_insert(tbody, child_to_append_after);
- return tbody;
+ return static_ptr_cast<HTMLTableSectionElement>(tbody);
}
NonnullRefPtr<DOM::HTMLCollection> HTMLTableElement::rows()
@@ -287,7 +287,7 @@ DOM::ExceptionOr<NonnullRefPtr<HTMLTableRowElement>> HTMLTableElement::insert_ro
if (index < -1 || index >= (long)rows_length) {
return DOM::IndexSizeError::create("Index is negative or greater than the number of rows");
}
- auto tr = static_cast<NonnullRefPtr<HTMLTableRowElement>>(DOM::create_element(document(), TagNames::tr, Namespace::HTML));
+ auto tr = static_ptr_cast<HTMLTableRowElement>(DOM::create_element(document(), TagNames::tr, Namespace::HTML));
if (rows_length == 0 && !has_child_of_type<HTMLTableRowElement>()) {
auto tbody = DOM::create_element(document(), TagNames::tbody, Namespace::HTML);
tbody->append_child(tr);
diff --git a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp
index 74b52e9b41..955416f9a9 100644
--- a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp
+++ b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp
@@ -166,7 +166,7 @@ void TreeBuilder::remove_irrelevant_boxes(NodeWithStyle& root)
{
// The following boxes are discarded as if they were display:none:
- NonnullRefPtrVector<Box> to_remove;
+ NonnullRefPtrVector<Node> to_remove;
// Children of a table-column.
for_each_in_tree_with_display<CSS::Display::TableColumn>(root, [&](Box& table_column) {
diff --git a/Userland/Shell/Parser.cpp b/Userland/Shell/Parser.cpp
index 68ff39accf..260fffbcdd 100644
--- a/Userland/Shell/Parser.cpp
+++ b/Userland/Shell/Parser.cpp
@@ -1431,7 +1431,7 @@ RefPtr<AST::Node> Parser::parse_variable_ref()
return create<AST::SimpleVariable>(move(name)); // Variable Simple
}
-RefPtr<AST::Node> Parser::parse_slice()
+RefPtr<AST::Slice> Parser::parse_slice()
{
auto rule_start = push_start();
if (!next_is("["))
diff --git a/Userland/Shell/Parser.h b/Userland/Shell/Parser.h
index 2c11d23a92..37aac4097f 100644
--- a/Userland/Shell/Parser.h
+++ b/Userland/Shell/Parser.h
@@ -85,7 +85,7 @@ private:
RefPtr<AST::Node> parse_string_inner(StringEndCondition);
RefPtr<AST::Node> parse_variable();
RefPtr<AST::Node> parse_variable_ref();
- RefPtr<AST::Node> parse_slice();
+ RefPtr<AST::Slice> parse_slice();
RefPtr<AST::Node> parse_evaluate();
RefPtr<AST::Node> parse_history_designator();
RefPtr<AST::Node> parse_comment();