Skip to content

Conversation

@madebr
Copy link
Contributor

@madebr madebr commented Oct 28, 2025

The suite now tests sorting int arrays, double arrays, custom struct array and int pointer arrays.

It also tests whether qsort preserves all items.
But because it is very slow (O(n^2)), I've hidden it behind a cli argument (--slow-checks)

Description

Existing Issue(s)

@madebr
Copy link
Contributor Author

madebr commented Oct 28, 2025

@sezero
I perhaps went a bit crazy with the macro templating, but can you see why clang fails here?

@madebr madebr force-pushed the testqsort-on-SDL_Test branch from 76058cc to 6eaa7af Compare October 28, 2025 01:57
@sezero
Copy link
Contributor

sezero commented Oct 28, 2025

I don't know how -Walloc-size-larger-than works, but maybe the compiler
is confused about type limits ???

9223372036854775807 is INT64_MAX (signed), whereas 18446744073709551615
is UINT64_MAX (unsigned) which correspond to SSIZE_MAX and SIZE_MAX for
x86_64.

I'm certainly reaching here, but, does it change anything if you add a
size_t cast in TEST_QSORT_ARRAY and TEST_ARRAY_LOST_NO_ELEMENTS, e.g.
like:

-        TYPE *copy = SDL_calloc((SIZE), sizeof(TYPE));                              \
+        TYPE *copy = SDL_calloc((size_t)(SIZE), sizeof(TYPE));                      \

@madebr madebr force-pushed the testqsort-on-SDL_Test branch 4 times, most recently from 86baecb to b625664 Compare October 28, 2025 04:36
@madebr
Copy link
Contributor Author

madebr commented Oct 28, 2025

-        TYPE *copy = SDL_calloc((SIZE), sizeof(TYPE));                              \
+        TYPE *copy = SDL_calloc((size_t)(SIZE), sizeof(TYPE));                      \

Thanks for the hint!
There was a int -> size_t cast for the arraylen variable. I changed the code to keep it always unsigned.

@madebr madebr force-pushed the testqsort-on-SDL_Test branch from 6be26b5 to fc1feca Compare October 28, 2025 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants