diff options
| author | Veronica Radu <veronicaradu@google.com> | 2019-09-11 18:20:17 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2019-09-23 15:33:19 +0200 |
| commit | bf7e28925b8894ca13f803f66d16cf2b0ae12430 (patch) | |
| tree | 5e25e384f1b97ff2f3fda580dd2ac2fe6fb43d91 /prog/mutation.go | |
| parent | d96e88f3207d7ac7ad65e13b896f702ad04c46f7 (diff) | |
prog: use type size when generating/mutating ints
Update #1381
Diffstat (limited to 'prog/mutation.go')
| -rw-r--r-- | prog/mutation.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/prog/mutation.go b/prog/mutation.go index 1031217b4..b0702ebba 100644 --- a/prog/mutation.go +++ b/prog/mutation.go @@ -258,6 +258,7 @@ func mutateInt(r *randGen, s *state, arg Arg) (calls []*Call, retry, preserve bo if r.bin() { return regenerate(r, s, arg) } + bits := arg.Type().TypeBitSize() a := arg.(*ConstArg) switch { case r.nOutOf(1, 3): @@ -265,8 +266,9 @@ func mutateInt(r *randGen, s *state, arg Arg) (calls []*Call, retry, preserve bo case r.nOutOf(1, 2): a.Val -= uint64(r.Intn(4)) + 1 default: - a.Val ^= 1 << uint64(r.Intn(64)) + a.Val ^= 1 << uint64(r.Intn(int(bits))) } + a.Val = truncateToBitSize(a.Val, bits) return } @@ -706,7 +708,7 @@ var mutateDataFuncs = [...]func(r *randGen, data []byte, minLen, maxLen uint64) return data, false } i := r.Intn(len(data) - width + 1) - value := r.randInt() + value := r.randInt64() if r.oneOf(10) { value = swap64(value) } |
