/src/llvm-project/libcxx/test/libcxx/fuzzing/partition.pass.cpp
Line | Count | Source |
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 | 47 | extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t *data, std::size_t size) { |
19 | 8.39M | auto is_even = [](auto x) { return x % 2 == 0; }; |
20 | 47 | std::vector<std::uint8_t> working(data, data + size); |
21 | 47 | auto iter = std::partition(working.begin(), working.end(), is_even); |
22 | | |
23 | 47 | if (!std::all_of(working.begin(), iter, is_even)) |
24 | 0 | return 1; |
25 | 47 | if (!std::none_of(iter, working.end(), is_even)) |
26 | 0 | return 2; |
27 | 47 | if (!fast_is_permutation(data, data + size, working.cbegin())) |
28 | 0 | return 99; |
29 | 47 | return 0; |
30 | 47 | } |