From bf7e28925b8894ca13f803f66d16cf2b0ae12430 Mon Sep 17 00:00:00 2001 From: Veronica Radu Date: Wed, 11 Sep 2019 18:20:17 +0200 Subject: prog: use type size when generating/mutating ints Update #1381 --- prog/mutation.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'prog/mutation.go') 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) } -- cgit mrf-deployment