aboutsummaryrefslogtreecommitdiffstats
path: root/prog/size.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-11-27 08:59:37 +0100
committerDmitry Vyukov <dvyukov@google.com>2017-12-31 12:29:08 +0100
commit71ed63015c8a77b1278197f6a0c472bbfef6d12f (patch)
tree15c2b365f6f2ee30c2e694cec1953b08f5c0c01c /prog/size.go
parent6bfd4f1979d582602a91ee57865e588ffed41ab5 (diff)
prog: mutate len arguments
Fixes #183
Diffstat (limited to 'prog/size.go')
-rw-r--r--prog/size.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/prog/size.go b/prog/size.go
index 718e0c426..5dd1310b4 100644
--- a/prog/size.go
+++ b/prog/size.go
@@ -106,3 +106,58 @@ func (target *Target) assignSizesArray(args []Arg) {
func (target *Target) assignSizesCall(c *Call) {
target.assignSizesArray(c.Args)
}
+
+func (r *randGen) mutateSize(arg *ConstArg, parent []Arg) bool {
+ typ := arg.Type().(*LenType)
+ elemSize := typ.ByteSize
+ if elemSize == 0 {
+ elemSize = 1
+ for _, field := range parent {
+ if typ.Buf != field.Type().FieldName() {
+ continue
+ }
+ if inner := InnerArg(field); inner != nil {
+ switch targetType := inner.Type().(type) {
+ case *VmaType:
+ return false
+ case *ArrayType:
+ elemSize = targetType.Type.Size()
+ }
+ }
+ break
+ }
+ }
+ if r.oneOf(100) {
+ arg.Val = r.rand64()
+ return true
+ }
+ if r.bin() {
+ // Small adjustment to trigger missed size checks.
+ if arg.Val != 0 && r.bin() {
+ arg.Val = r.randRangeInt(0, arg.Val-1)
+ } else {
+ arg.Val = r.randRangeInt(arg.Val+1, arg.Val+1000)
+ }
+ return true
+ }
+ // Try to provoke int overflows.
+ max := ^uint64(0)
+ if r.oneOf(3) {
+ max = 1<<32 - 1
+ if r.oneOf(2) {
+ max = 1<<16 - 1
+ if r.oneOf(2) {
+ max = 1<<8 - 1
+ }
+ }
+ }
+ n := max / elemSize
+ delta := uint64(1000 - r.biasedRand(1000, 10))
+ if elemSize == 1 || r.oneOf(10) {
+ n -= delta
+ } else {
+ n += delta
+ }
+ arg.Val = n
+ return true
+}