]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/fuzzer/number_format_fuzzer.cc
1 // © 2019 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 // Fuzzer for NumberFormat::parse.
9 #include "fuzzer_utils.h"
10 #include "unicode/numfmt.h"
12 IcuEnvironment
* env
= new IcuEnvironment();
14 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data
, size_t size
) {
15 UErrorCode status
= U_ZERO_ERROR
;
22 rnd
= *(reinterpret_cast<const uint16_t *>(data
));
26 size_t unistr_size
= size
/2;
27 std::unique_ptr
<char16_t[]> fuzzbuff(new char16_t[unistr_size
]);
28 std::memcpy(fuzzbuff
.get(), data
, unistr_size
* 2);
30 const icu::Locale
& locale
= GetRandomLocale(rnd
);
32 std::unique_ptr
<icu::NumberFormat
> fmt(
33 icu::NumberFormat::createInstance(locale
, status
));
34 if (U_FAILURE(status
)) {
38 icu::UnicodeString
fuzzstr(false, fuzzbuff
.get(), unistr_size
);
39 icu::Formattable result
;
40 fmt
->parse(fuzzstr
, result
, status
);