cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 367796028dc0e00c7de512968e147c99fcb8f8c1
parent 84b43eba5659e9eecb66f9769e49b02200d319aa
Author: Michael Forney <mforney@mforney.org>
Date:   Wed,  8 May 2019 16:05:04 -0700

scan: Handle EOF in comments, character constants, and string literals

Diffstat:
Mscan.c | 14+++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/scan.c b/scan.c @@ -207,6 +207,8 @@ charconst(struct scanner *s) return TCHARCONST; case '\n': error(&s->loc, "newline in character constant"); + case EOF: + error(&s->loc, "EOF in character constant"); default: nextchar(s); break; @@ -229,6 +231,8 @@ stringlit(struct scanner *s) return TSTRINGLIT; case '\n': error(&s->loc, "newline in string literal"); + case EOF: + error(&s->loc, "EOF in string literal"); default: nextchar(s); break; @@ -244,12 +248,16 @@ comment(struct scanner *s) switch (s->chr) { case '/': /* C++-style comment */ do nextchar(s); - while (s->chr != '\n'); + while (s->chr != '\n' && s->chr != EOF); return true; case '*': /* C-style comment */ nextchar(s); - do last = s->chr, nextchar(s); - while (last != '*' || s->chr != '/'); + do { + last = s->chr; + nextchar(s); + if (s->chr == EOF) + error(&s->loc, "EOF in comment"); + } while (last != '*' || s->chr != '/'); nextchar(s); return true; default: