From 51a5727c8d1381bb288cc58e42db861000e53fcd Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 28 May 2023 21:51:39 +0200 Subject: [PATCH] libluna: Fix a crash in quicksort --- libluna/src/Sort.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libluna/src/Sort.cpp b/libluna/src/Sort.cpp index 4a4da6b4..83015c18 100644 --- a/libluna/src/Sort.cpp +++ b/libluna/src/Sort.cpp @@ -1,4 +1,5 @@ #include +#include #include static void swap_sized(void* ptr1, void* ptr2, usize size) @@ -42,7 +43,7 @@ static void quicksort_impl(void* base, usize start, usize end, usize size, compa { usize pivot = partition(base, start, end, size, compar); if ((end - start) < 2) return; - quicksort_impl(base, start, pivot - 1, size, compar); + if (pivot > 0) quicksort_impl(base, start, pivot - 1, size, compar); quicksort_impl(base, pivot + 1, end, size, compar); } }