Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: demonstrate ownership bug #4

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/gno.land/r/demo/bugs/mis_ownership/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module "gno.land/r/demo/bugs/mis_ownership"

require (
"gno.land/r/demo/bugs/steal_ownership" v0.0.0-latest
)
12 changes: 12 additions & 0 deletions examples/gno.land/r/demo/bugs/mis_ownership/mis_ownership.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package mis_ownership

import "gno.land/r/demo/bugs/steal_ownership"

var (
x = uint32(42)
ptr = &x
)

func init() {
steal_ownership.Steal(ptr)
}
17 changes: 17 additions & 0 deletions examples/gno.land/r/demo/bugs/mis_ownership/mis_ownership_test.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package mis_ownership

import (
"testing"
)

func TestMisOwnership(t *testing.T) {
// by value
x = 21

// deref
*ptr = 21

// pointer change
nv := uint32(21)
ptr = &nv
}
1 change: 1 addition & 0 deletions examples/gno.land/r/demo/bugs/steal_ownership/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module "gno.land/r/demo/bugs/steal_ownership"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package steal_ownership

var ptr *uint32

func Steal(xptr *uint32) {
ptr = xptr
}