-
Notifications
You must be signed in to change notification settings - Fork 153
/
Copy pathfrom_chars.cc
38 lines (36 loc) · 1.23 KB
/
from_chars.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#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;
}