Skip to content

Commit 7162117

Browse files
committed
fix(gnovm): missing mapList size reset
1 parent 96781b2 commit 7162117

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

gnovm/pkg/gnolang/values.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,17 +655,18 @@ func (ml MapList) MarshalAmino() (MapListImage, error) {
655655
}
656656

657657
func (ml *MapList) UnmarshalAmino(mlimg MapListImage) error {
658-
for _, item := range mlimg.List {
659-
if ml.Head == nil {
658+
for i, item := range mlimg.List {
659+
if i == 0 {
660660
item.Prev = nil
661661
ml.Head = item
662662
ml.Tail = item
663+
ml.Size = 1
663664
} else {
664665
item.Prev = ml.Tail
665666
ml.Tail.Next = item
666667
ml.Tail = item
668+
ml.Size++
667669
}
668-
ml.Size++
669670
}
670671
return nil
671672
}
@@ -682,16 +683,20 @@ func (ml *MapList) Append(alloc *Allocator, key TypedValue) *MapListItem {
682683
item.Prev = nil
683684
ml.Head = item
684685
ml.Tail = item
686+
ml.Size = 1
685687
} else {
686688
item.Prev = ml.Tail
687689
ml.Tail.Next = item
688690
ml.Tail = item
691+
ml.Size++
689692
}
690-
ml.Size++
691693
return item
692694
}
693695

694696
func (ml *MapList) Remove(mli *MapListItem) {
697+
if ml.Size == 0 {
698+
return
699+
}
695700
prev, next := mli.Prev, mli.Next
696701
if prev == nil {
697702
ml.Head = next

0 commit comments

Comments
 (0)