Skip to content

Commit

Permalink
Fix #12079: Misra: calling unknown function in condition => false pos…
Browse files Browse the repository at this point in the history
…itive 14.4, missing misra-config warning
  • Loading branch information
swasti16 committed Oct 18, 2023
1 parent dd76504 commit 7a8a33b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
15 changes: 14 additions & 1 deletion addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -2805,7 +2805,9 @@ def misra_14_4(self, data):
continue
if not token.astOperand1 or not (token.astOperand1.str in ['if', 'while']):
continue
if not isBoolExpression(token.astOperand2):
if isBoolExpression(token.astOperand2):
continue
if token.astOperand2.valueType:
self.reportError(token, 14, 4)

def misra_15_1(self, data):
Expand Down Expand Up @@ -3185,6 +3187,17 @@ def misra_17_3(self, cfg):
for w in cfg.clang_warnings:
if w['message'].endswith('[-Wimplicit-function-declaration]'):
self.reportError(cppcheckdata.Location(w), 17, 3)
for token in cfg.tokenlist:
if token.str not in ["while","if"]:
continue
if token.next.str != "(":
continue
tok = token.next
while (tok != token.next.link):
if tok.isName and not tok.function and tok.next.str == "(":
self.reportError(tok, 17, 3)
tok = tok.next


def misra_17_6(self, rawTokens):
for token in rawTokens:
Expand Down
15 changes: 9 additions & 6 deletions addons/test/misra/misra-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static void misra_1_2(void)
static _Atomic int misra_1_4_var; // 1.4
static _Noreturn void misra_1_4_func(void) // 1.4
{
if (0 != _Generic(misra_1_4_var)) {} // 1.4
if (0 != _Generic(misra_1_4_var)) {} // 1.4 17.3
printf_s("hello"); // 1.4
}

Expand Down Expand Up @@ -160,13 +160,13 @@ static void foo(void)
{
for(i = 0; i < 10; i++)
{
if(misra_5_2_func3()) //14.4
if(misra_5_2_func3()) //17.3
{
int misra_5_2_var_hides_var_1____31x;
int misra_5_2_var_hides_var_1____31y;//5.2
}
}
} while(misra_5_2_func2()); //14.4
} while(misra_5_2_func2()); //17.3
}
break;
}
Expand Down Expand Up @@ -252,11 +252,11 @@ static void misra_5_5_func1(void)
{
do
{
if(misra_5_5_func3()) //14.4
if(misra_5_5_func3()) //17.3
{
int misra_5_5_hides_macro________31y; //5.5
}
} while(misra_5_5_func2()); //14.4
} while(misra_5_5_func2()); //17.3
}
break;
}
Expand Down Expand Up @@ -1297,13 +1297,16 @@ struct {
unsigned int y:1;
} r14_4_struct; // 8.4
static void misra_14_4(bool b) {
if (x+4){} // 14.4
if (x+4){}
else {}

if (b) {}
else {}

if (r14_4_struct.x) {}

// #12079
if (z) {}
}

static void misra_15_1(void) {
Expand Down

0 comments on commit 7a8a33b

Please sign in to comment.