mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-06 16:56:57 +08:00
commit
8cb0590c02
8
fuzz/build.sh
Normal file
8
fuzz/build.sh
Normal file
@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
$CXX $CFLAGS $CXXFLAGS \
|
||||
-I $SRC/fast_float/include \
|
||||
-c $SRC/fast_float/fuzz/from_chars.cc -o from_chars.o
|
||||
|
||||
$CXX $CFLAGS $CXXFLAGS $LIB_FUZZING_ENGINE from_chars.o \
|
||||
-o $OUT/from_chars
|
||||
34
fuzz/from_chars.cc
Normal file
34
fuzz/from_chars.cc
Normal file
@ -0,0 +1,34 @@
|
||||
#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(const uint8_t *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);
|
||||
double result_f = 0.0;
|
||||
answer =
|
||||
fast_float::from_chars(input_f.data(), input_f.data() + input_f.size(), result_f, format);
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user