Skip to content

Commit

Permalink
fix(gnovm): don't assert to bodyStmt when creating stacktraces (#3836)
Browse files Browse the repository at this point in the history
Stacktraces being generated when executing a known statement, like the
initialization of an if statement, will have the panicking statement at
the top of the Stmt stack, which may not be a bodyStmt. This PR fixes
the incorrect assertion.
  • Loading branch information
thehowl authored Feb 26, 2025
1 parent d7ce169 commit 05d8890
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions gnovm/pkg/gnolang/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,9 @@ func (m *Machine) Stacktrace() (stacktrace Stacktrace) {
for i := len(m.Frames) - 1; i >= 0; i-- {
if m.Frames[i].IsCall() {
stm := m.Stmts[nextStmtIndex]
bs := stm.(*bodyStmt)
stm = bs.Body[bs.NextBodyIndex-1]
if bs, ok := stm.(*bodyStmt); ok {
stm = bs.Body[bs.NextBodyIndex-1]
}
calls = append(calls, StacktraceCall{
Stmt: stm,
Frame: m.Frames[i],
Expand Down
16 changes: 16 additions & 0 deletions gnovm/tests/files/recover20.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

func main() {
var p *int
if i := *p; i == 0 {
println("hey")
}
}

// Error:
// nil pointer dereference

// Stacktrace:
// panic: nil pointer dereference
// main<VPBlock(1,0)>()
// main/files/recover20.gno:5

0 comments on commit 05d8890

Please sign in to comment.