aboutsummaryrefslogtreecommitdiff
path: root/src/prc1/tmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/prc1/tmp.c')
-rw-r--r--src/prc1/tmp.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/prc1/tmp.c b/src/prc1/tmp.c
index a08716b..96b2208 100644
--- a/src/prc1/tmp.c
+++ b/src/prc1/tmp.c
@@ -4,12 +4,13 @@
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
const struct stentry *tmp_create(struct fn *fn, const struct type *t)
{
- static const char fmt[] = "__tmp%zu";
+ static const char fmt[] = "__tmp%zu", path[] = "(temporary)";
int r = snprintf(NULL, 0, fmt, fn->ntmps);
- char *s = NULL, *tname = NULL;
+ char *s = NULL, *tname = NULL, *pathdup = NULL;
struct tmp *tmp;
if (!(tname = type_name(t)))
@@ -19,13 +20,15 @@ const struct stentry *tmp_create(struct fn *fn, const struct type *t)
fprintf(stderr, "%s: snprintf(3) failed\n", __func__);
goto failure;
}
- else if (!(s = malloc(r + 1)))
+ else if (!(s = malloc(r + 1))
+ || !(pathdup = malloc(strlen(path) + 1)))
{
perror("malloc(3)");
goto failure;
}
snprintf(s, r + 1, fmt, fn->ntmps++);
+ strcpy(pathdup, path);
if (!(tmp = malloc(sizeof *tmp)))
{
@@ -39,7 +42,7 @@ const struct stentry *tmp_create(struct fn *fn, const struct type *t)
{
.type = ID,
.s = s,
- .loc.f = "(temporary)"
+ .loc.f = pathdup
},
.e =
@@ -66,5 +69,6 @@ const struct stentry *tmp_create(struct fn *fn, const struct type *t)
failure:
free(s);
free(tname);
+ free(pathdup);
return NULL;
}