summaryrefslogtreecommitdiff
path: root/src/sdl
diff options
context:
space:
mode:
authorSimon McVittie <smcv@debian.org>2014-10-01 09:35:49 +0100
committerTim Angus <tim@ngus.net>2016-04-07 11:01:50 +0100
commit490d0b226e6a08433a12b356cc1460e0a50019b1 (patch)
tree483444662e0f41e03540c220cc7e649b135a8f5e /src/sdl
parent61f647351e041042a905153f3f9e8131b3193403 (diff)
Don't crash if more than 128 modes are available
Diffstat (limited to 'src/sdl')
-rw-r--r--src/sdl/sdl_glimp.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/sdl/sdl_glimp.c b/src/sdl/sdl_glimp.c
index 51b448a2..1f45551f 100644
--- a/src/sdl/sdl_glimp.c
+++ b/src/sdl/sdl_glimp.c
@@ -135,7 +135,8 @@ static void GLimp_DetectAvailableModes(void)
{
int i, j;
char buf[ MAX_STRING_CHARS ] = { 0 };
- SDL_Rect modes[ 128 ];
+ size_t numSDLModes;
+ SDL_Rect *modes;
int numModes = 0;
int display = SDL_GetWindowDisplayIndex( SDL_window );
@@ -147,7 +148,14 @@ static void GLimp_DetectAvailableModes(void)
return;
}
- for( i = 0; i < SDL_GetNumDisplayModes( display ); i++ )
+ numSDLModes = SDL_GetNumDisplayModes( display );
+ modes = SDL_calloc( numSDLModes, sizeof( SDL_Rect ));
+ if ( !modes )
+ {
+ ri.Error( ERR_FATAL, "Out of memory\n" );
+ }
+
+ for( i = 0; i < numSDLModes; i++ )
{
SDL_DisplayMode mode;
@@ -157,6 +165,7 @@ static void GLimp_DetectAvailableModes(void)
if( !mode.w || !mode.h )
{
ri.Printf( PRINT_ALL, "Display supports any resolution\n" );
+ SDL_free( modes );
return;
}
@@ -198,6 +207,7 @@ static void GLimp_DetectAvailableModes(void)
ri.Printf( PRINT_ALL, "Available modes: '%s'\n", buf );
ri.Cvar_Set( "r_availableModes", buf );
}
+ SDL_free( modes );
}
#define R_FAILSAFE_WIDTH 640