diff options
author | George Marques <george@gmarqu.es> | 2021-04-05 11:17:59 -0300 |
---|---|---|
committer | George Marques <george@gmarqu.es> | 2021-04-28 11:09:40 -0300 |
commit | 9ed0f0384cd73921f2c85d1e030fbb596b0954ea (patch) | |
tree | 294246e6d21fe468982ab78fd698e5ae6ff6e5e7 /modules/gdscript/gdscript_analyzer.cpp | |
parent | c201b212c7d188c15de78c4d4150e9d7337b6983 (diff) | |
download | redot-engine-9ed0f0384cd73921f2c85d1e030fbb596b0954ea.tar.gz |
GDScript: Fix crash when base of an attribute is invalid
In attribute expressions (`a.b`) it's possible that the base has an
incorrect syntax and thus become a nullptr expression in the tree. This
commit add the check for this case to fail gracefully instead of
crashing.
Diffstat (limited to 'modules/gdscript/gdscript_analyzer.cpp')
-rw-r--r-- | modules/gdscript/gdscript_analyzer.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index db554c1ab0..17ae52f3ab 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -2065,6 +2065,12 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool is_awa is_self = true; } else if (callee_type == GDScriptParser::Node::SUBSCRIPT) { GDScriptParser::SubscriptNode *subscript = static_cast<GDScriptParser::SubscriptNode *>(p_call->callee); + if (subscript->base == nullptr) { + // Invalid syntax, error already set on parser. + p_call->set_datatype(call_type); + mark_node_unsafe(p_call); + return; + } if (!subscript->is_attribute) { // Invalid call. Error already sent in parser. // TODO: Could check if Callable here. |