(data []byte)
| 24 | const dumpDebug = false |
| 25 | |
| 26 | func Fuzz(data []byte) int { |
| 27 | // Data contains the program and sample input, separated by SEP. |
| 28 | offset := bytes.Index(data, []byte(SEP)) |
| 29 | if offset < 0 { |
| 30 | // If no SEP, then append one and an empty line of input. |
| 31 | offset = len(data) |
| 32 | data = append(data, []byte(SEP+"\n")...) |
| 33 | } |
| 34 | fmt.Printf("data len %d, offset is %d, input starts at %d\n", len(data), offset, offset+len(SEP)) |
| 35 | |
| 36 | cOpts := []compiler.Option{} |
| 37 | if dumpDebug { |
| 38 | cOpts = append(cOpts, compiler.EmitAst(), compiler.EmitAstTypes()) |
| 39 | } |
| 40 | c, err := compiler.New(cOpts...) |
| 41 | if err != nil { |
| 42 | fmt.Println(err) |
| 43 | return 0 |
| 44 | } |
| 45 | obj, err := c.Compile("fuzz", bytes.NewReader(data[:offset])) |
| 46 | if err != nil { |
| 47 | fmt.Println(err) |
| 48 | return 0 // false |
| 49 | } |
| 50 | v := vm.New("fuzz", obj, false, nil, dumpDebug, dumpDebug) |
| 51 | if dumpDebug { |
| 52 | fmt.Println(v.DumpByteCode()) |
| 53 | } |
| 54 | v.HardCrash = true |
| 55 | scanner := bufio.NewScanner(bytes.NewBuffer(data[offset+len(SEP):])) |
| 56 | for scanner.Scan() { |
| 57 | v.ProcessLogLine(context.Background(), logline.New(context.Background(), "fuzz", scanner.Text())) |
| 58 | } |
| 59 | return 1 |
| 60 | } |
| 61 | |
| 62 | func init() { |
| 63 | // We need to successfully parse flags to initialize the glog logger used |
nothing calls this directly
no test coverage detected