Add check for MISRA-C 2012 rule 3.2 and test cases. (#2269)
* Add check for MISRA-C 2012 rule 3.2 and test cases. * Fix formatting of MISRA rule 3.2 example.
This commit is contained in:
parent
7d6d561c84
commit
387132389a
|
@ -746,6 +746,19 @@ class MisraChecker:
|
|||
if ((not starts_with_double_slash) and '//' in s) or '/*' in s:
|
||||
self.reportError(token, 3, 1)
|
||||
|
||||
def misra_3_2(self, rawTokens):
|
||||
for token in rawTokens:
|
||||
if token.str.startswith('//'):
|
||||
# Check for comment ends with trigraph which might be replaced
|
||||
# by a backslash.
|
||||
if token.str.endswith('??/'):
|
||||
self.reportError(token, 3, 2)
|
||||
# Check for comment which has been merged with subsequent line
|
||||
# because it ends with backslash.
|
||||
# The last backslash is no more part of the comment token thus
|
||||
# check if next token exists and compare line numbers.
|
||||
elif (token.next != None) and (token.linenr == token.next.linenr):
|
||||
self.reportError(token, 3, 2)
|
||||
|
||||
def misra_4_1(self, rawTokens):
|
||||
for token in rawTokens:
|
||||
|
@ -2404,6 +2417,7 @@ class MisraChecker:
|
|||
|
||||
if cfgNumber == 1:
|
||||
self.misra_3_1(data.rawTokens)
|
||||
self.misra_3_2(data.rawTokens)
|
||||
self.misra_4_1(data.rawTokens)
|
||||
self.misra_4_2(data.rawTokens)
|
||||
self.misra_5_1(cfg)
|
||||
|
|
|
@ -25,6 +25,22 @@ typedef unsigned long long u64;
|
|||
|
||||
// http://example.com // no warning
|
||||
|
||||
void misra_3_2(int enable)
|
||||
{
|
||||
// This won't generate a violation because of subsequent blank line \
|
||||
|
||||
int y = 0;
|
||||
int x = 0; // 3.2 non-compliant comment ends with backslash \
|
||||
if (enable != 0)
|
||||
{
|
||||
++x; // This is always executed
|
||||
// 3.2 potentially non-compliant comment ends with trigraph resolved to backslash ??/
|
||||
++y; // This is hidden if trigraph replacement is active
|
||||
}
|
||||
|
||||
(void)printf("x=%i, y=%i\n", x, y);
|
||||
}
|
||||
|
||||
extern int misra_5_1_extern_var_hides_var_x;
|
||||
extern int misra_5_1_extern_var_hides_var_y; //5.1
|
||||
int misra_5_1_var_hides_var________a;
|
||||
|
|
Loading…
Reference in New Issue