Mercurial > sdl-ios-xcode
diff src/main/win32/SDL_win32_main.c @ 1379:c0a74f199ecf
Use only safe string functions
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 19 Feb 2006 23:46:34 +0000 |
parents | 19418e4422cb |
children | 4ed717f9e509 |
line wrap: on
line diff
--- a/src/main/win32/SDL_win32_main.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/main/win32/SDL_win32_main.c Sun Feb 19 23:46:34 2006 +0000 @@ -18,7 +18,6 @@ # define fopen _wfopen # define freopen _wfreopen # define remove(x) DeleteFile(x) -# define strcat wcscat #else # define DIR_SEPERATOR TEXT("/") # include <direct.h> @@ -208,8 +207,7 @@ if ( bufp == NULL ) { return OutOfMemory(); } - SDL_strncpy(bufp, appname, n); - bufp[n] = '\0'; + SDL_strlcpy(bufp, appname, n); appname = bufp; /* Load SDL dynamic link library */ @@ -259,10 +257,12 @@ int nLen; #else char *bufp; + size_t nLen; #endif #ifndef NO_STDIO_REDIRECT FILE *newfp; #endif + int retval; /* Start up DDHELP.EXE before opening any files, so DDHELP doesn't keep them open. This is a hack.. hopefully it will be fixed @@ -274,14 +274,14 @@ } #ifndef NO_STDIO_REDIRECT - pathlen = GetModuleFileName(NULL, path, SDL_TABLESIZE(path)); + pathlen = GetModuleFileName(NULL, path, SDL_arraysize(path)); while ( pathlen > 0 && path[pathlen] != '\\' ) { --pathlen; } path[pathlen] = '\0'; - SDL_strcpy( stdoutPath, path ); - SDL_strcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE ); + SDL_strlcpy( stdoutPath, path, SDL_arraysize(stdoutPath) ); + SDL_strlcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) ); /* Redirect standard input and standard output */ newfp = freopen(stdoutPath, TEXT("w"), stdout); @@ -299,8 +299,8 @@ } #endif /* _WIN32_WCE */ - SDL_strcpy( stderrPath, path ); - SDL_strcat( stderrPath, DIR_SEPERATOR STDERR_FILE ); + SDL_strlcpy( stderrPath, path, SDL_arraysize(stderrPath) ); + SDL_strlcat( stderrPath, DIR_SEPERATOR STDERR_FILE, SDL_arraysize(stderrPath) ); newfp = freopen(stderrPath, TEXT("w"), stderr); #ifndef _WIN32_WCE @@ -328,7 +328,7 @@ wcscpy (bufp+wcslen(bufp), TEXT("\" ")); wcsncpy(bufp+wcslen(bufp), szCmdLine,nLen-wcslen(bufp)); nLen = wcslen(bufp)+1; - cmdline = (char *)alloca(nLen); + cmdline = SDL_stack_alloc(wchar_t, nLen); if ( cmdline == NULL ) { return OutOfMemory(); } @@ -336,21 +336,26 @@ #else /* Grab the command line (use alloca() on Windows) */ bufp = GetCommandLine(); - cmdline = (char *)alloca(SDL_strlen(bufp)+1); + nLen = SDL_strlen(bufp)+1; + cmdline = SDL_stack_alloc(char, nLen); if ( cmdline == NULL ) { return OutOfMemory(); } - SDL_strcpy(cmdline, bufp); + SDL_strlcpy(cmdline, bufp, nLen); #endif /* Parse it into argv and argc */ argc = ParseCommandLine(cmdline, NULL); - argv = (char **)alloca((argc+1)*(sizeof *argv)); + argv = SDL_stack_alloc(char*, argc+1); if ( argv == NULL ) { return OutOfMemory(); } ParseCommandLine(cmdline, argv); /* Run the main program (after a little SDL initialization) */ - return(console_main(argc, argv)); + retval = console_main(argc, argv); + + SDL_stack_free(cmdline); + SDL_stack_free(argv); + return retval; }