scc

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

commit bbdf237f3cb79ff55281f9a31c0a57068a375687
parent fdf6db7e69404134489a6f6aa7c8512a69307e6f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 21 May 2015 14:31:30 +0200

Avoid segmentation fault at EOF

When there is call to delinput() and we are at the end of
the input list, it is not desirable to go down in the
stack because in this case we can generate segmentation
faults calling getfname() or getfline().

Diffstat:
Mcc1/lex.c | 4+++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/cc1/lex.c b/cc1/lex.c @@ -65,7 +65,7 @@ addinput(char *fname) return 1; } -void +static void delinput(void) { Input *ip = input; @@ -74,6 +74,8 @@ delinput(void) if (fp) { if (fclose(fp)) die("error reading from input file '%s'", ip->fname); + if (!ip->next) + return; if (ip->fp != stdin) free(ip->fname); }