aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-05-08 16:05:04 -0700
committerMichael Forney <mforney@mforney.org>2019-05-08 20:26:09 -0700
commit367796028dc0e00c7de512968e147c99fcb8f8c1 (patch)
treed80cab169abbb74e64519eea05691e8b0d53fc49
parent84b43eba5659e9eecb66f9769e49b02200d319aa (diff)
downloadcproc-367796028dc0e00c7de512968e147c99fcb8f8c1.tar.xz
scan: Handle EOF in comments, character constants, and string literals
-rw-r--r--scan.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/scan.c b/scan.c
index f5ad2f9..489b599 100644
--- 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: