From b74c374a668c7ccbf03372c3d1c24e502cc32d76 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 5 Jan 2017 11:39:29 +0100 Subject: [PATCH] - fixed: The CheckReturn check for FxSwitchStatement was not strict enough. It may only return true if there is no default case because without that any non-matching value will go past the statement. --- src/scripting/codegeneration/codegen.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/scripting/codegeneration/codegen.cpp b/src/scripting/codegeneration/codegen.cpp index dc28f953c..ed0c27270 100644 --- a/src/scripting/codegeneration/codegen.cpp +++ b/src/scripting/codegeneration/codegen.cpp @@ -8926,15 +8926,20 @@ ExpEmit FxSwitchStatement::Emit(VMFunctionBuilder *build) bool FxSwitchStatement::CheckReturn() { - //A switch statement returns when it contains no breaks and ends with a return + bool founddefault = false; + //A switch statement returns when it contains a no breaks, a default case, and ends with a return for (auto line : Content) { if (line->ExprType == EFX_JumpStatement) { return false; // Break means that the end of the statement will be reached, Continue cannot happen in the last statement of the last block. } + else if (line->ExprType == EFX_CaseStatement) + { + if (static_cast(line)->Condition == nullptr) founddefault = true; + } } - return Content.Size() > 0 && Content.Last()->CheckReturn(); + return founddefault && Content.Size() > 0 && Content.Last()->CheckReturn(); } //==========================================================================