Skip to content

Commit

Permalink
fix: add filename to tcc error report on add_file
Browse files Browse the repository at this point in the history
  • Loading branch information
jaromil committed Dec 29, 2024
1 parent ebac1f3 commit e005378
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/cjit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e005378

Please sign in to comment.