From 381aaa1509aaa062df052c4e1be40f1073048b73 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Wed, 11 Sep 2024 13:13:40 +0200 Subject: [PATCH] Fix compiler crash with empty switch statement --- oscar64/InterCodeGenerator.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index 015d3e0..f384eec 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -5302,16 +5302,19 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* sexp = sexp->mRight; } - int i = 1, j = 1; - while (i < switchNodes.Size()) + if (switchNodes.Size() > 0) { - if (switchNodes[i].mBlock == switchNodes[j - 1].mBlock && switchNodes[i].mLower == switchNodes[j - 1].mUpper + 1) - switchNodes[j - 1].mUpper = switchNodes[i].mUpper; - else - switchNodes[j++] = switchNodes[i]; - i++; + int i = 1, j = 1; + while (i < switchNodes.Size()) + { + if (switchNodes[i].mBlock == switchNodes[j - 1].mBlock && switchNodes[i].mLower == switchNodes[j - 1].mUpper + 1) + switchNodes[j - 1].mUpper = switchNodes[i].mUpper; + else + switchNodes[j++] = switchNodes[i]; + i++; + } + switchNodes.SetSize(j); } - switchNodes.SetSize(j); BuildSwitchTree(proc, exp, sblock, inlineMapper, vl, switchNodes, 0, switchNodes.Size(), vleft, vright, dblock ? dblock : eblock);