Debian Codegraph @

tests/thirdparty/Fuzzer/test/Switch2Test.cpp

raw
1 // This file is distributed under the University of Illinois Open Source
2 // License. See LICENSE.TXT for details.
3
4 // Simple test for a fuzzer. The fuzzer must find the interesting switch value.
5 #include <cstdint>
6 #include <cstdlib>
7 #include <cstdio>
8 #include <cstring>
9 #include <cstddef>
10
11 int Switch(int a) {
12 switch(a) {
13 case 100001: return 1;
14 case 100002: return 2;
15 case 100003: return 4;
16 }
17 return 0;
18 }
19
20 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
21 const int N = 3;
22 if (Size < N * sizeof(int)) return 0;
23 int Res = 0;
24 for (int i = 0; i < N; i++) {
25 int X;
26 memcpy(&X, Data + i * sizeof(int), sizeof(int));
27 Res += Switch(X);
28 }
29 if (Res == 5 || Res == 3 || Res == 6 || Res == 7) {
30 fprintf(stderr, "BINGO; Found the target, exiting; Res=%d\n", Res);
31 exit(1);
32 }
33 return 0;
34 }
35