scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 18cffd69099077966d80b47aad16bf5f7f6b2e5b
parent 433b9cd26eb5d27977eb8cde6bb1c019606e0ffa
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  1 Nov 2021 17:45:02 +0100

cc1: Allow empty fname in setloc()

so setloc() must support an empty fname parameter for that case.

Diffstat:
Msrc/cmd/cc/cc1/lex.c | 15+++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/cmd/cc/cc1/lex.c b/src/cmd/cc/cc1/lex.c @@ -73,13 +73,16 @@ setloc(char *fname, unsigned line) { size_t len; - if ((len = strlen(fname)) >= FILENAME_MAX) - die("cc1: %s: file name too long", fname); - memmove(filenam, fname, len); - filenam[len] = '\0'; + if (fname) { + if ((len = strlen(fname)) >= FILENAME_MAX) + die("cc1: %s: file name too long", fname); + memmove(filenam, fname, len); + filenam[len] = '\0'; + + free(input->filenam); + input->filenam = xstrdup(fname); + } - free(input->filenam); - input->filenam = xstrdup(fname); lineno = input->lineno = line; }