Fixed crash with invalid bpp in SDL_SetVideoMode()
authorSam Lantinga <slouken@libsdl.org>
Tue, 20 Aug 2002 04:44:36 +0000
changeset 456 b4e14b15af3c
parent 455 a228badffb6c
child 457 d0ab9718bf91
Fixed crash with invalid bpp in SDL_SetVideoMode()
src/video/SDL_video.c
--- a/src/video/SDL_video.c	Tue Aug 20 00:27:37 2002 +0000
+++ b/src/video/SDL_video.c	Tue Aug 20 04:44:36 2002 +0000
@@ -362,7 +362,7 @@
 	if ( bpp < 8 || bpp > 32 ) {
 		return(0);
 	}
-	if ( (width == 0) || (height == 0) ) {
+	if ( (width <= 0) || (height <= 0) ) {
 		return(0);
 	}
 
@@ -415,8 +415,13 @@
 	SDL_PixelFormat format;
 	SDL_Rect **sizes;
 
+	/* Check parameters */
+	if ( *BitsPerPixel < 8 || *BitsPerPixel > 32 ) {
+		SDL_SetError("Invalid bits per pixel (range is {8...32})");
+		return(0);
+	}
 	if ((*w <= 0) || (*h <= 0)) {
-		SDL_SetError("Invalid parameter");
+		SDL_SetError("Invalid width or height");
 		return(0);
 	}