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