forked from dvyukov/go-fuzz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (38 loc) · 1.09 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2015 Dmitry Vyukov. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package fmt
import (
"fmt"
"reflect"
)
func Fuzz(data []byte) int {
f := string(data[:len(data)/2])
s := string(data[len(data)/2:])
for _, ctor := range []func() interface{}{
func() interface{} { return new(int) },
func() interface{} { return new(byte) },
func() interface{} { return new(uint16) },
func() interface{} { return new(int16) },
func() interface{} { return new(string) },
func() interface{} { return new(float32) },
func() interface{} { return new(float64) },
func() interface{} { return new(string) },
func() interface{} { return new(complex128) },
func() interface{} { return new([]int) },
func() interface{} { return new([][]string) },
func() interface{} { m := make(map[int]float64); return &m },
func() interface{} {
return &struct {
A int
B float64
C string
D []int
}{}
},
} {
v := ctor()
fmt.Sscanf(s, f, v)
fmt.Sprintf(f, reflect.ValueOf(v).Elem().Interface())
}
return 0
}