src/main/win32/SDL_win32_main.c
changeset 1379 c0a74f199ecf
parent 1361 19418e4422cb
child 1423 4ed717f9e509
     1.1 --- a/src/main/win32/SDL_win32_main.c	Sun Feb 19 23:38:57 2006 +0000
     1.2 +++ b/src/main/win32/SDL_win32_main.c	Sun Feb 19 23:46:34 2006 +0000
     1.3 @@ -18,7 +18,6 @@
     1.4  # define fopen		_wfopen
     1.5  # define freopen	_wfreopen
     1.6  # define remove(x)	DeleteFile(x)
     1.7 -# define strcat		wcscat
     1.8  #else
     1.9  # define DIR_SEPERATOR TEXT("/")
    1.10  # include <direct.h>
    1.11 @@ -208,8 +207,7 @@
    1.12  	if ( bufp == NULL ) {
    1.13  		return OutOfMemory();
    1.14  	}
    1.15 -	SDL_strncpy(bufp, appname, n);
    1.16 -	bufp[n] = '\0';
    1.17 +	SDL_strlcpy(bufp, appname, n);
    1.18  	appname = bufp;
    1.19  
    1.20  	/* Load SDL dynamic link library */
    1.21 @@ -259,10 +257,12 @@
    1.22  	int nLen;
    1.23  #else
    1.24  	char *bufp;
    1.25 +	size_t nLen;
    1.26  #endif
    1.27  #ifndef NO_STDIO_REDIRECT
    1.28  	FILE *newfp;
    1.29  #endif
    1.30 +	int retval;
    1.31  
    1.32  	/* Start up DDHELP.EXE before opening any files, so DDHELP doesn't
    1.33  	   keep them open.  This is a hack.. hopefully it will be fixed 
    1.34 @@ -274,14 +274,14 @@
    1.35  	}
    1.36  
    1.37  #ifndef NO_STDIO_REDIRECT
    1.38 -	pathlen = GetModuleFileName(NULL, path, SDL_TABLESIZE(path));
    1.39 +	pathlen = GetModuleFileName(NULL, path, SDL_arraysize(path));
    1.40  	while ( pathlen > 0 && path[pathlen] != '\\' ) {
    1.41  		--pathlen;
    1.42  	}
    1.43  	path[pathlen] = '\0';
    1.44  
    1.45 -	SDL_strcpy( stdoutPath, path );
    1.46 -	SDL_strcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE );
    1.47 +	SDL_strlcpy( stdoutPath, path, SDL_arraysize(stdoutPath) );
    1.48 +	SDL_strlcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) );
    1.49      
    1.50  	/* Redirect standard input and standard output */
    1.51  	newfp = freopen(stdoutPath, TEXT("w"), stdout);
    1.52 @@ -299,8 +299,8 @@
    1.53  	}
    1.54  #endif /* _WIN32_WCE */
    1.55  
    1.56 -	SDL_strcpy( stderrPath, path );
    1.57 -	SDL_strcat( stderrPath, DIR_SEPERATOR STDERR_FILE );
    1.58 +	SDL_strlcpy( stderrPath, path, SDL_arraysize(stderrPath) );
    1.59 +	SDL_strlcat( stderrPath, DIR_SEPERATOR STDERR_FILE, SDL_arraysize(stderrPath) );
    1.60  
    1.61  	newfp = freopen(stderrPath, TEXT("w"), stderr);
    1.62  #ifndef _WIN32_WCE
    1.63 @@ -328,7 +328,7 @@
    1.64  	wcscpy (bufp+wcslen(bufp), TEXT("\" "));
    1.65  	wcsncpy(bufp+wcslen(bufp), szCmdLine,nLen-wcslen(bufp));
    1.66  	nLen = wcslen(bufp)+1;
    1.67 -	cmdline = (char *)alloca(nLen);
    1.68 +	cmdline = SDL_stack_alloc(wchar_t, nLen);
    1.69  	if ( cmdline == NULL ) {
    1.70  		return OutOfMemory();
    1.71  	}
    1.72 @@ -336,21 +336,26 @@
    1.73  #else
    1.74  	/* Grab the command line (use alloca() on Windows) */
    1.75  	bufp = GetCommandLine();
    1.76 -	cmdline = (char *)alloca(SDL_strlen(bufp)+1);
    1.77 +	nLen = SDL_strlen(bufp)+1;
    1.78 +	cmdline = SDL_stack_alloc(char, nLen);
    1.79  	if ( cmdline == NULL ) {
    1.80  		return OutOfMemory();
    1.81  	}
    1.82 -	SDL_strcpy(cmdline, bufp);
    1.83 +	SDL_strlcpy(cmdline, bufp, nLen);
    1.84  #endif
    1.85  
    1.86  	/* Parse it into argv and argc */
    1.87  	argc = ParseCommandLine(cmdline, NULL);
    1.88 -	argv = (char **)alloca((argc+1)*(sizeof *argv));
    1.89 +	argv = SDL_stack_alloc(char*, argc+1);
    1.90  	if ( argv == NULL ) {
    1.91  		return OutOfMemory();
    1.92  	}
    1.93  	ParseCommandLine(cmdline, argv);
    1.94  
    1.95  	/* Run the main program (after a little SDL initialization) */
    1.96 -	return(console_main(argc, argv));
    1.97 +	retval = console_main(argc, argv);
    1.98 +
    1.99 +	SDL_stack_free(cmdline);
   1.100 +	SDL_stack_free(argv);
   1.101 +	return retval;
   1.102  }