Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / fuzzer / StrcmpTest.cpp
blob86d42d21ded377d57ad06ff170b03c52cc5c8e5b
1 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2 // See https://llvm.org/LICENSE.txt for license information.
3 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 // Break through a series of strcmp.
6 #include <cassert>
7 #include <cstdint>
8 #include <cstdio>
9 #include <cstdlib>
10 #include <cstring>
12 bool Eq(const uint8_t *Data, size_t Size, const char *Str) {
13 char Buff[1024];
14 size_t Len = strlen(Str);
15 if (Size < Len) return false;
16 if (Len >= sizeof(Buff)) return false;
17 memcpy(Buff, (const char*)Data, Len);
18 Buff[Len] = 0;
19 int res = strcmp(Buff, Str);
20 return res == 0;
23 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
24 if (Eq(Data, Size, "ABC") &&
25 Size >= 3 && Eq(Data + 3, Size - 3, "QWER") &&
26 Size >= 7 && Eq(Data + 7, Size - 7, "ZXCVN")) {
27 fprintf(stderr, "BINGO\n");
28 exit(1);
30 return 0;