1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03, c++11 |
10 | |
11 | #include <algorithm> |
12 | #include <cstddef> |
13 | #include <cstdint> |
14 | #include <vector> |
15 | |
16 | #include "fuzz.h" |
17 | |
18 | extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t *data, std::size_t size) { |
19 | auto is_even = [](auto b) { return b.key % 2 == 0; }; |
20 | |
21 | std::vector<ByteWithPayload> input; |
22 | for (std::size_t i = 0; i < size; ++i) |
23 | input.push_back(x: ByteWithPayload(data[i], i)); |
24 | std::vector<ByteWithPayload> working = input; |
25 | auto iter = std::stable_partition(first: working.begin(), last: working.end(), pred: is_even); |
26 | |
27 | if (!std::all_of(first: working.begin(), last: iter, pred: is_even)) |
28 | return 1; |
29 | if (!std::none_of(first: iter, last: working.end(), pred: is_even)) |
30 | return 2; |
31 | if (!std::is_sorted(first: working.begin(), last: iter, comp: ByteWithPayload::payload_less())) |
32 | return 3; |
33 | if (!std::is_sorted(first: iter, last: working.end(), comp: ByteWithPayload::payload_less())) |
34 | return 4; |
35 | if (!fast_is_permutation(first1: input.cbegin(), last1: input.cend(), first2: working.cbegin())) |
36 | return 99; |
37 | return 0; |
38 | } |
39 | |