1 #include "hb-fuzzer.hh"
10 enum set_operation_t : uint8_t
15 SYMMETRIC_DIFFERENCE = 3
20 set_operation_t operation;
21 uint32_t first_set_size;
24 static hb_set_t *create_set (const uint32_t *value_array, int count)
26 hb_set_t *set = hb_set_create ();
27 for (int i = 0; i < count; i++)
28 hb_set_add (set, value_array[i]);
33 extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
35 if (size < sizeof (instructions_t))
38 const instructions_t &instructions = reinterpret_cast<const instructions_t &> (data);
39 data += sizeof (instructions_t);
40 size -= sizeof (instructions_t);
42 const uint32_t *values = reinterpret_cast<const uint32_t *> (data);
43 size = size / sizeof (uint32_t);
45 if (size < instructions.first_set_size)
48 hb_set_t *set_a = create_set (values, instructions.first_set_size);
50 values += instructions.first_set_size;
51 size -= instructions.first_set_size;
52 hb_set_t *set_b = create_set (values, size);
54 switch (instructions.operation)
57 hb_set_intersect (set_a, set_b);
60 hb_set_union (set_a, set_b);
63 hb_set_subtract (set_a, set_b);
65 case SYMMETRIC_DIFFERENCE:
66 hb_set_symmetric_difference (set_a, set_b);
72 hb_set_destroy (set_a);
73 hb_set_destroy (set_b);