[libFuzzer] move the mutators to public interface so that custom mutators may reuse...
[oota-llvm.git] / lib / Fuzzer / test / StrcmpTest.cpp
1 // Break through a series of strcmp.
2 #include <cstring>
3 #include <cstdint>
4 #include <cstdio>
5 #include <cstdlib>
6 #include <cassert>
7
8 bool Eq(const uint8_t *Data, size_t Size, const char *Str) {
9   char Buff[1024];
10   size_t Len = strlen(Str);
11   if (Size < Len) return false;
12   if (Len >= sizeof(Buff)) return false;
13   memcpy(Buff, (char*)Data, Len);
14   Buff[Len] = 0;
15   int res = strcmp(Buff, Str);
16   return res == 0;
17 }
18
19 extern "C" void LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
20   if (Eq(Data, Size, "AAA") &&
21       Size >= 3 && Eq(Data + 3, Size - 3, "BBBB") &&
22       Size >= 7 && Eq(Data + 7, Size - 7, "CCCCCC") &&
23       Size >= 14 && Data[13] == 42
24     ) {
25     fprintf(stderr, "BINGO\n");
26     exit(1);
27   }
28 }