From c17b711751371c4d7c5a7c1b0995747f7e95fddb Mon Sep 17 00:00:00 2001 From: UnexomWid Date: Tue, 8 Dec 2020 10:50:48 +0200 Subject: [PATCH] [FIX] Rare bug caused by conditional stack not popping (#34) --- package-lock.json | 2 +- src/compiler/compiler.cxx | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0b748cf..3fb43c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1195,4 +1195,4 @@ } } } -} +} \ No newline at end of file diff --git a/src/compiler/compiler.cxx b/src/compiler/compiler.cxx index 3479bc6..eb6211b 100644 --- a/src/compiler/compiler.cxx +++ b/src/compiler/compiler.cxx @@ -1393,7 +1393,7 @@ BinaryData compileBytes(const uint8_t* input, size_t inputSize, const char* wd, output.reset(newOutput); } - // This is for the component body, as it requires the content length. + // The output size before writing the conditional end. size_t backup = outputSize; LOG_DEBUG("Writing template body end as BDP832 pair %zu -> %zu...", start - input, end - input); @@ -1404,12 +1404,12 @@ BinaryData compileBytes(const uint8_t* input, size_t inputSize, const char* wd, switch(templateStack.top().type) { case TemplateType::CONDITIONAL: case TemplateType::INVERTED_CONDITIONAL: - // Only write the end index, as there is no else (conditional) template. - BDP::lengthToBytes(output.get() + templateStack.top().bodyIndex - 2 * OSH_FORMAT, outputSize - templateStack.top().bodyIndex, OSH_FORMAT); + BDP::lengthToBytes(output.get() + templateStack.top().bodyIndex - 2 * OSH_FORMAT, backup - templateStack.top().bodyIndex, OSH_FORMAT); + BDP::lengthToBytes(output.get() + templateStack.top().bodyIndex - OSH_FORMAT, outputSize - backup, OSH_FORMAT); // Jumps at the end. break; case TemplateType::ELSE_CONDITIONAL: case TemplateType::ELSE: { - size_t currentEndIndex = outputSize - Global::BDP832->VALUE_LENGTH_BYTE_SIZE - bodyEndMarkerLength - Global::BDP832->NAME_LENGTH_BYTE_SIZE; // For the end index. The true end index will always be fixed. + size_t currentEndIndex = backup; // For the end index. The true end index will always be fixed. bool searching = true;