From 66c2eb6041f6970d616822e58dff00ac70d0fdce Mon Sep 17 00:00:00 2001 From: ltzmaxwell Date: Sun, 8 Dec 2024 05:01:51 +0800 Subject: [PATCH] fix(gnovm): make `Stacktrace` correctly handle panics with `len(Stmts) == 0` (#3273) While finalizing the realm, all statements in the machine have been popped out. A necessary check must be performed during stack trace handling.
Contributors' checklist... - [ ] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [ ] Updated the official documentation or not needed - [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [ ] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests
Co-authored-by: Petar Dambovaliev --- gnovm/pkg/gnolang/machine.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 4f4c7c188f3..b48c0742e6f 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -401,7 +401,7 @@ func destar(x Expr) Expr { // Stacktrace returns the stack trace of the machine. // It collects the executions and frames from the machine's frames and statements. func (m *Machine) Stacktrace() (stacktrace Stacktrace) { - if len(m.Frames) == 0 { + if len(m.Frames) == 0 || len(m.Stmts) == 0 { return }