scc

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

commit ad1f4adbdc619676c1e133465becbf96b16e4e05
parent 7d21e2bf608c9b2405c2cb68cb7b82f176e22ef4
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; }