Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / fuzzing / string / strcpy_fuzz.cpp
blobc15649aa07ecd8e67d3fbf53af41ffe49f5b47b9
1 //===-- strcpy_fuzz.cpp ---------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// Fuzzing test for llvm-libc strcpy implementation.
10 ///
11 //===----------------------------------------------------------------------===//
12 #include "src/string/strcpy.h"
13 #include <stdint.h>
15 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
16 // Validate input
17 if (!size) return 0;
18 if (data[size - 1] != '\0') return 0;
19 const char *src = (const char *)data;
21 char *dest = new char[size];
22 if (!dest) __builtin_trap();
24 LIBC_NAMESPACE::strcpy(dest, src);
26 size_t i;
27 for (i = 0; src[i] != '\0'; i++) {
28 // Ensure correctness of strcpy
29 if (dest[i] != src[i]) __builtin_trap();
31 // Ensure strcpy null terminates dest
32 if (dest[i] != src[i]) __builtin_trap();
34 delete[] dest;
36 return 0;