The following patch fixes a segfault in SDL_x11modes.c when changing
video modes on a display with only one configured modeline.
It was possible for `i’ to be negative after falling through to the
’match:’ block – this patch adds a new variable to keep track of the
best known mode instead of reusing the loop index.
#:jamesjb
— SDL-1.2.6/src/video/x11/SDL_x11modes.c 2003-08-30 12:13:12.000000000 -0700
+++ SDL-1.2.6-jamesjb/src/video/x11/SDL_x11modes.c 2003-08-31 14:20:32.000000000 -0700
@@ -100,6 +100,7 @@
SDL_NAME(XF86VidModeModeLine) mode;
SDL_NAME(XF86VidModeModeInfo) **modes;
int i;
-
int best_mode_index = -1; int best_width = 0, best_height = 0; int nmodes;
@@ -116,8 +117,10 @@
#endif
for ( i = 0; i < nmodes ; i++ ) {
if ( (modes[i]->hdisplay == width) &&
-
(modes[i]->vdisplay == height) )
-
(modes[i]->vdisplay == height) ) {
-
best_mode_index = i; goto match;
-
} } qsort(modes, nmodes, sizeof *modes, cmpmodes); for ( i = nmodes-1; i >= 0 ; i-- ) {
@@ -126,20 +129,25 @@
(modes[i]->vdisplay >= height) ) {
best_width = modes[i]->hdisplay;
best_height = modes[i]->vdisplay;
-
best_mode_index = i; } } else { if ( (modes[i]->hdisplay != best_width) || (modes[i]->vdisplay != best_height) ) {
-
i++;
-
break;
-
best_mode_index = i;
-
break; } } } match:
-
if ( (modes[i]->hdisplay != mode.hdisplay) ||
-
(modes[i]->vdisplay != mode.vdisplay) ) {
-
SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, modes[i]);
-
}
-
if (best_mode_index >= 0) {
-
if ( (modes[best_mode_index]->hdisplay != mode.hdisplay) ||
-
(modes[best_mode_index]->vdisplay != mode.vdisplay) ) {
-
SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen,
-
modes[best_mode_index]);
-
}
-
}}+ XFree(modes); }