/src/harfbuzz/test/fuzzing/hb-fuzzer.hh
Line | Count | Source (jump to first uncovered line) |
1 | | #include <hb-config.hh> |
2 | | |
3 | | #include <hb.h> |
4 | | #include <stddef.h> |
5 | | |
6 | | extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size); |
7 | | |
8 | | #if defined(__GNUC__) && (__GNUC__ >= 4) || (__clang__) |
9 | | #define HB_UNUSED __attribute__((unused)) |
10 | | #else |
11 | | #define HB_UNUSED |
12 | | #endif |
13 | | |
14 | | #ifdef HB_IS_IN_FUZZER |
15 | | |
16 | | /* See src/failing-alloc.c */ |
17 | | extern "C" int alloc_state; |
18 | | |
19 | | #else |
20 | | |
21 | | /* Just a dummy global variable */ |
22 | | static int HB_UNUSED alloc_state = 0; |
23 | | |
24 | | #endif |
25 | | |
26 | | static inline int |
27 | | _fuzzing_alloc_state (const uint8_t *data, size_t size) |
28 | 0 | { |
29 | | /* https://github.com/harfbuzz/harfbuzz/pull/2764#issuecomment-1172589849 */ |
30 | | |
31 | | /* In 50% of the runs, don't fail the allocator. */ |
32 | 0 | if (size && data[size - 1] < 0x80) |
33 | 0 | return 0; |
34 | | |
35 | 0 | return size; |
36 | 0 | } |