fix(libc): return success for heapsort with at most one element regardless of size

This commit is contained in:
iAbdulrrahman committed 2026-10-26 14:34:20 +03:00
1 parent 54fb58a5e4
commit b999ea3c43
2 files changed
+4 -1

No files matched your search

+1 -1
View File
@@ -753,11 +753,11 @@ int APS5_VABI mergesort_nid_postfix(void* base, size_t count, size_t size, Guest
}
int APS5_VABI heapsort_nid_postfix(void* base, size_t count, size_t size, GuestCompare compare) {
if (count <= 1) return 0;
if (size == 0) {
errno = 22;
return -1;
}
if (count <= 1) return 0;
if (!compare) throw std::invalid_argument("heapsort: null comparator");
if (!base) throw std::invalid_argument("heapsort: null base");
if (count > std::numeric_limits<size_t>::max() / size) throw std::overflow_error("heapsort: array size overflow");
+3
View File
@@ -225,6 +225,9 @@ bool CheckHeapsort() {
}
unsigned char bytes[3] = {3, 1, 2};
*__error_nid_postfix() = 0;
correct &= heapsort_nid_postfix(nullptr, 0, 0, nullptr) == 0;
unsigned char single = 42;
correct &= heapsort_nid_postfix(&single, 1, 0, nullptr) == 0;
correct &= heapsort_nid_postfix(bytes, 3, 0, CompareFirstByte) == -1 && *__error_nid_postfix() == 22 && bytes[0] == 3;
correct &= heapsort_nid_postfix(nullptr, 0, 4, CompareKeys) == 0;
if (!correct) std::fprintf(stderr, "heapsort failed\n");