From e005378bd8dd789410781e8f0c10f387d5a82926 Mon Sep 17 00:00:00 2001 From: Jaromil Date: Sun, 29 Dec 2024 01:19:05 +0100 Subject: [PATCH] fix: add filename to tcc error report on add_file --- src/cjit.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cjit.c b/src/cjit.c index 3848495..f29e69c 100644 --- a/src/cjit.c +++ b/src/cjit.c @@ -234,14 +234,23 @@ bool cjit_add_file(CJITState *cjit, const char *path) { _err("%s: fopen error: ", __func__, strerror(errno)); return false; } - char *contents = (char*)malloc((length + 1) * sizeof(char)); + char *spath = (char*)malloc((strlen(path)+16)*sizeof(char)); + sprintf(spath,"#line 1 \"%s\"\n",path); + size_t spath_len = strlen(spath); + char *contents = + (char*)malloc + ((spath_len + length + 1) + * sizeof(char)); if (!contents) { _err("%s: malloc error: %s",__func__, strerror(errno)); + free(spath); fclose(file); return false; } - fread(contents, 1, length, file); - contents[length] = 0x0; // Null-terminate the string + strcpy(contents,spath); + free(spath); + fread(contents+spath_len, 1, length, file); + contents[length+spath_len] = 0x0; fclose(file); cjit_setup(cjit); size_t dirname;