diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-10-01 01:04:30 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-10-11 00:14:35 +0200 |
| commit | 4ce39e4fc1de9536de7dedfe91b6dee38dec76ae (patch) | |
| tree | f9820f96b8eab624430c3700f32a2878a7036ee2 /src/prc1/tmp.c | |
| parent | 9140988be4e5bb028b7140aca1a67af1370c72a7 (diff) | |
| download | prc-4ce39e4fc1de9536de7dedfe91b6dee38dec76ae.tar.gz | |
WIP sym + cgen
Diffstat (limited to 'src/prc1/tmp.c')
| -rw-r--r-- | src/prc1/tmp.c | 12 |
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; } |
