aboutsummaryrefslogtreecommitdiffhomepage
path: root/c/lex.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2026-01-09 12:31:32 +0100
committerlemon <lsof@mailbox.org>2026-01-09 12:33:27 +0100
commit96e5ce447a6e5bf7302a5f905b1bb0a996c0502c (patch)
tree35731f6db078b2d70d06064a1f913d0ed425bc2b /c/lex.c
parent08a2f1a3dc834ed5ba7266be99306fccfb768c1a (diff)
cpp: fix multiline comment in skipped preprocessor directive
Diffstat (limited to 'c/lex.c')
-rw-r--r--c/lex.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/c/lex.c b/c/lex.c
index e2d86c6..02e9f3d 100644
--- a/c/lex.c
+++ b/c/lex.c
@@ -722,8 +722,22 @@ static void
ppskipline(struct lexer *lx)
{
while (lx->macstk) popmac(lx);
- while (peek(lx, 0) != '\n' && !lx->eof)
- next(lx);
+ for (int c; (c = peek(lx, 0)) != '\n' && !lx->eof; next(lx)) {
+ if (c == '/' && peek(lx, 1) == '*') { /* comment */
+ next(lx), next(lx);
+ bool done = 0;
+ while (!((c = peek(lx, 0)) == '*' && peek(lx, 1) == '/')) {
+ if (lx->eof) {
+ struct span span = {{ lx->idx, lx->chridx - lx->idx, lx->fileid }};
+ fatal(&span, "unterminated comment");
+ }
+ done = c == '\n';
+ next(lx);
+ }
+ next(lx);
+ if (done) return;
+ }
+ }
}
static bool