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

Refactor IteratorReference #501

Merged
merged 7 commits into from
Feb 23, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use math.MaxInt32
webmaster128 committed Feb 23, 2024
commit bd8c932afcfb6beb0b3ca94326e7df3f1a33cc79
10 changes: 3 additions & 7 deletions internal/api/iterator.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package api

import (
"fmt"
"math"
"sync"

"github.com/CosmWasm/wasmvm/v2/types"
@@ -99,15 +100,10 @@ func retrieveIterator(callID uint64, iteratorID uint64) types.Iterator {
return myFrame[indexInFrame]
}

const (
INT32_MAX_AS_UINT64 uint64 = 2147483647
INT32_MAX_AS_INT int = 2147483647
)

// iteratorIdToIndex converts an iterator ID to an index in the frame.
// The second value marks if the conversion succeeded.
func iteratorIdToIndex(id uint64) (int, bool) {
if id < 1 || id > INT32_MAX_AS_UINT64 {
if id < 1 || id > math.MaxInt32 {
return 777777777, false
}

@@ -118,7 +114,7 @@ func iteratorIdToIndex(id uint64) (int, bool) {
// indexToIteratorID converts an index in the frame to an iterator ID.
// The second value marks if the conversion succeeded.
func indexToIteratorID(index int) (uint64, bool) {
if index < 0 || index > INT32_MAX_AS_INT {
if index < 0 || index > math.MaxInt32 {
return 888888888, false
chipshort marked this conversation as resolved.
Show resolved Hide resolved
}