Skip to content

Commit 30ff1aa

Browse files
apulyPaul B
andauthored
misra: fix misra-3_1 false positive for URIs in block comments (#4939)
* misra: fix misra-3_1 false positive for URIs in block comments * added unit test, improved new misra 3.1 based on false positives --------- Co-authored-by: Paul B <unconfigured@null.spigotmc.org>
1 parent 12118d8 commit 30ff1aa

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

addons/misra.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,10 +1543,19 @@ def misra_2_7(self, data):
15431543
def misra_3_1(self, rawTokens):
15441544
for token in rawTokens:
15451545
starts_with_double_slash = token.str.startswith('//')
1546-
if token.str.startswith('/*') or starts_with_double_slash:
1547-
s = token.str.lstrip('/')
1548-
if ((not starts_with_double_slash) and '//' in s) or '/*' in s:
1549-
self.reportError(token, 3, 1)
1546+
starts_with_block_comment = token.str.startswith("/*")
1547+
s = token.str.lstrip('/')
1548+
if (starts_with_double_slash or starts_with_block_comment) and "/*" in s:
1549+
# Block comment inside of regular comment, violation
1550+
self.reportError(token, 3, 1)
1551+
elif starts_with_block_comment and "//" in s:
1552+
# "//" in block comment, check if it's a uri
1553+
while "//" in s:
1554+
possible_uri, s = s.split("//", 1)
1555+
if not re.search(r"\w+:$", possible_uri):
1556+
# Violation if no uri was found
1557+
self.reportError(token, 3, 1)
1558+
break
15501559

15511560
def misra_3_2(self, rawTokens):
15521561
for token in rawTokens:

addons/test/misra/misra-test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ static void misra_2_2(int x) {
8282
/* // */ // 3.1
8383
/* /* */ // 3.1
8484
////
85+
/* https://cppcheck.net */
8586

8687
// http://example.com // no warning
8788

0 commit comments

Comments
 (0)