/src/icu/icu4c/source/test/fuzzer/unicodeset_fuzzer.cpp
Line | Count | Source |
1 | | // © 2019 and later: Unicode, Inc. and others. |
2 | | // License & terms of use: http://www.unicode.org/copyright.html |
3 | | |
4 | | #include <cstring> |
5 | | |
6 | | #include "fuzzer_utils.h" |
7 | | #include "unicode/coll.h" |
8 | | #include "unicode/localpointer.h" |
9 | | #include "unicode/uniset.h" |
10 | | |
11 | 33.3k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
12 | 33.3k | UErrorCode status = U_ZERO_ERROR; |
13 | | |
14 | 33.3k | size_t unistr_size = size/2; |
15 | 33.3k | std::unique_ptr<char16_t[]> fuzzbuff(new char16_t[unistr_size]); |
16 | 33.3k | std::memcpy(fuzzbuff.get(), data, unistr_size * 2); |
17 | 33.3k | icu::UnicodeString fuzzstr(false, fuzzbuff.get(), unistr_size); |
18 | | |
19 | 33.3k | icu::LocalPointer<icu::UnicodeSet> set( |
20 | 33.3k | new icu::UnicodeSet(fuzzstr, status)); |
21 | | |
22 | 33.3k | status = U_ZERO_ERROR; |
23 | | |
24 | 33.3k | set.adoptInstead(new icu::UnicodeSet()); |
25 | 33.3k | set->applyPattern (fuzzstr, status); |
26 | | |
27 | 33.3k | set.adoptInstead(new icu::UnicodeSet()); |
28 | 33.3k | set->addAll(fuzzstr); |
29 | | |
30 | 33.3k | set.adoptInstead(new icu::UnicodeSet()); |
31 | 33.3k | set->add(fuzzstr); |
32 | | |
33 | 33.3k | set.adoptInstead(new icu::UnicodeSet()); |
34 | 33.3k | set->retainAll(fuzzstr); |
35 | | |
36 | 33.3k | set.adoptInstead(new icu::UnicodeSet()); |
37 | 33.3k | set->complementAll(fuzzstr); |
38 | | |
39 | 33.3k | set.adoptInstead(new icu::UnicodeSet()); |
40 | 33.3k | set->removeAll(fuzzstr); |
41 | | |
42 | 33.3k | set.adoptInstead(new icu::UnicodeSet()); |
43 | 33.3k | set->retain(fuzzstr); |
44 | | |
45 | 33.3k | set.adoptInstead(new icu::UnicodeSet()); |
46 | 33.3k | set->remove(fuzzstr); |
47 | | |
48 | 33.3k | set.adoptInstead(new icu::UnicodeSet()); |
49 | 33.3k | set->complement(fuzzstr); |
50 | | |
51 | 33.3k | set.adoptInstead(icu::UnicodeSet::createFrom(fuzzstr)); |
52 | | |
53 | 33.3k | set.adoptInstead(icu::UnicodeSet::createFromAll(fuzzstr)); |
54 | 33.3k | return 0; |
55 | 33.3k | } |