summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/main.c b/main.c
index b43cd134a151..620ce3fdb35c 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.54 2014/10/06 22:40:07 tom Exp $ */
+/* $Id: main.c,v 1.55 2015/07/11 00:34:19 tom Exp $ */
#include <signal.h>
#ifndef _WIN32
@@ -551,6 +551,7 @@ my_mkstemp(char *temp)
static FILE *
open_tmpfile(const char *label)
{
+#define MY_FMT "%s/%.*sXXXXXX"
FILE *result;
#if USE_MKSTEMP
int fd;
@@ -569,7 +570,11 @@ open_tmpfile(const char *label)
tmpdir = ".";
}
- name = malloc(strlen(tmpdir) + 10 + strlen(label));
+ /* The size of the format is guaranteed to be longer than the result from
+ * printing empty strings with it; this calculation accounts for the
+ * string-lengths as well.
+ */
+ name = malloc(strlen(tmpdir) + sizeof(MY_FMT) + strlen(label));
result = 0;
if (name != 0)
@@ -579,7 +584,7 @@ open_tmpfile(const char *label)
if ((mark = strrchr(label, '_')) == 0)
mark = label + strlen(label);
- sprintf(name, "%s/%.*sXXXXXX", tmpdir, (int)(mark - label), label);
+ sprintf(name, MY_FMT, tmpdir, (int)(mark - label), label);
fd = mkstemp(name);
if (fd >= 0)
{
@@ -612,6 +617,7 @@ open_tmpfile(const char *label)
if (result == 0)
open_error(label);
return result;
+#undef MY_FMT
}
static void