comparison src/stdlib/SDL_getenv.c @ 1379:c0a74f199ecf

Use only safe string functions
author Sam Lantinga <slouken@libsdl.org>
date Sun, 19 Feb 2006 23:46:34 +0000
parents c71e05b4dc2e
children d910939febfa
comparison
equal deleted inserted replaced
1378:dc0e13e7e1ae 1379:c0a74f199ecf
51 return -1; 51 return -1;
52 } 52 }
53 SDL_envmem = newmem; 53 SDL_envmem = newmem;
54 SDL_envmemlen = bufferlen; 54 SDL_envmemlen = bufferlen;
55 } 55 }
56 SDL_strcpy(SDL_envmem, variable); 56 SDL_strlcpy(SDL_envmem, variable, bufferlen);
57 value = SDL_envmem + (sep - variable); 57 value = SDL_envmem + (sep - variable);
58 *value++ = '\0'; 58 *value++ = '\0';
59 if ( !SetEnvironmentVariable(SDL_envmem, *value ? value : NULL) ) { 59 if ( !SetEnvironmentVariable(SDL_envmem, *value ? value : NULL) ) {
60 return -1; 60 return -1;
61 } 61 }
109 } else { 109 } else {
110 return(-1); 110 return(-1);
111 } 111 }
112 112
113 /* Allocate memory for the variable */ 113 /* Allocate memory for the variable */
114 new_variable = (char *)SDL_malloc(SDL_strlen(variable)+1); 114 new_variable = SDL_strdup(variable);
115 if ( ! new_variable ) { 115 if ( ! new_variable ) {
116 return(-1); 116 return(-1);
117 } 117 }
118 SDL_strcpy(new_variable, variable);
119 118
120 /* Actually put it into the environment */ 119 /* Actually put it into the environment */
121 added = 0; 120 added = 0;
122 i = 0; 121 i = 0;
123 if ( SDL_env ) { 122 if ( SDL_env ) {