Skip to content

Commit

Permalink
fix(gnovm): forbid star expression when value is nil (#3053)
Browse files Browse the repository at this point in the history
close: #3052 
<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [ ] 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
</details>
  • Loading branch information
omarsy authored Oct 30, 2024
1 parent e9640ef commit 8ec556e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,9 @@ func preprocess1(store Store, ctx BlockNode, n Node) Node {
// TRANS_LEAVE -----------------------
case *StarExpr:
xt := evalStaticTypeOf(store, last, n.X)
if xt == nil {
panic(fmt.Sprintf("invalid operation: cannot indirect nil"))
}
if xt.Kind() != PointerKind && xt.Kind() != TypeKind {
panic(fmt.Sprintf("invalid operation: cannot indirect %s (variable of type %s)", n.X.String(), xt.String()))
}
Expand Down
8 changes: 8 additions & 0 deletions gnovm/tests/files/ptr10.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

func main() {
println(*nil)
}

// Error:
// main/files/ptr10.gno:4:10: invalid operation: cannot indirect nil

0 comments on commit 8ec556e

Please sign in to comment.