]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/fuzzer/collator_compare_fuzzer.cpp
1 // © 2019 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
6 #include "fuzzer_utils.h"
7 #include "unicode/coll.h"
8 #include "unicode/localpointer.h"
9 #include "unicode/locid.h"
11 IcuEnvironment
* env
= new IcuEnvironment();
13 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data
, size_t size
) {
14 UErrorCode status
= U_ZERO_ERROR
;
19 std::unique_ptr
<char16_t> compbuff1(new char16_t[size
/4]);
20 std::memcpy(compbuff1
.get(), data
, (size
/4)*2);
22 std::unique_ptr
<char16_t> compbuff2(new char16_t[size
/4]);
23 std::memcpy(compbuff2
.get(), data
, (size
/4)*2);
25 icu::LocalPointer
<icu::Collator
> fuzzCollator(
26 icu::Collator::createInstance(icu::Locale::getUS(), status
), status
);
27 if (U_FAILURE(status
))
29 fuzzCollator
->setStrength(icu::Collator::TERTIARY
);
31 fuzzCollator
->compare(compbuff1
.get(), size
/4,
32 compbuff2
.get(), size
/4);