Skip to content

Commit

Permalink
Set capacity to length before storing value
Browse files Browse the repository at this point in the history
So I think we can state that the bugs we have in gnolang#960, gnolang#1167 and gnolang#1170,
are all related to slice storage when its capacity is different than its
length.

@deelawn found a great way to overcome that bug, but the bug is still
there, somewhere in the VM code I think. I spent the last couple of days
trying to find it, unfortunately without success.

That said, I found a workaround, that could be also applied: when a
slice is stored, ignore any capacity different than the slice's length.

I think this is a good workaround because its one-line and because we
don't really care about storing slice with capacity higher than their
length (unless I'm missing something).
  • Loading branch information
tbruyelle committed Nov 1, 2023
1 parent cec8f0d commit 71b27ee
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gnovm/pkg/gnolang/realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,9 @@ func copyValueWithRefs(parent Object, val Value) Value {
Base: toRefValue(parent, cv.Base),
Offset: cv.Offset,
Length: cv.Length,
Maxcap: cv.Maxcap,
// Force capacity to length, because we have issues with store when they
// are differents.
Maxcap: cv.Length,
}
case *StructValue:
fields := make([]TypedValue, len(cv.Fields))
Expand Down

0 comments on commit 71b27ee

Please sign in to comment.