src/video/windx5/SDL_dx5video.c
changeset 1330 450721ad5436
parent 1312 c9b51268668f
child 1336 3692456e7b0f
     1.1 --- a/src/video/windx5/SDL_dx5video.c	Sat Feb 04 22:01:44 2006 +0000
     1.2 +++ b/src/video/windx5/SDL_dx5video.c	Mon Feb 06 08:28:51 2006 +0000
     1.3 @@ -20,10 +20,7 @@
     1.4      slouken@libsdl.org
     1.5  */
     1.6  
     1.7 -#include <stdio.h>
     1.8 -#include <stdlib.h>
     1.9 -#include <malloc.h>
    1.10 -#include <windows.h>
    1.11 +#include "SDL_windows.h"
    1.12  #include "directx.h"
    1.13  
    1.14  /* Not yet in the mingw32 cross-compile headers */
    1.15 @@ -35,6 +32,8 @@
    1.16  #include "SDL_timer.h"
    1.17  #include "SDL_events.h"
    1.18  #include "SDL_syswm.h"
    1.19 +#include "SDL_stdlib.h"
    1.20 +#include "SDL_string.h"
    1.21  #include "SDL_sysvideo.h"
    1.22  #include "SDL_blit.h"
    1.23  #include "SDL_pixels_c.h"
    1.24 @@ -810,12 +809,13 @@
    1.25  			error = "Interface not present";
    1.26  			break;
    1.27  		default:
    1.28 -			sprintf(errbuf, "%s: Unknown DirectDraw error: 0x%x",
    1.29 +			snprintf(errbuf, SDL_arraysize(errbuf),
    1.30 +			         "%s: Unknown DirectDraw error: 0x%x",
    1.31  								function, code);
    1.32  			break;
    1.33  	}
    1.34  	if ( ! errbuf[0] ) {
    1.35 -		sprintf(errbuf, "%s: %s", function, error);
    1.36 +		snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error);
    1.37  	}
    1.38  	SDL_SetError("%s", errbuf);
    1.39  	return;
    1.40 @@ -1109,7 +1109,8 @@
    1.41  			settings.dmPelsWidth = width;
    1.42  			settings.dmPelsHeight = height;
    1.43  			settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
    1.44 -			if ( width <= SDL_desktop_mode.dmPelsWidth && height <= SDL_desktop_mode.dmPelsHeight ) {
    1.45 +			if ( width <= (int)SDL_desktop_mode.dmPelsWidth &&
    1.46 +			     height <= (int)SDL_desktop_mode.dmPelsHeight ) {
    1.47  				settings.dmDisplayFrequency = SDL_desktop_mode.dmDisplayFrequency;
    1.48  				settings.dmFields |= DM_DISPLAYFREQUENCY;
    1.49  			}
    1.50 @@ -2170,7 +2171,7 @@
    1.51  	}
    1.52  #else
    1.53  	/* Allocate memory for the arrays we use */
    1.54 -	pool = (int *)alloca(2*ncolors*sizeof(int));
    1.55 +	pool = SDL_stack_alloc(int, 2*ncolors);
    1.56  	if ( pool == NULL ) {
    1.57  		/* No worries, just return */;
    1.58  		return;
    1.59 @@ -2217,6 +2218,7 @@
    1.60  		SDL_colors[j].peGreen = colors[order[i]].g;
    1.61  		SDL_colors[j].peBlue = colors[order[i]].b;
    1.62  	}
    1.63 +	SDL_stack_free(pool);
    1.64  #endif /* SIMPLE_COMPRESSION */
    1.65  }
    1.66  
    1.67 @@ -2458,12 +2460,12 @@
    1.68  	if ( palette == NULL ) { /* Sometimes we don't have a palette */
    1.69  		return;
    1.70  	}
    1.71 -	entries = (PALETTEENTRY *)alloca(palette->ncolors*sizeof(*entries));
    1.72 +	entries = SDL_stack_alloc(PALETTEENTRY, palette->ncolors);
    1.73  	hdc = GetDC(window);
    1.74  	GetSystemPaletteEntries(hdc, 0, palette->ncolors, entries);
    1.75  	ReleaseDC(window, hdc);
    1.76  	if ( ! colorchange_expected ) {
    1.77 -		saved = (SDL_Color *)alloca(palette->ncolors*sizeof(SDL_Color));
    1.78 +		saved = SDL_stack_alloc(SDL_Color, palette->ncolors);
    1.79  		memcpy(saved, palette->colors, 
    1.80  					palette->ncolors*sizeof(SDL_Color));
    1.81  	}
    1.82 @@ -2472,6 +2474,7 @@
    1.83  		palette->colors[i].g = entries[i].peGreen;
    1.84  		palette->colors[i].b = entries[i].peBlue;
    1.85  	}
    1.86 +	SDL_stack_free(entries);
    1.87  	if ( ! colorchange_expected ) {
    1.88  		Uint8 mapping[256];
    1.89  
    1.90 @@ -2481,6 +2484,7 @@
    1.91  					saved[i].r, saved[i].g, saved[i].b);
    1.92  		}
    1.93  		DX5_Recolor8Bit(this, SDL_VideoSurface, mapping);
    1.94 +		SDL_stack_free(saved);
    1.95  	}
    1.96  	colorchange_expected = 0;
    1.97