Use only safe string functions

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401383
This commit is contained in:
Sam Lantinga 2006-02-19 23:46:34 +00:00
parent a81db3ea34
commit 1da8cb0143
60 changed files with 223 additions and 263 deletions

View File

@ -119,7 +119,7 @@ if test x$enable_libc = xyes; then
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

View File

@ -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

View File

@ -206,6 +206,9 @@ extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size,
#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 int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t le
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

View File

@ -59,8 +59,7 @@ void SDL_SetError (const char *fmt, ...)
/* 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 @@ void SDL_SetError (const char *fmt, ...)
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 @@ Uint8 *SDL_GetErrorMsg(Uint8 *errstr, unsigned int maxlen)
/* 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);
}

View File

@ -373,8 +373,7 @@ int SDL_AudioInit(const char *driver_name)
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);

View File

@ -89,7 +89,7 @@ int SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic)
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 @@ static int OpenUserDefinedDevice(char *path, int maxlen, int flags)
}
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 @@ int SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic)
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;
}

View File

@ -124,7 +124,7 @@ static int LoadALSALibrary(void) {
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");

View File

@ -90,7 +90,7 @@ static int LoadARTSLibrary(void)
if ( arts_handle ) {
arts_loaded = 1;
retval = 0;
for ( i=0; i<SDL_TABLESIZE(arts_functions); ++i ) {
for ( i=0; i<SDL_arraysize(arts_functions); ++i ) {
*arts_functions[i].func = SDL_LoadFunction(arts_handle, arts_functions[i].name);
if ( !*arts_functions[i].func ) {
retval = -1;

View File

@ -85,7 +85,7 @@ static int LoadESDLibrary(void)
if ( esd_handle ) {
esd_loaded = 1;
retval = 0;
for ( i=0; i<SDL_TABLESIZE(esd_functions); ++i ) {
for ( i=0; i<SDL_arraysize(esd_functions); ++i ) {
*esd_functions[i].func = SDL_LoadFunction(esd_handle, esd_functions[i].name);
if ( !*esd_functions[i].func ) {
retval = -1;

View File

@ -124,12 +124,11 @@ static void AddDrive(char *drive, struct stat *stbuf)
/* 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
@ -302,9 +301,10 @@ int SDL_SYS_CDInit(void)
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 @@ 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 */
@ -360,21 +360,23 @@ static int SDL_SYS_CDOpen(int drive)
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);
}
}

View File

@ -224,12 +224,11 @@ static void AddDrive(char *drive, struct stat *stbuf)
/* 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 @@ int SDL_SYS_CDInit(void)
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 @@ 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 */

View File

@ -110,12 +110,11 @@ static void AddDrive(char *drive, struct stat *stbuf)
/* 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 @@ int SDL_SYS_CDInit(void)
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 @@ 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 */

View File

@ -167,12 +167,11 @@ static void AddDrive(char *drive, struct stat *stbuf)
/* 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 @@ static void CheckMounts(const char *mtab)
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 @@ static void CheckMounts(const char *mtab)
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 @@ int SDL_SYS_CDInit(void)
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 @@ 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 */

View File

@ -115,12 +115,11 @@ static void AddDrive(char *drive, struct stat *stbuf)
/* 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 @@ int SDL_SYS_CDInit(void)
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 @@ 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 */

View File

@ -94,13 +94,12 @@ for (i=0; i<SDL_numcds; i++)
{
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);
}

View File

@ -119,13 +119,11 @@ static void AddDrive(char *drive, struct stat *stbuf)
/* 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 @@ int SDL_SYS_CDInit(void)
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 @@ 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 */
@ -226,15 +225,6 @@ int SDL_SYS_CDInit(void)
#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);
}

View File

@ -124,13 +124,12 @@ static void AddDrive(char *drive, struct stat *stbuf)
/* 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 @@ int SDL_SYS_CDInit(void)
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 @@ 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 */

View File

@ -63,12 +63,11 @@ static void AddDrive(char *drive)
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);

View File

@ -554,7 +554,7 @@ int SDL_JoystickEventState(int state)
switch (state) {
case SDL_QUERY:
state = SDL_IGNORE;
for ( i=0; i<SDL_TABLESIZE(event_list); ++i ) {
for ( i=0; i<SDL_arraysize(event_list); ++i ) {
state = SDL_EventState(event_list[i],SDL_QUERY);
if ( state == SDL_ENABLE ) {
break;
@ -562,7 +562,7 @@ int SDL_JoystickEventState(int state)
}
break;
default:
for ( i=0; i<SDL_TABLESIZE(event_list); ++i ) {
for ( i=0; i<SDL_arraysize(event_list); ++i ) {
SDL_EventState(event_list[i], state);
}
break;

View File

@ -179,17 +179,6 @@ struct joystick_hwdata {
#endif
};
static char *mystrdup(const char *string)
{
char *newstring;
newstring = (char *)SDL_malloc(SDL_strlen(string)+1);
if ( newstring ) {
SDL_strcpy(newstring, string);
}
return(newstring);
}
#ifndef NO_LOGICAL_JOYSTICKS
@ -204,7 +193,7 @@ static int CountLogicalJoysticks(int max)
name = SDL_SYS_JoystickName(i);
if (name) {
for(j = 0; j < SDL_TABLESIZE(joystick_logicalmap); j++) {
for(j = 0; j < SDL_arraysize(joystick_logicalmap); j++) {
if (!SDL_strcmp(name, joystick_logicalmap[j].name)) {
prev = i;
@ -303,13 +292,12 @@ int SDL_SYS_JoystickInit(void)
/* First see if the user specified a joystick to use */
if ( SDL_getenv("SDL_JOYSTICK_DEVICE") != NULL ) {
SDL_strncpy(path, SDL_getenv("SDL_JOYSTICK_DEVICE"), sizeof(path));
path[sizeof(path)-1] = '\0';
SDL_strlcpy(path, SDL_getenv("SDL_JOYSTICK_DEVICE"), sizeof(path));
if ( stat(path, &sb) == 0 ) {
fd = open(path, O_RDONLY, 0);
if ( fd >= 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 @@ int SDL_SYS_JoystickInit(void)
}
}
for ( i=0; i<SDL_TABLESIZE(joydev_pattern); ++i ) {
for ( i=0; i<SDL_arraysize(joydev_pattern); ++i ) {
for ( j=0; j < MAX_JOYSTICKS; ++j ) {
SDL_snprintf(path, SDL_arraysize(path), joydev_pattern[i], j);
@ -357,7 +345,7 @@ int SDL_SYS_JoystickInit(void)
close(fd);
/* We're fine, add this joystick */
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;
@ -489,7 +477,7 @@ static SDL_bool JS_ConfigJoystick(SDL_Joystick *joystick, int fd)
}
/* Special joystick support */
for ( i=0; i < SDL_TABLESIZE(special_joysticks); ++i ) {
for ( i=0; i < SDL_arraysize(special_joysticks); ++i ) {
if ( SDL_strcmp(name, special_joysticks[i].name) == 0 ) {
joystick->naxes = special_joysticks[i].naxes;
@ -503,7 +491,7 @@ static SDL_bool JS_ConfigJoystick(SDL_Joystick *joystick, int fd)
/* 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 )

View File

@ -165,7 +165,7 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
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(

View File

@ -214,7 +214,7 @@ if (numdevs > 0)
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

View File

@ -42,9 +42,10 @@ void *SDL_LoadFunction(void *handle, const char *name)
{
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 ) {

View File

@ -42,8 +42,7 @@ void *SDL_LoadObject(const char *sofile)
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 @@ void *SDL_LoadFunction(void *handle, const char *name)
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";

View File

@ -281,7 +281,7 @@ static void error(const char *str, ...)
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 @@ static NSSymbol *search_linked_libs(const struct mach_header * mh, const char *s
}
/* 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 @@ static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetErr
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 @@ static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetErr
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 @@ static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetErr
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 @@ static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetErr
debug(savedErrorStr);
}
if (savedErrorStr)
SDL_free((char*)savedErrorStr);
SDL_free(savedErrorStr);
return NULL;
}
return NSAddressOfSymbol(nssym);

View File

@ -47,7 +47,7 @@ void *SDL_LoadObject(const char *sofile)
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 @@ void *SDL_LoadObject(const char *sofile)
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 @@ void *SDL_LoadFunction(void *handle, const char *name)
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 @@ void *SDL_LoadFunction(void *handle, const char *name)
FORMAT_MESSAGE_FROM_SYSTEM),
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
errbuf, SDL_TABLESIZE(errbuf), NULL);
errbuf, SDL_arraysize(errbuf), NULL);
loaderror = errbuf;
}
#endif

View File

@ -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 @@ int console_main(int argc, char *argv[])
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 WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
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 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
}
#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 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
}
#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 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
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 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
#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;
}

View File

@ -53,7 +53,7 @@ int SDL_putenv(const char *variable)
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 @@ int SDL_putenv(const char *variable)
}
/* 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;

View File

@ -294,39 +294,38 @@ size_t SDL_strlen(const char *string)
}
#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 @@ static size_t SDL_PrintLong(char *text, long value, int radix, size_t maxlen)
if ( size > maxlen ) {
size = maxlen;
}
SDL_strncpy(text, num, size);
SDL_strlcpy(text, num, size);
return size;
}
@ -926,7 +925,7 @@ static size_t SDL_PrintUnsignedLong(char *text, unsigned long value, int radix,
if ( size > maxlen ) {
size = maxlen;
}
SDL_strncpy(text, num, size);
SDL_strlcpy(text, num, size);
return size;
}
@ -941,7 +940,7 @@ static size_t SDL_PrintLongLong(char *text, Sint64 value, int radix, size_t maxl
if ( size > maxlen ) {
size = maxlen;
}
SDL_strncpy(text, num, size);
SDL_strlcpy(text, num, size);
return size;
}
@ -955,7 +954,7 @@ static size_t SDL_PrintUnsignedLongLong(char *text, Uint64 value, int radix, siz
if ( size > maxlen ) {
size = maxlen;
}
SDL_strncpy(text, num, size);
SDL_strlcpy(text, num, size);
return size;
}

View File

@ -283,8 +283,7 @@ int SDL_VideoInit (const char *driver_name, Uint32 flags)
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 @@ void SDL_WM_SetCaption (const char *title, const char *icon)
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);

View File

@ -234,8 +234,7 @@ SDL_NAME(XvQueryAdaptors)(
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 @@ SDL_NAME(XvQueryEncodings)(
SyncHandle();
return(XvBadAlloc);
}
strncpy(name, u.string, size);
name[size] = '\0';
SDL_strlcpy(name, u.string, size);
pe->name = name;
pe++;

View File

@ -36,6 +36,8 @@ in this Software without prior written authorization from The Open Group.
#ifndef _EXTUTIL_H_
#define _EXTUTIL_H_
#include "SDL_stdinc.h" /* For portable string functions */
#include <X11/extensions/Xext.h>
/*
@ -212,7 +214,7 @@ char *proc (Display *dpy, int code, XExtCodes *codes, char *buf, int n) \
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; \
} \

View File

@ -122,7 +122,7 @@ void AA_InitOSKeymap(_THIS)
const char *std;
/* Initialize the AAlib key translation table */
for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
for ( i=0; i<SDL_arraysize(keymap); ++i )
keymap[i] = SDLK_UNKNOWN;
keymap[AA_ESC] = SDLK_ESCAPE;

View File

@ -219,10 +219,10 @@ int SDL_AtariGL_LoadLibrary(_THIS, const char *path)
this->gl_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

View File

@ -301,7 +301,7 @@ void amiga_InitKeymap(void)
int i;
/* Map the miscellaneous keys */
for ( i=0; i<SDL_TABLESIZE(MISC_keymap); ++i )
for ( i=0; i<SDL_arraysize(MISC_keymap); ++i )
MISC_keymap[i] = SDLK_UNKNOWN;
/* These X keysyms have 0xFF as the high byte */

View File

@ -90,7 +90,7 @@ void DirectFB_InitOSKeymap (_THIS)
int i;
/* Initialize the DirectFB key translation table */
for (i=0; i<SDL_TABLESIZE(keymap); ++i)
for (i=0; i<SDL_arraysize(keymap); ++i)
keymap[i] = SDLK_UNKNOWN;
keymap[DIKI_A - DIKI_UNKNOWN] = SDLK_a;

View File

@ -994,7 +994,7 @@ void FB_InitOSKeymap(_THIS)
/* Initialize the Linux key translation table */
/* First get the ascii keys and others not well handled */
for (i=0; i<SDL_TABLESIZE(keymap); ++i) {
for (i=0; i<SDL_arraysize(keymap); ++i) {
switch(i) {
/* These aren't handled by the x86 kernel keymapping (?) */
case SCANCODE_PRINTSCREEN:
@ -1033,7 +1033,7 @@ void FB_InitOSKeymap(_THIS)
break;
}
}
for (i=0; i<SDL_TABLESIZE(keymap); ++i) {
for (i=0; i<SDL_arraysize(keymap); ++i) {
switch(keymap_temp[i]) {
case K_F1: keymap[i] = SDLK_F1; break;
case K_F2: keymap[i] = SDLK_F2; break;

View File

@ -123,7 +123,7 @@ void GGI_InitOSKeymap(_THIS)
int i;
/* Initialize the GGI key translation table */
for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
for ( i=0; i<SDL_arraysize(keymap); ++i )
keymap[i] = SDLK_UNKNOWN;
keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;

View File

@ -457,7 +457,7 @@ void Mac_InitOSKeymap(_THIS)
int world = SDLK_WORLD_0;
/* Map the MAC keysyms */
for ( i=0; i<SDL_TABLESIZE(MAC_keymap); ++i )
for ( i=0; i<SDL_arraysize(MAC_keymap); ++i )
MAC_keymap[i] = SDLK_UNKNOWN;
/* Defined MAC_* constants */

View File

@ -355,7 +355,7 @@ static SDL_Rect** DSp_BuildModeList (const GDHandle gDevice)
if ( DSpContext_GetAttributes (context, &attributes) != noErr )
return NULL;
for ( i = 0; i < SDL_TABLESIZE(temp_list); i++ ) {
for ( i = 0; i < SDL_arraysize(temp_list); i++ ) {
width = attributes.displayWidth;
height = attributes.displayHeight;

View File

@ -41,7 +41,7 @@ void NX_InitOSKeymap (_THIS)
Dprintf ("enter NX_InitOSKeymap\n") ;
// Map the nanox scancodes to SDL keysyms
for (i = 0; i < SDL_TABLESIZE (NX_NONASCII_keymap); ++ i)
for (i = 0; i < SDL_arraysize (NX_NONASCII_keymap); ++ i)
NX_NONASCII_keymap [i] = SDLK_UNKNOWN ;
NX_NONASCII_keymap [MWKEY_LEFT & 0xFF] = SDLK_LEFT ;

View File

@ -442,13 +442,13 @@ void ph_InitKeymap(void)
int i;
/* Odd keys used in international keyboards */
for (i=0; i<SDL_TABLESIZE(ODD_keymap); ++i)
for (i=0; i<SDL_arraysize(ODD_keymap); ++i)
{
ODD_keymap[i] = SDLK_UNKNOWN;
}
/* Map the miscellaneous keys */
for (i=0; i<SDL_TABLESIZE(MISC_keymap); ++i)
for (i=0; i<SDL_arraysize(MISC_keymap); ++i)
{
MISC_keymap[i] = SDLK_UNKNOWN;
}

View File

@ -123,7 +123,7 @@ int ph_GL_LoadLibrary(_THIS, const char* path)
this->gl_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;
}

View File

@ -822,7 +822,7 @@ void GS_InitOSKeymap(_THIS)
/* Initialize the Linux key translation table */
/* First get the ascii keys and others not well handled */
for (i=0; i<SDL_TABLESIZE(keymap); ++i) {
for (i=0; i<SDL_arraysize(keymap); ++i) {
switch(i) {
/* These aren't handled by the x86 kernel keymapping (?) */
case SCANCODE_PRINTSCREEN:
@ -861,7 +861,7 @@ void GS_InitOSKeymap(_THIS)
break;
}
}
for (i=0; i<SDL_TABLESIZE(keymap); ++i) {
for (i=0; i<SDL_arraysize(keymap); ++i) {
switch(keymap_temp[i]) {
case K_F1: keymap[i] = SDLK_F1; break;
case K_F2: keymap[i] = SDLK_F2; break;

View File

@ -657,8 +657,7 @@ static void FULLSCREEN_EnableEscape()
/** Store caption in case this is called before we create a window */
void FULLSCREEN_SetWMCaption(_THIS, const char *title, const char *icon)
{
SDL_strncpy(this->hidden->title, title, 255);
this->hidden->title[255] = 0;
SDL_strlcpy(this->hidden->title, title, SDL_arraysize(this->hidden->title));
}
/* Set screen mode

View File

@ -101,7 +101,7 @@ void RISCOS_InitOSKeymap(_THIS)
int i;
/* Map the VK keysyms */
for ( i=0; i<SDL_TABLESIZE(RO_keymap); ++i )
for ( i=0; i<SDL_arraysize(RO_keymap); ++i )
RO_keymap[i] = SDLK_UNKNOWN;
RO_keymap[3] = SDLK_LSHIFT;

View File

@ -57,7 +57,7 @@ extern int mouseInWindow; /* Mouse is in WIMP window */
/* Local function */
static int RISCOS_GetTaskName(char *task_name);
static int RISCOS_GetTaskName(char *task_name, size_t maxlen);
/* Uncomment next line to copy mode changes/restores to stderr */
/* #define DUMP_MODE */
@ -91,7 +91,7 @@ int RISCOS_InitTask()
_kernel_swi_regs regs;
int messages[4];
if (RISCOS_GetTaskName(task_name) == 0) return 0;
if (RISCOS_GetTaskName(task_name, SDL_arraysize(task_name)) == 0) return 0;
messages[0] = 9; /* Palette changed */
messages[1] = 0x400c1; /* Mode changed */
@ -177,7 +177,7 @@ void RISCOS_ExitTask()
***************************************************************************/
int RISCOS_GetTaskName(char *task_name)
int RISCOS_GetTaskName(char *task_name, size_t maxlen)
{
_kernel_swi_regs regs;
@ -187,11 +187,12 @@ int RISCOS_GetTaskName(char *task_name)
if (_kernel_swi(OS_GetEnv, &regs, &regs) == 0)
{
char *command_line = (char *)regs.r[0];
char *buffer = SDL_malloc(SDL_strlen(command_line)+1);
size_t len = SDL_strlen(command_line)+1;
char *buffer = SDL_stack_alloc(char, len);
char *env_var;
char *p;
SDL_strcpy(buffer, command_line);
SDL_strlcpy(buffer, command_line, len);
p = SDL_strchr(buffer, ' ');
if (p) *p = 0;
p = SDL_strrchr(buffer, '.');
@ -217,45 +218,45 @@ int RISCOS_GetTaskName(char *task_name)
if (*p)
{
/* Read variables that effect the RISC OS SDL engine for this task */
env_var = SDL_malloc(SDL_strlen(p) + 18); /* 18 is larger than the biggest variable name */
len = SDL_strlen(p) + 18; /* 18 is larger than the biggest variable name */
env_var = SDL_stack_alloc(char, len);
if (env_var)
{
char *env_val;
/* See if a variable of form SDL$<dirname>$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;
}

View File

@ -384,8 +384,7 @@ void WIMP_SetWMCaption(_THIS, const char *title, const char *icon)
{
_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)
{

View File

@ -210,7 +210,7 @@ void SVGA_InitOSKeymap(_THIS)
int i;
/* Initialize the BeOS key translation table */
for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
for ( i=0; i<SDL_arraysize(keymap); ++i )
keymap[i] = SDLK_UNKNOWN;
keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;

View File

@ -143,7 +143,7 @@ void VGL_InitOSKeymap(_THIS)
int i;
/* Initialize the BeOS key translation table */
for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
for ( i=0; i<SDL_arraysize(keymap); ++i )
keymap[i] = SDLK_UNKNOWN;
keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;

View File

@ -702,13 +702,13 @@ int SDL_RegisterApp(char *name, Uint32 style, void *hInst)
if ( name ) {
#ifdef _WIN32_WCE
/* WinCE uses the UNICODE version */
int nLen = SDL_strlen(name)+1;
size_t nLen = SDL_strlen(name)+1;
SDL_Appname = SDL_malloc(nLen*2);
MultiByteToWideChar(CP_ACP, 0, name, -1, SDL_Appname, nLen);
#else
int nLen = SDL_strlen(name)+1;
size_t nLen = SDL_strlen(name)+1;
SDL_Appname = SDL_malloc(nLen);
SDL_strcpy(SDL_Appname, name);
SDL_strlcpy(SDL_Appname, name, nLen);
#endif /* _WIN32_WCE */
SDL_Appstyle = style;
SDL_Instance = hInst ? hInst : SDL_GetModuleHandle();

View File

@ -551,7 +551,7 @@ int WIN_GL_LoadLibrary(_THIS, const char* path)
}
this->gl_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;
}

View File

@ -251,7 +251,7 @@ void DIB_InitOSKeymap(_THIS)
int i;
/* Map the VK keysyms */
for ( i=0; i<SDL_TABLESIZE(VK_keymap); ++i )
for ( i=0; i<SDL_arraysize(VK_keymap); ++i )
VK_keymap[i] = SDLK_UNKNOWN;
VK_keymap[VK_BACK] = SDLK_BACKSPACE;

View File

@ -703,7 +703,7 @@ void DX5_InitOSKeymap(_THIS)
int i;
/* Map the DIK scancodes to SDL keysyms */
for ( i=0; i<SDL_TABLESIZE(DIK_keymap); ++i )
for ( i=0; i<SDL_arraysize(DIK_keymap); ++i )
DIK_keymap[i] = 0;
/* Defined DIK_* constants */

View File

@ -100,7 +100,7 @@ static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym)
keysym->sym = 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 @@ void WSCONS_InitOSKeymap(_THIS)
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;
}

View File

@ -693,7 +693,7 @@ void X11_InitKeymap(void)
int i;
/* Odd keys used in international keyboards */
for ( i=0; i<SDL_TABLESIZE(ODD_keymap); ++i )
for ( i=0; i<SDL_arraysize(ODD_keymap); ++i )
ODD_keymap[i] = SDLK_UNKNOWN;
/* Some of these might be mappable to an existing SDLK_ code */
@ -729,7 +729,7 @@ void X11_InitKeymap(void)
#endif
/* Map the miscellaneous keys */
for ( i=0; i<SDL_TABLESIZE(MISC_keymap); ++i )
for ( i=0; i<SDL_arraysize(MISC_keymap); ++i )
MISC_keymap[i] = SDLK_UNKNOWN;
/* These X keysyms have 0xFF as the high byte */

View File

@ -414,10 +414,10 @@ int X11_GL_LoadLibrary(_THIS, const char* path)
this->gl_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;
}

View File

@ -493,7 +493,7 @@ int X11_GetVideoModes(_THIS)
}
this->hidden->nvisuals = 0;
if ( ! add_visual_byid(this, SDL_getenv("SDL_VIDEO_X11_VISUALID")) ) {
for ( i=0; i<SDL_TABLESIZE(depth_list); ++i ) {
for ( i=0; i<SDL_arraysize(depth_list); ++i ) {
if ( depth_list[i] > 8 ) {
if ( use_directcolor ) {
add_visual(this, depth_list[i], DirectColor);

View File

@ -191,14 +191,16 @@ void X11_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
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 ) {

View File

@ -275,7 +275,7 @@ static char *get_classname(char *classname, int maxlen)
/* 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 @@ static char *get_classname(char *classname, int maxlen)
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;
}