scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 2edbdb8b2a7914d14f1b080179a057879144378e
parent 664e782912da639d082308433dd7dddfcf9922ce
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  7 May 2015 15:18:13 +0200

Add newline()

This function increment the current line number and check
if the file is too long (more of 65536 lines).

Diffstat:
Mcc1/lex.c | 11+++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/cc1/lex.c b/cc1/lex.c @@ -64,6 +64,13 @@ fileline(void) return input->nline; } +static void +newline(void) +{ + if (++input->nline == 0) + die("input file too long"); +} + static uint8_t integer(char *s, char base) { @@ -181,7 +188,7 @@ repeat: warn("character constant out of range"); break; case '\n': - ++input->nline; + newline(); if ((c = getchar()) == '\\') goto repeat; break; @@ -403,7 +410,7 @@ skipspaces(void) while (isspace(c = getchar())) { if (c == '\n') - ++input->nline; + newline(); } return c; }