Comments (8)
During testing, I found the same problem with out-of-bounds access in the Insertion
macro (used by qsort_r_aligned
and qsort_r_unaligned
, but not by qsort_r_words
).
I will submit a fix a bit later, I want to fuzz it to make sure nothing gets out of sight.
from sdl.
@DanielGibson that's right! I was wrong when I debugged this change. (For some unknown reason, it was fixed for me, but fuzzing revealed the real problem see #10066).
from sdl.
I just tested it, the error still exists.
The pure C version works.
Linux 64bit
// gcc main.c -o main
#include <stdio.h>
#include <stdlib.h>
#define array_len 100
static int num_compare(const void *_a, const void *_b)
{
int a = *((int *) _a);
int b = *((int *) _b);
return (a > b); // non-transitive
}
int main(int argc, char *argv[])
{
srand(time(NULL));
int nums[array_len];
for (int i = 0; i < array_len; i++) {
nums[i] = (int)rand();
}
qsort(nums, array_len, sizeof (int), num_compare);
for (int i = 0; i < array_len; i++) {
printf("%i\n", nums[i]);
}
return 0;
}
from sdl.
@sechshelme can you test with this patch?
diff --git a/src/stdlib/SDL_qsort.c b/src/stdlib/SDL_qsort.c
index c6a06dde9..a6e91fa61 100644
--- a/src/stdlib/SDL_qsort.c
+++ b/src/stdlib/SDL_qsort.c
@@ -506,7 +506,7 @@ fprintf(stderr, "after partitioning first=#%lu last=#%lu\n", (first-(char*)base)
/* Find the right place for |first|. My apologies for var reuse */
int *pl=(int*)(first-WORD_BYTES),*pr=(int*)first;
*(int*)pivot=*(int*)first;
- for (;compare(userdata,pl,pivot)>0;pr=pl,--pl) {
+ for (;pl > (int*)base && compare(userdata,pl,pivot)>0;pr=pl,--pl) {
*pr=*pl; }
if (pr!=(int*)first) *pr=*(int*)pivot;
}
from sdl.
Since the version on git is (still) too old, I added it myself.
The error seems to have gone away.
// for (;compare(userdata,pl,pivot)>0;pr=pl,--pl) {
for (;pl > (int*)base && compare(userdata,pl,pivot)>0;pr=pl,--pl) {
from sdl.
Can you make that into a pull request so that it gets reviewed and merged?
from sdl.
Of course, but first I want to run some tests to make sure it doesn't break anything
from sdl.
That fix in upstream qsort 1.16 was about recursing on the smaller or bigger partition - that can prevent stack overflows, but only in very large arrays.
With only 50 or 100 elements, like in the case this bugreport is about, it doesn't matter what partition you recurse on, a callstack depth of 100 or so won't overflow it (on modern operating systems the stack usually is 8MB, on Windows it's 1MB and even that is more than enough for this usecase)
from sdl.
Related Issues (20)
- Should destroy functions take pointer to pointer? HOT 8
- SDL 2.30.4 breaks Steam Deck gamepad on Arch Linux HOT 12
- Documentation: clarify how hidpi affects mouse scaling HOT 2
- [SDL2] [Wayland] Power-cycling monitor causes SDL2 programs to crash (cause is known and described)
- SDL_timer.h: canceling a timer vs removing a timer HOT 1
- Question about compiler warnings HOT 6
- Mac OS window persists and hangs after destroy window and quit HOT 3
- `SDL_HashTableEmpty(SDL_objects)` assertion failure in testautomation HOT 1
- Unable to enable Enhanced Reports on DualSense over Bluetooth HOT 2
- KEYBOARD_IGNOREMODIFIERS 0x08 vs. 0x0 HOT 3
- SDL_Vulkan_CreateSurface() return value? HOT 4
- sdl2-config cannot run on Solaris 10 HOT 15
- Loading BMP and WAV tests fail after compiling SDL2 with Sun/Oracle compilers on UltraSPARC platform HOT 4
- Solaris 10 does not include compatible UTF8 support by default, SDL2 cannot compile HOT 2
- SDL_FALLTHROUGH check in ./include/begin_code.h incompatible with Solaris 10 UNIX "make" HOT 8
- SDL2 threading config in ./cmake/sdlchecks.cmake not correct for non-GNU compiler (e.g. SunPro cc) HOT 2
- UNIX version of SDL_GetBasePath in SDL_sysfilesystem.c not correct for Solaris, probably other UNIXes HOT 2
- Compiling SDL on SPARC platform with GNU toolset should target correct CPU by default HOT 3
- SDL incorrectly detects X11_XRANDR with CMake, does not compile on Solaris 10
- SDL build with configure (autoconf) incorrectly tries to build with Vulkan support on Solaris 10 (probably other UNIXes) HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdl.