1
- // ===-- qsort_fuzz .cpp ---- ------------------------------------------------===//
1
+ // ===-- quick_sort_fuzz .cpp------------------------------------------------===//
2
2
//
3
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
4
// See https://llvm.org/LICENSE.txt for license information.
5
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
6
//
7
7
// ===----------------------------------------------------------------------===//
8
8
// /
9
- // / Fuzzing test for llvm-libc qsort implementation.
9
+ // / Fuzzing test for llvm-libc quick_sort implementation.
10
10
// /
11
11
// ===----------------------------------------------------------------------===//
12
12
13
- #include " src/stdlib/qsort .h"
13
+ #include " src/stdlib/qsort_util .h"
14
14
#include < stdint.h>
15
15
16
- static int int_compare (const void *l, const void *r) {
17
- int li = *reinterpret_cast <const int *>(l);
18
- int ri = *reinterpret_cast <const int *>(r);
19
- if (li == ri)
20
- return 0 ;
21
- else if (li > ri)
22
- return 1 ;
23
- else
24
- return -1 ;
25
- }
26
-
27
16
extern " C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) {
28
17
const size_t array_size = size / sizeof (int );
29
18
if (array_size == 0 )
@@ -34,7 +23,17 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
34
23
for (size_t i = 0 ; i < array_size; ++i)
35
24
array[i] = data_as_int[i];
36
25
37
- LIBC_NAMESPACE::qsort (array, array_size, sizeof (int ), int_compare);
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);
30
+
31
+ return a < b;
32
+ };
33
+
34
+ constexpr bool USE_QUICKSORT = true ;
35
+ LIBC_NAMESPACE::internal::unstable_sort_impl<USE_QUICKSORT>(
36
+ array, array_size, sizeof (int ), is_less);
38
37
39
38
for (size_t i = 0 ; i < array_size - 1 ; ++i) {
40
39
if (array[i] > array[i + 1 ])
0 commit comments