• 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     if (size < 2)
20         return 0;
21 
22     // Make a heap from the first half of the data
23     std::vector<std::uint8_t> working(data, data + size);
24     auto iter = working.begin() + (size / 2);
25     std::make_heap(working.begin(), iter);
26     if (!std::is_heap(working.begin(), iter))
27         return 1;
28 
29     // Now push the rest onto the heap, one at a time
30     ++iter;
31     for (; iter != working.end(); ++iter) {
32         std::push_heap(working.begin(), iter);
33         if (!std::is_heap(working.begin(), iter))
34             return 2;
35     }
36 
37     if (!fast_is_permutation(data, data + size, working.cbegin()))
38         return 99;
39     return 0;
40 }
41