1 //===-- heap_sort_fuzz.cpp ------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 /// Fuzzing test for llvm-libc heap_sort implementation.
11 //===----------------------------------------------------------------------===//
13 #include "src/stdlib/qsort_util.h"
16 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data
, size_t size
) {
17 const size_t array_size
= size
/ sizeof(int);
21 int *array
= new int[array_size
];
22 const int *data_as_int
= reinterpret_cast<const int *>(data
);
23 for (size_t i
= 0; i
< array_size
; ++i
)
24 array
[i
] = data_as_int
[i
];
26 const auto is_less
= [](const void *a_ptr
,
27 const void *b_ptr
) noexcept
-> bool {
28 const int &a
= *static_cast<const int *>(a_ptr
);
29 const int &b
= *static_cast<const int *>(b_ptr
);
34 constexpr bool USE_QUICKSORT
= false;
35 LIBC_NAMESPACE::internal::unstable_sort_impl
<USE_QUICKSORT
>(
36 array
, array_size
, sizeof(int), is_less
);
38 for (size_t i
= 0; i
< array_size
- 1; ++i
) {
39 if (array
[i
] > array
[i
+ 1])