diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-11-23 22:44:06 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-11-23 23:10:01 -0800 |
commit | d00b208df92061f0049bfcd993ab1f92dc8aa2cb (patch) | |
tree | 6b87fb156e3e52b06434ecd50928842b526a6fe2 /save.c | |
parent | d59fe3c0501ec07b725004de86c1a8adac966092 (diff) |
Convert sprintf calls to asprintf or snprintf
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'save.c')
-rw-r--r-- | save.c | 17 |
1 files changed, 6 insertions, 11 deletions
@@ -361,7 +361,7 @@ unique_filename(char *path, char *prefix, int *pFd) char tempFile[PATH_MAX]; char *tmp; - sprintf (tempFile, "%s/%sXXXXXX", path, prefix); + snprintf (tempFile, sizeof(tempFile), "%s/%sXXXXXX", path, prefix); tmp = (char *) mktemp (tempFile); if (tmp) { @@ -373,17 +373,12 @@ unique_filename(char *path, char *prefix, int *pFd) return (NULL); # endif /* HAVE_MKTEMP */ #else /* HAVE_MKSTEMP */ - char tempFile[PATH_MAX]; - char *ptr; + char *tempFile; - sprintf (tempFile, "%s/%sXXXXXX", path, prefix); - ptr = (char *)malloc(strlen(tempFile) + 1); - if (ptr != NULL) - { - strcpy(ptr, tempFile); - *pFd = mkstemp(ptr); - } - return ptr; + if (asprintf (&tempFile, "%s/%sXXXXXX", path, prefix) == -1) + return NULL; + *pFd = mkstemp(tempFile); + return tempFile; #endif /* HAVE_MKSTEMP */ } |