Skip to content

Commit

Permalink
Replaced sprintf() calls with snprintf().
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jul 9, 2017
1 parent e4c035a commit f8ed5c6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/archiver_dir.c
Expand Up @@ -13,10 +13,11 @@



static char *cvtToDependent(const char *prepend, const char *path, char *buf)
static char *cvtToDependent(const char *prepend, const char *path,
char *buf, const size_t buflen)
{
BAIL_IF(buf == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
sprintf(buf, "%s%s", prepend ? prepend : "", path);
snprintf(buf, buflen, "%s%s", prepend ? prepend : "", path);

if (__PHYSFS_platformDirSeparator != '/')
{
Expand All @@ -31,7 +32,7 @@ static char *cvtToDependent(const char *prepend, const char *path, char *buf)

#define CVT_TO_DEPENDENT(buf, pre, dir) { \
const size_t len = ((pre) ? strlen((char *) pre) : 0) + strlen(dir) + 1; \
buf = cvtToDependent((char*)pre,dir,(char*)__PHYSFS_smallAlloc(len)); \
buf = cvtToDependent((char*)pre,dir,(char*)__PHYSFS_smallAlloc(len),len); \
}


Expand Down
5 changes: 2 additions & 3 deletions src/physfs.c
Expand Up @@ -9,7 +9,6 @@
*/

/* !!! FIXME: ERR_PAST_EOF shouldn't trigger for reads. Just return zero. */
/* !!! FIXME: use snprintf(), not sprintf(). */

#define __PHYSICSFS_INTERNAL__
#include "physfs_internal.h"
Expand Down Expand Up @@ -1831,7 +1830,7 @@ static void setSaneCfgAddPath(const char *i, const size_t l, const char *dirsep,
char *str = (char *) __PHYSFS_smallAlloc(allocsize);
if (str != NULL)
{
sprintf(str, "%s%s%s", d, dirsep, i);
snprintf(str, allocsize, "%s%s%s", d, dirsep, i);
PHYSFS_mount(str, NULL, archivesFirst == 0);
__PHYSFS_smallFree(str);
} /* if */
Expand Down Expand Up @@ -2272,7 +2271,7 @@ static void enumCallbackFilterSymLinks(void *_data, const char *origdir,
const DirHandle *dh = data->dirhandle;
PHYSFS_Stat statbuf;

sprintf(path, "%s%s%s", trimmedDir, *trimmedDir ? "/" : "", fname);
snprintf(path, slen, "%s%s%s", trimmedDir, *trimmedDir ? "/" : "", fname);
if (dh->funcs->stat(dh->opaque, path, &statbuf))
{
/* Pass it on to the application if it's not a symlink. */
Expand Down
2 changes: 1 addition & 1 deletion src/platform_windows.c
Expand Up @@ -413,7 +413,7 @@ char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app)
BAIL(PHYSFS_ERR_OUT_OF_MEMORY, NULL);
} /* if */

sprintf(retval, "%s\\%s\\%s\\", utf8, org, app);
snprintf(retval, len, "%s\\%s\\%s\\", utf8, org, app);
allocator.Free(utf8);
return retval;
} /* __PHYSFS_platformCalcPrefDir */
Expand Down

0 comments on commit f8ed5c6

Please sign in to comment.