Restrict global and function references to memory size
This commit is contained in:
@@ -12,10 +12,10 @@ func randOperand(t vm.OperandNumericType) *vm.Operand {
|
||||
|
||||
switch op.Type {
|
||||
case vm.GlobalMemoryIndex:
|
||||
op.Value = RandBiasedUint64()
|
||||
op.Value = RandBiasedUint64n(vm.GlobalMemorySize)
|
||||
|
||||
case vm.FunctionMemoryIndex:
|
||||
op.Value = RandBiasedUint64()
|
||||
op.Value = RandBiasedUint64n(vm.FunctionMemorySize)
|
||||
|
||||
case vm.Literal:
|
||||
switch t {
|
||||
|
||||
10
gen/rand.go
10
gen/rand.go
@@ -9,6 +9,16 @@ func RandBiasedUint64() uint64 {
|
||||
return (rand.Uint64() | 0x8000000000000000) >> rand.Intn(65)
|
||||
}
|
||||
|
||||
// Like RandBiasedUint64() but always returns < n
|
||||
func RandBiasedUint64n(n uint64) uint64 {
|
||||
for {
|
||||
ret := RandBiasedUint64()
|
||||
if ret < n {
|
||||
return ret
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generate a random int64 with an even distribution of the tuple
|
||||
// {sign, bits.Len64(math.Abs())}
|
||||
func RandBiasedInt64() uint64 {
|
||||
|
||||
Reference in New Issue
Block a user