# HG changeset patch # User Sam Lantinga # Date 1140392794 0 # Node ID c0a74f199ecf89dad7eacea1dd6472089a3f00c0 # Parent dc0e13e7e1aee6963706a8636a76f628971e3290 Use only safe string functions diff -r dc0e13e7e1ae -r c0a74f199ecf configure.in --- a/configure.in Sun Feb 19 23:38:57 2006 +0000 +++ b/configure.in Sun Feb 19 23:46:34 2006 +0000 @@ -119,7 +119,7 @@ if test x$ac_cv_func_strtod = xyes; then AC_DEFINE(HAVE_STRTOD) fi - AC_CHECK_FUNCS(malloc calloc realloc free getenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strcpy strncpy strcat strncat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol _i64toa _ui64toa strtoll atoi atof strcmp strncmp stricmp strcasecmp sscanf snprintf vsnprintf sigaction setjmp nanosleep) + AC_CHECK_FUNCS(malloc calloc realloc free getenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol _i64toa _ui64toa strtoll atoi atof strcmp strncmp stricmp strcasecmp sscanf snprintf vsnprintf sigaction setjmp nanosleep) AC_CHECK_LIB(m, pow, [BUILD_LIBS="$BUILD_LIBS -lm"]) fi diff -r dc0e13e7e1ae -r c0a74f199ecf include/SDL_config.h.in --- a/include/SDL_config.h.in Sun Feb 19 23:38:57 2006 +0000 +++ b/include/SDL_config.h.in Sun Feb 19 23:46:34 2006 +0000 @@ -87,10 +87,8 @@ #undef HAVE_MEMMOVE #undef HAVE_MEMCMP #undef HAVE_STRLEN -#undef HAVE_STRCPY -#undef HAVE_STRNCPY -#undef HAVE_STRCAT -#undef HAVE_STRNCAT +#undef HAVE_STRLCPY +#undef HAVE_STRLCAT #undef HAVE_STRDUP #undef HAVE__STRREV #undef HAVE__STRUPR diff -r dc0e13e7e1ae -r c0a74f199ecf include/SDL_stdinc.h --- a/include/SDL_stdinc.h Sun Feb 19 23:38:57 2006 +0000 +++ b/include/SDL_stdinc.h Sun Feb 19 23:46:34 2006 +0000 @@ -206,6 +206,9 @@ #define SDL_abs(X) ((X) < 0 ? -(X) : (X)) #endif +#define SDL_min(x, y) (((x) < (y)) ? (x) : (y)) +#define SDL_max(x, y) (((x) > (y)) ? (x) : (y)) + #if HAVE_CTYPE_H #define SDL_isdigit(X) isdigit(X) #define SDL_isspace(X) isspace(X) @@ -355,28 +358,16 @@ extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string); #endif -#if HAVE_STRCPY -#define SDL_strcpy strcpy +#if HAVE_STRLCPY +#define SDL_strlcpy strlcpy #else -extern DECLSPEC char * SDLCALL SDL_strcpy(char *dst, const char *src); +extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen); #endif -#if HAVE_STRNCPY -#define SDL_strncpy strncpy +#if HAVE_STRLCAT +#define SDL_strlcat strlcat #else -extern DECLSPEC char * SDLCALL SDL_strncpy(char *dst, const char *src, size_t maxlen); -#endif - -#if HAVE_STRCAT -#define SDL_strcat strcat -#else -#define SDL_strcat(dst, src) (SDL_strcpy(dst+SDL_strlen(dst), src), dst) -#endif - -#if HAVE_STRNCAT -#define SDL_strncat strncat -#else -#define SDL_strncat(dst, src, n) (SDL_strncpy(dst+SDL_strlen(dst), src, n), dst) +extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen); #endif #if HAVE_STRDUP diff -r dc0e13e7e1ae -r c0a74f199ecf src/SDL_error.c --- a/src/SDL_error.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/SDL_error.c Sun Feb 19 23:46:34 2006 +0000 @@ -59,8 +59,7 @@ /* Copy in the key, mark error as valid */ error = SDL_GetErrBuf(); error->error = 1; - SDL_strncpy((char *)error->key, fmt, sizeof(error->key)); - error->key[sizeof(error->key)-1] = '\0'; + SDL_strlcpy((char *)error->key, fmt, sizeof(error->key)); va_start(ap, fmt); error->argc = 0; @@ -94,8 +93,7 @@ char *str = va_arg(ap, char *); if (str == NULL) str = "(null)"; - SDL_strncpy((char *)error->args[index].buf, str, ERR_MAX_STRLEN); - error->args[index].buf[ERR_MAX_STRLEN-1] = 0; + SDL_strlcpy((char *)error->args[index].buf, str, ERR_MAX_STRLEN); error->argc++; } break; @@ -251,8 +249,7 @@ /* Allocate the UNICODE buffer */ errstr16 = (Uint16 *)SDL_malloc(maxlen * (sizeof *errstr16)); if ( ! errstr16 ) { - SDL_strncpy((char *)errstr, "Out of memory", maxlen); - errstr[maxlen-1] = '\0'; + SDL_strlcpy((char *)errstr, "Out of memory", maxlen); return(errstr); } diff -r dc0e13e7e1ae -r c0a74f199ecf src/audio/SDL_audio.c --- a/src/audio/SDL_audio.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/audio/SDL_audio.c Sun Feb 19 23:46:34 2006 +0000 @@ -373,8 +373,7 @@ char *SDL_AudioDriverName(char *namebuf, int maxlen) { if ( current_audio != NULL ) { - SDL_strncpy(namebuf, current_audio->name, maxlen-1); - namebuf[maxlen-1] = '\0'; + SDL_strlcpy(namebuf, current_audio->name, maxlen); return(namebuf); } return(NULL); diff -r dc0e13e7e1ae -r c0a74f199ecf src/audio/SDL_audiodev.c --- a/src/audio/SDL_audiodev.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/audio/SDL_audiodev.c Sun Feb 19 23:46:34 2006 +0000 @@ -89,7 +89,7 @@ audiodev = audiopath; } if ( path != NULL ) { - SDL_strncpy(path, audiodev, maxlen); + SDL_strlcpy(path, audiodev, maxlen); path[maxlen-1] = '\0'; } return(audio_fd); @@ -136,7 +136,7 @@ } audio_fd = open(audiodev, flags, 0); if ( path != NULL ) { - SDL_strncpy(path, audiodev, maxlen); + SDL_strlcpy(path, audiodev, maxlen); path[maxlen-1] = '\0'; } return audio_fd; @@ -166,8 +166,7 @@ audio_fd = open(audiopath, flags, 0); if ( audio_fd > 0 ) { if ( path != NULL ) { - SDL_strncpy( path, audiopath, maxlen ); - path[maxlen-1] = '\0'; + SDL_strlcpy( path, audiopath, maxlen ); } return audio_fd; } diff -r dc0e13e7e1ae -r c0a74f199ecf src/audio/alsa/SDL_alsa_audio.c --- a/src/audio/alsa/SDL_alsa_audio.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/audio/alsa/SDL_alsa_audio.c Sun Feb 19 23:46:34 2006 +0000 @@ -124,7 +124,7 @@ if (alsa_handle) { alsa_loaded = 1; retval = 0; - for (i = 0; i < SDL_TABLESIZE(alsa_functions); i++) { + for (i = 0; i < SDL_arraysize(alsa_functions); i++) { /* *alsa_functions[i].func = SDL_LoadFunction(alsa_handle,alsa_functions[i].name);*/ #if HAVE_DLVSYM *alsa_functions[i].func = dlvsym(alsa_handle,alsa_functions[i].name,"ALSA_0.9"); diff -r dc0e13e7e1ae -r c0a74f199ecf src/audio/arts/SDL_artsaudio.c --- a/src/audio/arts/SDL_artsaudio.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/audio/arts/SDL_artsaudio.c Sun Feb 19 23:46:34 2006 +0000 @@ -90,7 +90,7 @@ if ( arts_handle ) { arts_loaded = 1; retval = 0; - for ( i=0; ist_rdev; ++SDL_numcds; #ifdef DEBUG_CDROM @@ -302,9 +301,10 @@ SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ if ( SDLcdrom != NULL ) { char *cdpath, *delim; - cdpath = 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, ':'); @@ -323,7 +323,7 @@ SDLcdrom = NULL; } } while ( SDLcdrom ); - SDL_free(cdpath); + SDL_stack_free(cdpath); } /* If we found our drives, there's nothing left to do */ @@ -360,21 +360,23 @@ int fd; char* lastsl; char* cdromname; + size_t len; /* * We found /dev/cd? drives and that is in our list. But we can * open only the /dev/rcd? versions of those devices for Audio CD. */ - cdromname = (char*)SDL_malloc( SDL_strlen(SDL_cdlist[drive]+2) ); - SDL_strcpy(cdromname,SDL_cdlist[drive]); + len = SDL_strlen(SDL_cdlist[drive])+2; + cdromname = (char*)SDL_malloc(len); + SDL_strlcpy(cdromname,SDL_cdlist[drive],len); lastsl = SDL_strrchr(cdromname,'/'); if (lastsl) { *lastsl = 0; - strcat(cdromname,"/r"); + SDL_strlcat(cdromname,"/r",len); lastsl = SDL_strrchr(SDL_cdlist[drive],'/'); if (lastsl) { lastsl++; - strcat(cdromname,lastsl); + SDL_strlcat(cdromname,lastsl,len); } } diff -r dc0e13e7e1ae -r c0a74f199ecf src/cdrom/bsdi/SDL_syscdrom.c --- a/src/cdrom/bsdi/SDL_syscdrom.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/cdrom/bsdi/SDL_syscdrom.c Sun Feb 19 23:46:34 2006 +0000 @@ -224,12 +224,11 @@ /* Add this drive to our list */ i = SDL_numcds; - SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1); + SDL_cdlist[i] = SDL_strdup(drive); if ( SDL_cdlist[i] == NULL ) { SDL_OutOfMemory(); return; } - SDL_strcpy(SDL_cdlist[i], drive); SDL_cdmode[i] = stbuf->st_rdev; ++SDL_numcds; #ifdef DEBUG_CDROM @@ -265,9 +264,10 @@ SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ if ( SDLcdrom != NULL ) { char *cdpath, *delim; - cdpath = 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, ':'); @@ -283,7 +283,7 @@ SDLcdrom = NULL; } } while ( SDLcdrom ); - SDL_free(cdpath); + SDL_stack_free(cdpath); } /* If we found our drives, there's nothing left to do */ diff -r dc0e13e7e1ae -r c0a74f199ecf src/cdrom/freebsd/SDL_syscdrom.c --- a/src/cdrom/freebsd/SDL_syscdrom.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/cdrom/freebsd/SDL_syscdrom.c Sun Feb 19 23:46:34 2006 +0000 @@ -110,12 +110,11 @@ /* Add this drive to our list */ i = SDL_numcds; - SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1); + SDL_cdlist[i] = SDL_strdup(drive); if ( SDL_cdlist[i] == NULL ) { SDL_OutOfMemory(); return; } - SDL_strcpy(SDL_cdlist[i], drive); SDL_cdmode[i] = stbuf->st_rdev; ++SDL_numcds; #ifdef DEBUG_CDROM @@ -152,9 +151,10 @@ SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ if ( SDLcdrom != NULL ) { char *cdpath, *delim; - cdpath = 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, ':'); @@ -170,7 +170,7 @@ SDLcdrom = NULL; } } while ( SDLcdrom ); - SDL_free(cdpath); + SDL_stack_free(cdpath); } /* If we found our drives, there's nothing left to do */ diff -r dc0e13e7e1ae -r c0a74f199ecf src/cdrom/linux/SDL_syscdrom.c --- a/src/cdrom/linux/SDL_syscdrom.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/cdrom/linux/SDL_syscdrom.c Sun Feb 19 23:46:34 2006 +0000 @@ -167,12 +167,11 @@ /* Add this drive to our list */ i = SDL_numcds; - SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1); + SDL_cdlist[i] = SDL_strdup(drive); if ( SDL_cdlist[i] == NULL ) { SDL_OutOfMemory(); return; } - SDL_strcpy(SDL_cdlist[i], drive); SDL_cdmode[i] = stbuf->st_rdev; ++SDL_numcds; #ifdef DEBUG_CDROM @@ -192,21 +191,25 @@ if ( mntfp != NULL ) { char *tmp; char *mnt_type; + size_t mnt_type_len; char *mnt_dev; + size_t mnt_dev_len; while ( (mntent=getmntent(mntfp)) != NULL ) { - mnt_type = SDL_malloc(SDL_strlen(mntent->mnt_type) + 1); + mnt_type_len = SDL_strlen(mntent->mnt_type) + 1; + mnt_type = SDL_stack_alloc(char, mnt_type_len); if (mnt_type == NULL) continue; /* maybe you'll get lucky next time. */ - mnt_dev = SDL_malloc(SDL_strlen(mntent->mnt_fsname) + 1); + mnt_dev_len = SDL_strlen(mntent->mnt_fsname) + 1; + mnt_dev = SDL_stack_alloc(char, mnt_dev_len); if (mnt_dev == NULL) { - SDL_free(mnt_type); + SDL_stack_free(mnt_type); continue; } - SDL_strcpy(mnt_type, mntent->mnt_type); - SDL_strcpy(mnt_dev, mntent->mnt_fsname); + SDL_strlcpy(mnt_type, mntent->mnt_type, mnt_type_len); + SDL_strlcpy(mnt_dev, mntent->mnt_fsname, mnt_dev_len); /* Handle "supermount" filesystem mounts */ if ( SDL_strcmp(mnt_type, MNTTYPE_SUPER) == 0 ) { @@ -242,8 +245,8 @@ AddDrive(mnt_dev, &stbuf); } } - SDL_free(mnt_dev); - SDL_free(mnt_type); + SDL_stack_free(mnt_dev); + SDL_stack_free(mnt_type); } endmntent(mntfp); } @@ -277,9 +280,10 @@ SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ if ( SDLcdrom != NULL ) { char *cdpath, *delim; - cdpath = 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, ':'); @@ -298,7 +302,7 @@ SDLcdrom = NULL; } } while ( SDLcdrom ); - SDL_free(cdpath); + SDL_stack_free(cdpath); } /* If we found our drives, there's nothing left to do */ diff -r dc0e13e7e1ae -r c0a74f199ecf src/cdrom/openbsd/SDL_syscdrom.c --- a/src/cdrom/openbsd/SDL_syscdrom.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/cdrom/openbsd/SDL_syscdrom.c Sun Feb 19 23:46:34 2006 +0000 @@ -115,12 +115,11 @@ /* Add this drive to our list */ i = SDL_numcds; - SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1); + SDL_cdlist[i] = SDL_strdup(drive); if ( SDL_cdlist[i] == NULL ) { SDL_OutOfMemory(); return; } - SDL_strcpy(SDL_cdlist[i], drive); SDL_cdmode[i] = stbuf->st_rdev; ++SDL_numcds; #ifdef DEBUG_CDROM @@ -161,9 +160,10 @@ SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ if ( SDLcdrom != NULL ) { char *cdpath, *delim; - cdpath = 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, ':'); @@ -179,7 +179,7 @@ SDLcdrom = NULL; } } while ( SDLcdrom ); - SDL_free(cdpath); + SDL_stack_free(cdpath); } /* If we found our drives, there's nothing left to do */ diff -r dc0e13e7e1ae -r c0a74f199ecf src/cdrom/os2/SDL_syscdrom.c --- a/src/cdrom/os2/SDL_syscdrom.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/cdrom/os2/SDL_syscdrom.c Sun Feb 19 23:46:34 2006 +0000 @@ -94,13 +94,12 @@ { msp.ulNumber = i+1; mciSendCommand(0,MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_WAIT,&msp, 0); - SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(SysInfoRet)+1); + SDL_cdlist[i] = SDL_strdup(SysInfoRet); if ( SDL_cdlist[i] == NULL ) { SDL_OutOfMemory(); return(-1); } - SDL_strcpy(SDL_cdlist[i], SysInfoRet); } return(0); } diff -r dc0e13e7e1ae -r c0a74f199ecf src/cdrom/osf/SDL_syscdrom.c --- a/src/cdrom/osf/SDL_syscdrom.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/cdrom/osf/SDL_syscdrom.c Sun Feb 19 23:46:34 2006 +0000 @@ -119,13 +119,11 @@ /* Add this drive to our list */ i = SDL_numcds; - SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1); + SDL_cdlist[i] = SDL_strdup(drive); if ( SDL_cdlist[i] == NULL ) { SDL_OutOfMemory(); return; } - - SDL_strcpy(SDL_cdlist[i], drive); SDL_cdmode[i] = stbuf->st_rdev; ++SDL_numcds; #ifdef DEBUG_CDROM @@ -174,9 +172,10 @@ SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ if ( SDLcdrom != NULL ) { char *cdpath, *delim; - cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1); + size_t len = SDL_strlen(SDLcdrom)+1; + cdpath = SDL_stack_alloc(len); if ( cdpath != NULL ) { - SDL_strcpy(cdpath, SDLcdrom); + SDL_strlcpy(cdpath, SDLcdrom, len); SDLcdrom = cdpath; do { delim = SDL_strchr(SDLcdrom, ':'); @@ -192,7 +191,7 @@ SDLcdrom = NULL; } } while ( SDLcdrom ); - SDL_free(cdpath); + SDL_stack_free(cdpath); } /* If we found our drives, there's nothing left to do */ @@ -226,15 +225,6 @@ #endif } } - -/* - SDLcdrom=SDL_malloc(sizeof(char) * 32); - SDL_strcpy(SDLcdrom,"/dev/rdisk/cdrom0c"); - SDL_cdlist[0] = SDLcdrom; - stat(SDLcdrom, &stbuf); - SDL_cdmode[0] = stbuf.st_rdev; - SDL_numcds = 1; - */ return (0); } diff -r dc0e13e7e1ae -r c0a74f199ecf src/cdrom/qnx/SDL_syscdrom.c --- a/src/cdrom/qnx/SDL_syscdrom.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/cdrom/qnx/SDL_syscdrom.c Sun Feb 19 23:46:34 2006 +0000 @@ -124,13 +124,12 @@ /* Add this drive to our list */ i = SDL_numcds; - SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1); + SDL_cdlist[i] = SDL_strdup(drive); if (SDL_cdlist[i] == NULL) { SDL_OutOfMemory(); return; } - SDL_strcpy(SDL_cdlist[i], drive); SDL_cdmode[i] = stbuf->st_rdev; ++SDL_numcds; } @@ -169,11 +168,11 @@ if ( SDLcdrom != NULL ) { char *cdpath, *delim; - - cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1); + size_t len = SDL_strlen(SDLcdrom)+1; + cdpath = SDL_stack_alloc(len); if (cdpath != NULL) { - SDL_strcpy(cdpath, SDLcdrom); + SDL_strlcpy(cdpath, SDLcdrom, len); SDLcdrom = cdpath; do { delim = SDL_strchr(SDLcdrom, ':'); @@ -194,7 +193,7 @@ SDLcdrom = NULL; } } while (SDLcdrom); - SDL_free(cdpath); + SDL_stack_free(cdpath); } /* If we found our drives, there's nothing left to do */ diff -r dc0e13e7e1ae -r c0a74f199ecf src/cdrom/win32/SDL_syscdrom.c --- a/src/cdrom/win32/SDL_syscdrom.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/cdrom/win32/SDL_syscdrom.c Sun Feb 19 23:46:34 2006 +0000 @@ -63,12 +63,11 @@ if ( SDL_numcds < MAX_DRIVES ) { /* Add this drive to our list */ i = SDL_numcds; - SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1); + SDL_cdlist[i] = SDL_strdup(drive); if ( SDL_cdlist[i] == NULL ) { SDL_OutOfMemory(); return; } - SDL_strcpy(SDL_cdlist[i], drive); ++SDL_numcds; #ifdef CDROM_DEBUG fprintf(stderr, "Added CD-ROM drive: %s\n", drive); diff -r dc0e13e7e1ae -r c0a74f199ecf src/joystick/SDL_joystick.c --- a/src/joystick/SDL_joystick.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/joystick/SDL_joystick.c Sun Feb 19 23:46:34 2006 +0000 @@ -554,7 +554,7 @@ switch (state) { case SDL_QUERY: state = SDL_IGNORE; - for ( i=0; i= 0 ) { /* Assume the user knows what they're doing. */ - SDL_joylist[numjoysticks].fname =mystrdup(path); + SDL_joylist[numjoysticks].fname = SDL_strdup(path); if ( SDL_joylist[numjoysticks].fname ) { dev_nums[numjoysticks] = sb.st_rdev; ++numjoysticks; @@ -319,7 +307,7 @@ } } - for ( i=0; inaxes = special_joysticks[i].naxes; @@ -503,7 +491,7 @@ /* User environment joystick support */ if ( (env = SDL_getenv("SDL_LINUX_JOYSTICK")) ) { - SDL_strcpy(env_name, ""); + *env_name = '\0'; if ( *env == '\'' && SDL_sscanf(env, "'%[^']s'", env_name) == 1 ) env += SDL_strlen(env_name)+2; else if ( SDL_sscanf(env, "%s", env_name) == 1 ) diff -r dc0e13e7e1ae -r c0a74f199ecf src/joystick/macos/SDL_sysjoystick.c --- a/src/joystick/macos/SDL_sysjoystick.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/joystick/macos/SDL_sysjoystick.c Sun Feb 19 23:46:34 2006 +0000 @@ -165,7 +165,7 @@ return(-1); } SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); - SDL_strcpy(joystick->hwdata->name, SDL_SYS_JoystickName(index)); + SDL_strlcpy(joystick->hwdata->name, SDL_SYS_JoystickName(index), SDL_arraysize(joystick->hwdata->name)); joystick->name = joystick->hwdata->name; ISpElementList_ExtractByKind( diff -r dc0e13e7e1ae -r c0a74f199ecf src/joystick/os2/SDL_sysjoystick.c --- a/src/joystick/os2/SDL_sysjoystick.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/joystick/os2/SDL_sysjoystick.c Sun Feb 19 23:46:34 2006 +0000 @@ -214,7 +214,7 @@ if (joycfg.buttons>=7) SYS_JoyData[0].buttoncalc[2]=((axis[2]->upper+axis[3]->centre)>>1); if (joycfg.buttons>=8) SYS_JoyData[0].buttoncalc[3]=((axis[3]->upper+axis[3]->centre)>>1); /* Intialize Joystick Name */ - SDL_strcpy (SYS_JoyData[0].szDeviceName,joycfg.name); + SDL_strlcpy (SYS_JoyData[0].szDeviceName,joycfg.name, SDL_arraysize(SYS_JoyData[0].szDeviceName)); } /* Default Init ... autoconfig */ else diff -r dc0e13e7e1ae -r c0a74f199ecf src/loadso/dlopen/SDL_sysloadso.c --- a/src/loadso/dlopen/SDL_sysloadso.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/loadso/dlopen/SDL_sysloadso.c Sun Feb 19 23:46:34 2006 +0000 @@ -42,9 +42,10 @@ { void *symbol = dlsym(handle, name); if ( symbol == NULL ) { - char *_name = SDL_stack_alloc(char, 1+SDL_strlen(name)+1); + size_t len = 1+SDL_strlen(name)+1; + char *_name = SDL_stack_alloc(char, len); _name[0] = '_'; - SDL_strcpy(&_name[1], name); + SDL_strlcpy(&_name[1], name, len); symbol = dlsym(handle, name); SDL_stack_free(_name); if ( symbol == NULL ) { diff -r dc0e13e7e1ae -r c0a74f199ecf src/loadso/macos/SDL_sysloadso.c --- a/src/loadso/macos/SDL_sysloadso.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/loadso/macos/SDL_sysloadso.c Sun Feb 19 23:46:34 2006 +0000 @@ -42,8 +42,7 @@ OSErr error; char psofile[512]; - SDL_strncpy(psofile, sofile, SDL_TABLESIZE(psofile)); - psofile[SDL_TABLESIZE(psofile)-1] = '\0'; + SDL_strlcpy(psofile, sofile, SDL_arraysize(psofile)); error = GetSharedLibrary(C2PStr(psofile), kCompiledCFragArch, kLoadCFrag, &library_id, &mainAddr, errName); switch (error) { @@ -80,8 +79,7 @@ CFragConnectionID library_id = (CFragConnectionID)handle; char pname[512]; - SDL_strncpy(pname, name, SDL_TABLESIZE(pname)); - pname[SDL_TABLESIZE(pname)-1] = '\0'; + SDL_strlcpy(pname, name, SDL_arraysize(pname)); if ( FindSymbol(library_id, C2PStr(pname), (char **)&symbol, &class) != noErr ) { loaderror = "Symbol not found"; diff -r dc0e13e7e1ae -r c0a74f199ecf src/loadso/macosx/SDL_sysloadso.c --- a/src/loadso/macosx/SDL_sysloadso.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/loadso/macosx/SDL_sysloadso.c Sun Feb 19 23:46:34 2006 +0000 @@ -281,7 +281,7 @@ va_start(arg, str); tss = pthread_getspecific(dlerror_key); err_str = tss->errstr; - SDL_strncpy(err_str, "dlcompat: ", ERR_STR_LEN); + SDL_strlcpy(err_str, "dlcompat: ", ERR_STR_LEN); vsnprintf(err_str + 10, ERR_STR_LEN - 10, str, arg); va_end(arg); debug("ERROR: %s\n", err_str); @@ -620,18 +620,17 @@ } /* Up to the caller to SDL_free() returned string */ -static inline const char *dyld_error_str() +static inline char *dyld_error_str() { NSLinkEditErrors dylder; int dylderno; const char *dylderrstr; const char *dyldfile; - const char* retStr = NULL; + char* retStr = NULL; NSLinkEditError(&dylder, &dylderno, &dyldfile, &dylderrstr); - if (dylderrstr && SDL_strlen(dylderrstr)) + if (dylderrstr && *dylderrstr) { - retStr = SDL_malloc(SDL_strlen(dylderrstr) +1); - SDL_strcpy((char*)retStr,dylderrstr); + retStr = SDL_strdup(dylderrstr); } return retStr; } @@ -645,7 +644,7 @@ void *caller = NULL; #endif const struct mach_header *caller_mh = 0; - const char* savedErrorStr = NULL; + char* savedErrorStr = NULL; resetdlerror(); #ifndef RTLD_SELF #define RTLD_SELF ((void *) -3) @@ -734,9 +733,9 @@ else { if (savedErrorStr) - SDL_free((char*)savedErrorStr); + SDL_free(savedErrorStr); savedErrorStr = SDL_malloc(256); - SDL_snprintf((char*)savedErrorStr, 256, "Symbol \"%s\" not in global context",symbol); + SDL_snprintf(savedErrorStr, 256, "Symbol \"%s\" not in global context",symbol); } } } @@ -746,9 +745,9 @@ if (!savedErrorStr || !SDL_strlen(savedErrorStr)) { if (savedErrorStr) - SDL_free((char*)savedErrorStr); + SDL_free(savedErrorStr); savedErrorStr = SDL_malloc(256); - SDL_snprintf((char*)savedErrorStr, 256,"Symbol \"%s\" not found",symbol); + SDL_snprintf(savedErrorStr, 256,"Symbol \"%s\" not found",symbol); } if (canSetError) { @@ -759,7 +758,7 @@ debug(savedErrorStr); } if (savedErrorStr) - SDL_free((char*)savedErrorStr); + SDL_free(savedErrorStr); return NULL; } return NSAddressOfSymbol(nssym); diff -r dc0e13e7e1ae -r c0a74f199ecf src/loadso/win32/SDL_sysloadso.c --- a/src/loadso/win32/SDL_sysloadso.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/loadso/win32/SDL_sysloadso.c Sun Feb 19 23:46:34 2006 +0000 @@ -47,7 +47,7 @@ FORMAT_MESSAGE_FROM_SYSTEM), NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - errbuf_t, SDL_TABLESIZE(errbuf), NULL); + errbuf_t, SDL_arraysize(errbuf), NULL); WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL); loaderror = errbuf; } @@ -66,7 +66,7 @@ FORMAT_MESSAGE_FROM_SYSTEM), NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - errbuf, SDL_TABLESIZE(errbuf), NULL); + errbuf, SDL_arraysize(errbuf), NULL); loaderror = errbuf; } #endif @@ -97,7 +97,7 @@ FORMAT_MESSAGE_FROM_SYSTEM), NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - errbuf_t, SDL_TABLESIZE(errbuf), NULL); + errbuf_t, SDL_arraysize(errbuf), NULL); WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL); loaderror = errbuf; } @@ -114,7 +114,7 @@ FORMAT_MESSAGE_FROM_SYSTEM), NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - errbuf, SDL_TABLESIZE(errbuf), NULL); + errbuf, SDL_arraysize(errbuf), NULL); loaderror = errbuf; } #endif diff -r dc0e13e7e1ae -r c0a74f199ecf src/main/win32/SDL_win32_main.c --- 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 @@ -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; } diff -r dc0e13e7e1ae -r c0a74f199ecf src/stdlib/SDL_getenv.c --- a/src/stdlib/SDL_getenv.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/stdlib/SDL_getenv.c Sun Feb 19 23:46:34 2006 +0000 @@ -53,7 +53,7 @@ SDL_envmem = newmem; SDL_envmemlen = bufferlen; } - SDL_strcpy(SDL_envmem, variable); + SDL_strlcpy(SDL_envmem, variable, bufferlen); value = SDL_envmem + (sep - variable); *value++ = '\0'; if ( !SetEnvironmentVariable(SDL_envmem, *value ? value : NULL) ) { @@ -111,11 +111,10 @@ } /* Allocate memory for the variable */ - new_variable = (char *)SDL_malloc(SDL_strlen(variable)+1); + new_variable = SDL_strdup(variable); if ( ! new_variable ) { return(-1); } - SDL_strcpy(new_variable, variable); /* Actually put it into the environment */ added = 0; diff -r dc0e13e7e1ae -r c0a74f199ecf src/stdlib/SDL_string.c --- a/src/stdlib/SDL_string.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/stdlib/SDL_string.c Sun Feb 19 23:46:34 2006 +0000 @@ -294,39 +294,38 @@ } #endif -#ifndef HAVE_STRCPY -char *SDL_strcpy(char *dst, const char *src) +#ifndef HAVE_STRLCPY +size_t SDL_strlcpy(char *dst, const char *src, size_t maxlen) { - char *dstp = dst; - while ( *src ) { - *dstp++ = *src++; + size_t srclen = SDL_strlen(src); + if ( maxlen > 0 ) { + size_t len = SDL_min(srclen, maxlen-1); + SDL_memcpy(dst, src, len); + dst[len] = '\0'; } - *dstp = '\0'; - - return dst; + return srclen; } #endif -#ifndef HAVE_STRNCPY -char *SDL_strncpy(char *dst, const char *src, size_t maxlen) +#ifndef HAVE_STRLCAT +size_t SDL_strlcat(char *dst, const char *src, size_t maxlen) { - char *dstp = dst; - while ( maxlen-- && *src ) { - *dstp++ = *src++; + size_t dstlen = SDL_strlen(dst); + size_t srclen = SDL_strlen(src); + if ( dstlen < maxlen ) { + SDL_strlcpy(dst+dstlen, src, maxlen-dstlen); } - *dstp = '\0'; - - return dst; + return dstlen+srclen; } #endif #ifndef HAVE_STRDUP char *SDL_strdup(const char *string) { - size_t len = SDL_strlen(string); - char *newstr = SDL_malloc(len+1); + size_t len = SDL_strlen(string)+1; + char *newstr = SDL_malloc(len); if ( newstr ) { - SDL_strcpy(newstr, string); + SDL_strlcpy(newstr, string, len); } return newstr; } @@ -912,7 +911,7 @@ if ( size > maxlen ) { size = maxlen; } - SDL_strncpy(text, num, size); + SDL_strlcpy(text, num, size); return size; } @@ -926,7 +925,7 @@ if ( size > maxlen ) { size = maxlen; } - SDL_strncpy(text, num, size); + SDL_strlcpy(text, num, size); return size; } @@ -941,7 +940,7 @@ if ( size > maxlen ) { size = maxlen; } - SDL_strncpy(text, num, size); + SDL_strlcpy(text, num, size); return size; } @@ -955,7 +954,7 @@ if ( size > maxlen ) { size = maxlen; } - SDL_strncpy(text, num, size); + SDL_strlcpy(text, num, size); return size; } diff -r dc0e13e7e1ae -r c0a74f199ecf src/video/SDL_video.c --- a/src/video/SDL_video.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/video/SDL_video.c Sun Feb 19 23:46:34 2006 +0000 @@ -283,8 +283,7 @@ char *SDL_VideoDriverName(char *namebuf, int maxlen) { if ( current_video != NULL ) { - SDL_strncpy(namebuf, current_video->name, maxlen-1); - namebuf[maxlen-1] = '\0'; + SDL_strlcpy(namebuf, current_video->name, maxlen); return(namebuf); } return(NULL); @@ -1664,19 +1663,13 @@ if ( video->wm_title ) { SDL_free(video->wm_title); } - video->wm_title = (char *)SDL_malloc(SDL_strlen(title)+1); - if ( video->wm_title != NULL ) { - SDL_strcpy(video->wm_title, title); - } + video->wm_title = SDL_strdup(title); } if ( icon ) { if ( video->wm_icon ) { SDL_free(video->wm_icon); } - video->wm_icon = (char *)SDL_malloc(SDL_strlen(icon)+1); - if ( video->wm_icon != NULL ) { - SDL_strcpy(video->wm_icon, icon); - } + video->wm_icon = SDL_strdup(icon); } if ( (title || icon) && (video->SetCaption != NULL) ) { video->SetCaption(this, video->wm_title,video->wm_icon); diff -r dc0e13e7e1ae -r c0a74f199ecf src/video/Xext/Xv/Xv.c --- a/src/video/Xext/Xv/Xv.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/video/Xext/Xv/Xv.c Sun Feb 19 23:46:34 2006 +0000 @@ -234,8 +234,7 @@ SyncHandle(); return(XvBadAlloc); } - (void)strncpy(name, u.string, size); - name[size] = '\0'; + SDL_strlcpy(name, u.string, size); pa->name = name; u.buffer += (size + 3) & ~3; @@ -386,8 +385,7 @@ SyncHandle(); return(XvBadAlloc); } - strncpy(name, u.string, size); - name[size] = '\0'; + SDL_strlcpy(name, u.string, size); pe->name = name; pe++; diff -r dc0e13e7e1ae -r c0a74f199ecf src/video/Xext/extensions/extutil.h --- a/src/video/Xext/extensions/extutil.h Sun Feb 19 23:38:57 2006 +0000 +++ b/src/video/Xext/extensions/extutil.h Sun Feb 19 23:46:34 2006 +0000 @@ -36,6 +36,8 @@ #ifndef _EXTUTIL_H_ #define _EXTUTIL_H_ +#include "SDL_stdinc.h" /* For portable string functions */ + #include /* @@ -212,7 +214,7 @@ code -= codes->first_error; \ if (code >= 0 && code < nerr) { \ char tmp[256]; \ - sprintf (tmp, "%s.%d", extname, code); \ + SDL_snprintf (tmp, SDL_arraysize(tmp), "%s.%d", extname, code); \ pXGetErrorDatabaseText (dpy, "XProtoError", tmp, errl[code], buf, n); \ return buf; \ } \ diff -r dc0e13e7e1ae -r c0a74f199ecf src/video/aalib/SDL_aaevents.c --- a/src/video/aalib/SDL_aaevents.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/video/aalib/SDL_aaevents.c Sun Feb 19 23:46:34 2006 +0000 @@ -122,7 +122,7 @@ const char *std; /* Initialize the AAlib key translation table */ - for ( i=0; igl_config.dll_handle = handle; if ( path ) { - 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)); } else { - SDL_strcpy(this->gl_config.driver_path, ""); + *this->gl_config.driver_path = '\0'; } #endif diff -r dc0e13e7e1ae -r c0a74f199ecf src/video/cybergfx/SDL_amigaevents.c --- a/src/video/cybergfx/SDL_amigaevents.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/video/cybergfx/SDL_amigaevents.c Sun Feb 19 23:46:34 2006 +0000 @@ -301,7 +301,7 @@ int i; /* Map the miscellaneous keys */ - for ( i=0; igl_config.dll_handle = handle; 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)); return 0; } diff -r dc0e13e7e1ae -r c0a74f199ecf src/video/ps2gs/SDL_gsevents.c --- a/src/video/ps2gs/SDL_gsevents.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/video/ps2gs/SDL_gsevents.c Sun Feb 19 23:46:34 2006 +0000 @@ -822,7 +822,7 @@ /* Initialize the Linux key translation table */ /* First get the ascii keys and others not well handled */ - for (i=0; ihidden->title, title, 255); - this->hidden->title[255] = 0; + SDL_strlcpy(this->hidden->title, title, SDL_arraysize(this->hidden->title)); } /* Set screen mode diff -r dc0e13e7e1ae -r c0a74f199ecf src/video/riscos/SDL_riscosevents.c --- a/src/video/riscos/SDL_riscosevents.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/video/riscos/SDL_riscosevents.c Sun Feb 19 23:46:34 2006 +0000 @@ -101,7 +101,7 @@ int i; /* Map the VK keysyms */ - for ( i=0; i$TaskName exists */ - SDL_strcpy(env_var, "SDL$"); - strcat(env_var, p); - strcat(env_var, "$TaskName"); + SDL_strlcpy(env_var, "SDL$", len); + SDL_strlcat(env_var, p, len); + SDL_strlcat(env_var, "$TaskName", len); env_val = SDL_getenv(env_var); - if (env_val) SDL_strncpy(task_name, env_val, 31); + if (env_val) SDL_strlcpy(task_name, env_val, maxlen); - SDL_strcpy(env_var, "SDL$"); - strcat(env_var, p); - strcat(env_var, "$BackBuffer"); + SDL_strlcpy(env_var, "SDL$", len); + SDL_strlcat(env_var, p, len); + SDL_strlcat(env_var, "$BackBuffer", len); env_val = SDL_getenv(env_var); if (env_val) riscos_backbuffer = atoi(env_val); - SDL_strcpy(env_var, "SDL$"); - strcat(env_var, p); - strcat(env_var, "$CloseAction"); + SDL_strlcpy(env_var, "SDL$", len); + SDL_strlcat(env_var, p, len); + SDL_strlcat(env_var, "$CloseAction", len); env_val = SDL_getenv(env_var); if (env_val && SDL_strcmp(env_val,"0") == 0) riscos_closeaction = 0; - SDL_free(env_var); + SDL_stack_free(env_var); } - if (task_name[0] == 0) SDL_strncpy(task_name, p, 31); - task_name[31] = 0; + if (!*task_name) SDL_strlcpy(task_name, p, maxlen); } - SDL_free(buffer); + SDL_stack_free(buffer); } - if (task_name[0] == 0) SDL_strcpy(task_name, "SDL Task"); + if (task_name[0] == 0) SDL_strlcpy(task_name, "SDL Task", maxlen); return 1; } diff -r dc0e13e7e1ae -r c0a74f199ecf src/video/riscos/SDL_wimpvideo.c --- a/src/video/riscos/SDL_wimpvideo.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/video/riscos/SDL_wimpvideo.c Sun Feb 19 23:46:34 2006 +0000 @@ -384,8 +384,7 @@ { _kernel_swi_regs regs; - SDL_strncpy(this->hidden->title, title, 255); - this->hidden->title[255] = 0; + SDL_strlcpy(this->hidden->title, title, SDL_arraysize(this->hidden->title)); if (RISCOS_GetWimpVersion() < 380) { diff -r dc0e13e7e1ae -r c0a74f199ecf src/video/svga/SDL_svgaevents.c --- a/src/video/svga/SDL_svgaevents.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/video/svga/SDL_svgaevents.c Sun Feb 19 23:46:34 2006 +0000 @@ -210,7 +210,7 @@ int i; /* Initialize the BeOS key translation table */ - for ( i=0; igl_config.dll_handle = handle; - SDL_strcpy(this->gl_config.driver_path, path); + SDL_strlcpy(this->gl_config.driver_path, path, SDL_arraysize(this->gl_config.driver_path)); this->gl_config.driver_loaded = 1; return 0; } diff -r dc0e13e7e1ae -r c0a74f199ecf src/video/windib/SDL_dibevents.c --- a/src/video/windib/SDL_dibevents.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/video/windib/SDL_dibevents.c Sun Feb 19 23:46:34 2006 +0000 @@ -251,7 +251,7 @@ int i; /* Map the VK keysyms */ - for ( i=0; isym = SDLK_UNKNOWN; keysym->mod = KMOD_NONE; - if (scancode < SDL_TABLESIZE(keymap)) + if (scancode < SDL_arraysize(keymap)) keysym->sym = keymap[scancode]; if (keysym->sym == SDLK_UNKNOWN) @@ -141,7 +141,7 @@ int i; /* Make sure unknown keys are mapped correctly */ - for (i=0; i < SDL_TABLESIZE(keymap); i++) { + for (i=0; i < SDL_arraysize(keymap); i++) { keymap[i] = SDLK_UNKNOWN; } diff -r dc0e13e7e1ae -r c0a74f199ecf src/video/x11/SDL_x11events.c --- a/src/video/x11/SDL_x11events.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/video/x11/SDL_x11events.c Sun Feb 19 23:46:34 2006 +0000 @@ -693,7 +693,7 @@ int i; /* Odd keys used in international keyboards */ - for ( i=0; igl_config.dll_handle = handle; this->gl_config.driver_loaded = 1; if ( path ) { - 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)); } else { - SDL_strcpy(this->gl_config.driver_path, ""); + *this->gl_config.driver_path = '\0'; } return 0; } diff -r dc0e13e7e1ae -r c0a74f199ecf src/video/x11/SDL_x11modes.c --- a/src/video/x11/SDL_x11modes.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/video/x11/SDL_x11modes.c Sun Feb 19 23:46:34 2006 +0000 @@ -493,7 +493,7 @@ } this->hidden->nvisuals = 0; if ( ! add_visual_byid(this, SDL_getenv("SDL_VIDEO_X11_VISUALID")) ) { - for ( i=0; i 8 ) { if ( use_directcolor ) { add_visual(this, depth_list[i], DirectColor); diff -r dc0e13e7e1ae -r c0a74f199ecf src/video/x11/SDL_x11mouse.c --- a/src/video/x11/SDL_x11mouse.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/video/x11/SDL_x11mouse.c Sun Feb 19 23:46:34 2006 +0000 @@ -191,14 +191,16 @@ static void SetMouseAccel(_THIS, const char *accel_param) { int i; + size_t len; int accel_value[3]; char *mouse_param, *mouse_param_buf, *pin; - mouse_param_buf = (char *)SDL_malloc(SDL_strlen(accel_param)+1); + len = SDL_strlen(accel_param)+1; + mouse_param_buf = SDL_stack_alloc(char, len); if ( ! mouse_param_buf ) { return; } - SDL_strcpy(mouse_param_buf, accel_param); + SDL_strlcpy(mouse_param_buf, accel_param, len); mouse_param = mouse_param_buf; for ( i=0; (i < 3) && mouse_param; ++i ) { diff -r dc0e13e7e1ae -r c0a74f199ecf src/video/x11/SDL_x11video.c --- a/src/video/x11/SDL_x11video.c Sun Feb 19 23:38:57 2006 +0000 +++ b/src/video/x11/SDL_x11video.c Sun Feb 19 23:46:34 2006 +0000 @@ -275,7 +275,7 @@ /* First allow environment variable override */ spot = SDL_getenv("SDL_VIDEO_X11_WMCLASS"); if ( spot ) { - SDL_strncpy(classname, spot, maxlen); + SDL_strlcpy(classname, spot, maxlen); return classname; } @@ -293,16 +293,16 @@ linkfile[linksize] = '\0'; spot = SDL_strrchr(linkfile, '/'); if ( spot ) { - SDL_strncpy(classname, spot+1, maxlen); + SDL_strlcpy(classname, spot+1, maxlen); } else { - SDL_strncpy(classname, linkfile, maxlen); + SDL_strlcpy(classname, linkfile, maxlen); } return classname; } #endif /* linux */ /* Finally use the default we've used forever */ - SDL_strncpy(classname, "SDL_App", maxlen); + SDL_strlcpy(classname, "SDL_App", maxlen); return classname; }