From 6486380dd1983d5440866356e20463315bceb5b4 Mon Sep 17 00:00:00 2001 From: Chronos Ouroboros Date: Fri, 14 Feb 2020 22:25:18 -0300 Subject: [PATCH] Fixed a crash when trying to include a missing mixin. --- src/scripting/zscript/zcc_compile.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 887c8ab68..316e39f37 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -100,8 +100,6 @@ FString ZCCCompiler::StringConstFromNode(ZCC_TreeNode *node, PContainerType *cls ZCC_MixinDef *ZCCCompiler::ResolveMixinStmt(ZCC_MixinStmt *mixinStmt, EZCCMixinType type) { - ZCC_MixinDef *mixinDef = nullptr; - for (auto mx : Mixins) { if (mx->mixin->NodeName == mixinStmt->MixinName) @@ -109,18 +107,16 @@ ZCC_MixinDef *ZCCCompiler::ResolveMixinStmt(ZCC_MixinStmt *mixinStmt, EZCCMixinT if (mx->mixin->MixinType != type) { Error(mixinStmt, "Mixin %s is a %s mixin cannot be used here.", FName(mixinStmt->MixinName).GetChars(), GetMixinTypeString(type)); + return nullptr; } return mx->mixin; } } - if (mixinDef == nullptr) - { - Error(mixinStmt, "Mixin %s does not exist.", FName(mixinStmt->MixinName).GetChars()); - } + Error(mixinStmt, "Mixin %s does not exist.", FName(mixinStmt->MixinName).GetChars()); - return mixinDef; + return nullptr; } @@ -163,6 +159,7 @@ void ZCCCompiler::ProcessClass(ZCC_Class *cnode, PSymbolTreeNode *treenode) // [pbeta] Handle mixins here for the sake of simplifying things. if (node != nullptr) { + bool mixinError = false; TArray mixinStmts; mixinStmts.Clear(); @@ -182,6 +179,12 @@ void ZCCCompiler::ProcessClass(ZCC_Class *cnode, PSymbolTreeNode *treenode) { ZCC_MixinDef *mixinDef = ResolveMixinStmt(mixinStmt, ZCC_Mixin_Class); + if (mixinDef == nullptr) + { + mixinError = true; + continue; + } + // Insert the mixin if there's a body. If not, just remove this node. if (mixinDef->Body != nullptr) { @@ -230,6 +233,11 @@ void ZCCCompiler::ProcessClass(ZCC_Class *cnode, PSymbolTreeNode *treenode) } mixinStmts.Clear(); + + if (mixinError) + { + return; + } } node = cnode->Body;