From 5482d1db320a86a0eccfa4118528261e77194eda Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 6 Nov 2023 12:43:53 +0200 Subject: Fix C-comment scanning bug in cc::lexer --- libbuild2/cc/lexer+comment.test.testscript | 5 +++++ libbuild2/cc/lexer.cxx | 17 +++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/libbuild2/cc/lexer+comment.test.testscript b/libbuild2/cc/lexer+comment.test.testscript index 358865c..381e479 100644 --- a/libbuild2/cc/lexer+comment.test.testscript +++ b/libbuild2/cc/lexer+comment.test.testscript @@ -16,6 +16,11 @@ four /** six /* */ +/* */ +/* + +*/ +/**/ EOI : cxx-comment diff --git a/libbuild2/cc/lexer.cxx b/libbuild2/cc/lexer.cxx index 96bd887..d20e0dc 100644 --- a/libbuild2/cc/lexer.cxx +++ b/libbuild2/cc/lexer.cxx @@ -1111,21 +1111,18 @@ namespace build2 if (eos (c)) fail (p) << "unterminated comment"; - if (c == '*' && (c = peek ()) == '/') + if (c == '*') { - get (c); - break; + if ((c = peek ()) == '/') + { + get (c); + break; + } } - - if (c != '*' && c != '\\') + else { // Direct buffer scan. // - // Note that we should call get() prior to the direct buffer - // scan (see butl::char_scanner for details). - // - get (c); - const char* b (gptr_); const char* e (egptr_); const char* p (b); -- cgit v1.1