add CERT exp15-c check (#1897)

* add CERT exp15-c check

* fix false positive

* remove useless check

* fine tune check and test
This commit is contained in:
fuzzelhjb 2019-06-26 18:49:47 +02:00 committed by Daniel Marjamäki
parent cf1f353ec3
commit 9a7ecd622c
2 changed files with 30 additions and 2 deletions

View File

@ -154,6 +154,15 @@ def exp42(data):
token, 'style', "Comparison of struct padding data " +
"(fix either by packing the struct using '#pragma pack' or by rewriting the comparison)", 'EXP42-C')
# EXP15-C
# Do not place a semicolon on the same line as an if, for or while statement
def exp15(data):
for scope in data.scopes:
if scope.type in ('If', 'For', 'While'):
token = scope.bodyStart.next
if token.str==';' and token.linenr==scope.bodyStart.linenr:
reportError(token, 'style', 'Do not place a semicolon on the same line as an IF, FOR or WHILE', 'EXP15-C')
# EXP46-C
# Do not use a bitwise operator with a Boolean-like operand
@ -293,6 +302,7 @@ for arg in sys.argv[1:]:
exp05(cfg)
exp42(cfg)
exp46(cfg)
exp15(cfg)
int31(cfg, data.platform)
str03(cfg)
str05(cfg)

View File

@ -61,6 +61,18 @@ void msc30()
int a = rand;
}
void exp15()
{
int x=5, y=7;
if(x==y); //cert-EXP15-C
{
printf("not working\n");
}
if(x)
;
}
void str03()
{
char *string_data=(char*)malloc(16);
@ -72,8 +84,14 @@ void str03()
void str05()
{
char *str1 = "abc"; //cert-STR05-C
wchar_t *str2 = L"hello"; //cert-STR05-C
int x=5, y=7;
if(x==y); //cert-EXP15-C
{
printf("not working\n");
}
if(x)
;
}
void str07(char *buf, const char *newBuf)