comparison src/SDL_error.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 d910939febfa
comparison
equal deleted inserted replaced
1378:dc0e13e7e1ae 1379:c0a74f199ecf
57 SDL_error *error; 57 SDL_error *error;
58 58
59 /* Copy in the key, mark error as valid */ 59 /* Copy in the key, mark error as valid */
60 error = SDL_GetErrBuf(); 60 error = SDL_GetErrBuf();
61 error->error = 1; 61 error->error = 1;
62 SDL_strncpy((char *)error->key, fmt, sizeof(error->key)); 62 SDL_strlcpy((char *)error->key, fmt, sizeof(error->key));
63 error->key[sizeof(error->key)-1] = '\0';
64 63
65 va_start(ap, fmt); 64 va_start(ap, fmt);
66 error->argc = 0; 65 error->argc = 0;
67 while ( *fmt ) { 66 while ( *fmt ) {
68 if ( *fmt++ == '%' ) { 67 if ( *fmt++ == '%' ) {
92 { 91 {
93 int index = error->argc; 92 int index = error->argc;
94 char *str = va_arg(ap, char *); 93 char *str = va_arg(ap, char *);
95 if (str == NULL) 94 if (str == NULL)
96 str = "(null)"; 95 str = "(null)";
97 SDL_strncpy((char *)error->args[index].buf, str, ERR_MAX_STRLEN); 96 SDL_strlcpy((char *)error->args[index].buf, str, ERR_MAX_STRLEN);
98 error->args[index].buf[ERR_MAX_STRLEN-1] = 0;
99 error->argc++; 97 error->argc++;
100 } 98 }
101 break; 99 break;
102 default: 100 default:
103 break; 101 break;
249 unsigned int i; 247 unsigned int i;
250 248
251 /* Allocate the UNICODE buffer */ 249 /* Allocate the UNICODE buffer */
252 errstr16 = (Uint16 *)SDL_malloc(maxlen * (sizeof *errstr16)); 250 errstr16 = (Uint16 *)SDL_malloc(maxlen * (sizeof *errstr16));
253 if ( ! errstr16 ) { 251 if ( ! errstr16 ) {
254 SDL_strncpy((char *)errstr, "Out of memory", maxlen); 252 SDL_strlcpy((char *)errstr, "Out of memory", maxlen);
255 errstr[maxlen-1] = '\0';
256 return(errstr); 253 return(errstr);
257 } 254 }
258 255
259 /* Get the error message */ 256 /* Get the error message */
260 SDL_GetErrorMsgUNICODE(errstr16, maxlen); 257 SDL_GetErrorMsgUNICODE(errstr16, maxlen);