mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-07 01:06:48 +08:00
manually checked modified files for errors, but not committing .clang-format due to the following warning: >>> Setting `QualifierAlignment` to something other than `Leave`, COULD lead to incorrect code formatting due to incorrect decisions made due to clang-formats lack of complete semantic information. As such extra care should be taken to review code changes made by the use of this option.
38 lines
1.2 KiB
C++
38 lines
1.2 KiB
C++
#include "fast_float/fast_float.h"
|
|
#include <fuzzer/FuzzedDataProvider.h>
|
|
#include <string>
|
|
#include <system_error>
|
|
|
|
fast_float::chars_format arbitrary_format(FuzzedDataProvider &fdp) {
|
|
using fast_float::chars_format;
|
|
switch (fdp.ConsumeIntegralInRange<int>(0, 3)) {
|
|
case 0:
|
|
return chars_format::scientific;
|
|
break;
|
|
case 1:
|
|
return chars_format::fixed;
|
|
break;
|
|
case 2:
|
|
return chars_format::fixed;
|
|
break;
|
|
}
|
|
return chars_format::general;
|
|
}
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(uint8_t const *data, size_t size) {
|
|
FuzzedDataProvider fdp(data, size);
|
|
fast_float::chars_format format = arbitrary_format(fdp);
|
|
double result_d = 0.0;
|
|
std::string input_d = fdp.ConsumeRandomLengthString(128);
|
|
auto answer = fast_float::from_chars(
|
|
input_d.data(), input_d.data() + input_d.size(), result_d, format);
|
|
std::string input_f = fdp.ConsumeRandomLengthString(128);
|
|
float result_f = 0.0;
|
|
answer = fast_float::from_chars(
|
|
input_f.data(), input_f.data() + input_f.size(), result_f, format);
|
|
int result_i = 0;
|
|
std::string input_i = fdp.ConsumeRandomLengthString(128);
|
|
answer = fast_float::from_chars(input_i.data(),
|
|
input_i.data() + input_i.size(), result_i);
|
|
return 0;
|
|
} |