Skip to content

Commit

Permalink
[FIX] Rare bug caused by conditional stack not popping (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
UnexomWid committed Dec 8, 2020
1 parent f354ee8 commit c17b711
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/compiler/compiler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand Down

0 comments on commit c17b711

Please sign in to comment.