Fix several bugs with multiline comments
Empty the current line if it's entirely inside a comment.
Don't incorrectly end a block comment at the second line if it doesn't
contain `*/`.
Recognize `/*` to start a multiline comment even if it isn't at the start of
the line.
When stripping off comments, consistently strip off `/*` and `*/`.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/tests/scripts/check_names.py b/tests/scripts/check_names.py
index 164d730..5737cd6 100755
--- a/tests/scripts/check_names.py
+++ b/tests/scripts/check_names.py
@@ -478,10 +478,15 @@
* in_block_comment indicates whether the line ends inside a block
comment that continues on the next line.
"""
- # Terminate current comment?
+
+ # Terminate current multiline comment?
if in_block_comment:
- line = re.sub(r".*?\*/", r"", line, 1)
- in_block_comment = False
+ m = re.search(r"\*/", line)
+ if m:
+ in_block_comment = False
+ line = line[m.end(0):]
+ else:
+ return '', True
# Remove full comments and string literals.
# Do it all together to handle cases like "/*" correctly.
@@ -492,10 +497,10 @@
# Start an unfinished comment?
# (If `/*` was part of a complete comment, it's already been removed.)
- m = re.match(r"/\*", line)
+ m = re.search(r"/\*", line)
if m:
in_block_comment = True
- line = line[:m.end(0)]
+ line = line[:m.start(0)]
return line, in_block_comment