aboutsummaryrefslogtreecommitdiff
path: root/src/prc1/tmp.c
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2026-10-11 01:26:41 +0200
committerXavier Del Campo Romero <xavi92@disroot.org>2026-10-20 01:03:47 +0200
commitcab0135f57ca1c7e448e11f866b0adb8a1328d48 (patch)
treefcc24dc0b2d350524c33f07dc8b71f491431e832 /src/prc1/tmp.c
parent4ce39e4fc1de9536de7dedfe91b6dee38dec76ae (diff)
downloadprc-cab0135f57ca1c7e448e11f866b0adb8a1328d48.tar.gz
WIP tripletHEADmaster
Diffstat (limited to 'src/prc1/tmp.c')
-rw-r--r--src/prc1/tmp.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/prc1/tmp.c b/src/prc1/tmp.c
index 96b2208..c990216 100644
--- a/src/prc1/tmp.c
+++ b/src/prc1/tmp.c
@@ -1,6 +1,7 @@
#include "tmp.h"
#include "dbg.h"
#include "type.h"
+#include "prv.h"
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -11,7 +12,7 @@ const struct stentry *tmp_create(struct fn *fn, const struct type *t)
static const char fmt[] = "__tmp%zu", path[] = "(temporary)";
int r = snprintf(NULL, 0, fmt, fn->ntmps);
char *s = NULL, *tname = NULL, *pathdup = NULL;
- struct tmp *tmp;
+ struct tmp *tmp = NULL;
if (!(tname = type_name(t)))
goto failure;
@@ -21,20 +22,15 @@ const struct stentry *tmp_create(struct fn *fn, const struct type *t)
goto failure;
}
else if (!(s = malloc(r + 1))
- || !(pathdup = malloc(strlen(path) + 1)))
+ || !(tmp = malloc(sizeof *tmp)))
{
perror("malloc(3)");
goto failure;
}
+ else if (!(pathdup = sdup(path + 1)))
+ goto failure;
snprintf(s, r + 1, fmt, fn->ntmps++);
- strcpy(pathdup, path);
-
- if (!(tmp = malloc(sizeof *tmp)))
- {
- perror("realloc(3)");
- goto failure;
- }
*tmp = (struct tmp)
{
@@ -68,6 +64,7 @@ const struct stentry *tmp_create(struct fn *fn, const struct type *t)
failure:
free(s);
+ free(tmp);
free(tname);
free(pathdup);
return NULL;