diff --git a/src/cdrom/beos/SDL_syscdrom.cc b/src/cdrom/beos/SDL_syscdrom.cc index ae5e058be..5cb68e710 100644 --- a/src/cdrom/beos/SDL_syscdrom.cc +++ b/src/cdrom/beos/SDL_syscdrom.cc @@ -109,16 +109,18 @@ static int CheckDrive(char *drive) static void AddDrive(char *drive) { int i; + size_t len; if ( SDL_numcds < MAX_DRIVES ) { /* Add this drive to our list */ i = SDL_numcds; - SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1); + len = SDL_strlen(drive)+1; + SDL_cdlist[i] = (char *)SDL_malloc(len); if ( SDL_cdlist[i] == NULL ) { SDL_OutOfMemory(); return; } - SDL_strcpy(SDL_cdlist[i], drive); + SDL_strlcpy(SDL_cdlist[i], drive, len); ++SDL_numcds; #ifdef CDROM_DEBUG fprintf(stderr, "Added CD-ROM drive: %s\n", drive); @@ -165,9 +167,10 @@ int SDL_SYS_CDInit(void) SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ if ( SDLcdrom != NULL ) { char *cdpath, *delim; - cdpath = (char *)SDL_malloc(SDL_strlen(SDLcdrom)+1); + size_t len = SDL_strlen(SDLcdrom)+1; + cdpath = SDL_stack_alloc(char, len); if ( cdpath != NULL ) { - SDL_strcpy(cdpath, SDLcdrom); + SDL_strlcpy(cdpath, SDLcdrom, len); SDLcdrom = cdpath; do { delim = SDL_strchr(SDLcdrom, ':'); @@ -183,7 +186,7 @@ int SDL_SYS_CDInit(void) SDLcdrom = NULL; } } while ( SDLcdrom ); - SDL_free(cdpath); + SDL_stack_free(cdpath); } /* If we found our drives, there's nothing left to do */ diff --git a/src/main/macosx/SDLMain.m b/src/main/macosx/SDLMain.m index 2c26c0f86..66e30f14b 100644 --- a/src/main/macosx/SDLMain.m +++ b/src/main/macosx/SDLMain.m @@ -252,19 +252,20 @@ static void CustomApplicationMain (int argc, char **argv) return FALSE; const char *temparg = [filename UTF8String]; - char *arg = (char *) malloc(strlen(temparg) + 1); + size_t arglen = SDL_strlen(temparg) + 1; + char *arg = (char *) SDL_malloc(arglen); if (arg == NULL) return FALSE; char **newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2)); if (newargv == NULL) { - free(arg); + SDL_free(arg); return FALSE; } gArgv = newargv; - strcpy(arg, temparg); + SDL_strlcpy(arg, temparg, arglen); gArgv[gArgc++] = arg; gArgv[gArgc] = NULL; return TRUE; @@ -346,7 +347,7 @@ int main (int argc, char **argv) /* Copy the arguments into a global variable */ /* This is passed if we are launched by double-clicking */ if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { - gArgv = (char **) malloc(sizeof (char *) * 2); + gArgv = (char **) SDL_malloc(sizeof (char *) * 2); gArgv[0] = argv[0]; gArgv[1] = NULL; gArgc = 1; @@ -354,7 +355,7 @@ int main (int argc, char **argv) } else { int i; gArgc = argc; - gArgv = (char **) malloc(sizeof (char *) * (argc+1)); + gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1)); for (i = 0; i <= argc; i++) gArgv[i] = argv[i]; gFinderLaunch = NO; diff --git a/src/video/bwindow/SDL_sysvideo.cc b/src/video/bwindow/SDL_sysvideo.cc index 0a6f4ac8c..18e305ad4 100644 --- a/src/video/bwindow/SDL_sysvideo.cc +++ b/src/video/bwindow/SDL_sysvideo.cc @@ -639,7 +639,7 @@ int BE_GL_LoadLibrary(_THIS, const char *path) if (get_image_symbol((image_id)cookie,"glBegin",B_SYMBOL_TYPE_ANY,&location) == B_OK) { _this->gl_config.dll_handle = (void*)cookie; _this->gl_config.driver_loaded = 1; - SDL_strncpy(_this->gl_config.driver_path, "libGL.so", sizeof(_this->gl_config.driver_path)-1); + SDL_strlcpy(_this->gl_config.driver_path, "libGL.so", SDL_arraysize(_this->gl_config.driver_path)); } } } @@ -667,7 +667,7 @@ int BE_GL_LoadLibrary(_THIS, const char *path) if ((_this->gl_config.dll_handle = (void*)load_add_on(path)) != (void*)B_ERROR) { _this->gl_config.driver_loaded = 1; - SDL_strncpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path)-1); + SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path)); }*/ } @@ -676,7 +676,7 @@ int BE_GL_LoadLibrary(_THIS, const char *path) } else { _this->gl_config.dll_handle = NULL; _this->gl_config.driver_loaded = 0; - SDL_strcpy(_this->gl_config.driver_path, ""); + *_this->gl_config.driver_path = '\0'; return -1; } }