Coverage Report

Created: 2024-05-15 07:05

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