This repository has been archived by the owner on May 11, 2020. It is now read-only.
disasm: fix if-else bug causing stack underflow error #104
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here is a test case to trigger a bug (wasm file included):
And here is the trace with
SetDebugMode(true)
indisasm/log.go
:The underflow error is thrown here, because
curDepth
is 1 andprevDepth
is 3:wagon/disasm/disasm.go
Lines 196 to 198 in fde98f7
prevDepth
is the number of stack elements before entering the if block. The problem is that the stack depth when entering the if-else block should be the same as when entering the if-then block (3 stack elements). The bug is pushing a stack depth of 0 when entering the if-else block. The stack depth when entering the if-else block is the same as when entering the if-then block, so the fix is to push the same stack depth for if-else as done for if-then.