• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
LLVMFuzzerTestOneInput(const std::uint8_t * data,std::size_t size)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(ByteWithPayload(data[i], i));
24     std::vector<ByteWithPayload> working = input;
25     auto iter = std::stable_partition(working.begin(), working.end(), is_even);
26 
27     if (!std::all_of(working.begin(), iter, is_even))
28         return 1;
29     if (!std::none_of(iter,   working.end(), is_even))
30         return 2;
31     if (!std::is_sorted(working.begin(), iter, ByteWithPayload::payload_less()))
32         return 3;
33     if (!std::is_sorted(iter,   working.end(), ByteWithPayload::payload_less()))
34         return 4;
35     if (!fast_is_permutation(input.cbegin(), input.cend(), working.cbegin()))
36         return 99;
37     return 0;
38 }
39