| 1 | //===-- atof_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 atof implementation. |
| 10 | /// |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | #include "src/stdlib/atof.h" |
| 13 | #include <stddef.h> |
| 14 | #include <stdint.h> |
| 15 | #include <stdlib.h> |
| 16 | |
| 17 | #include "fuzzing/stdlib/StringParserOutputDiff.h" |
| 18 | |
| 19 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
| 20 | uint8_t *container = new uint8_t[size + 1]; |
| 21 | if (!container) |
| 22 | __builtin_trap(); |
| 23 | size_t i; |
| 24 | |
| 25 | for (i = 0; i < size; ++i) |
| 26 | container[i] = data[i]; |
| 27 | container[size] = '\0'; // Add null terminator to container. |
| 28 | |
| 29 | StringParserOutputDiff<double>(&LIBC_NAMESPACE::atof, &::atof, container, |
| 30 | size); |
| 31 | delete[] container; |
| 32 | return 0; |
| 33 | } |
| 34 | |