Fixed #9625 (false negative: misra-c2012-13.1)

This commit is contained in:
Daniel Marjamäki 2020-02-11 18:00:41 +01:00
parent 0bf9858d57
commit 099dd57eb8
2 changed files with 7 additions and 2 deletions

View File

@ -1738,7 +1738,9 @@ class MisraChecker:
def misra_13_1(self, data):
for token in data.tokenlist:
if not simpleMatch(token, '= {'):
if simpleMatch(token, ") {") and token.next.astParent == token.link:
pass
elif not simpleMatch(token, '= {'):
continue
init = token.next
end = init.link

View File

@ -1,5 +1,5 @@
// To test:
// ~/cppcheck/cppcheck --dump misra-test.c && python ../../misra.py -verify misra-test.c.dump
// ~/cppcheck/cppcheck --dump --suppress=uninitvar --suppress=uninitStructMember misra/misra-test.c --std=c89 && python3 ../misra.py -verify misra/misra-test.c.dump
#include "path\file.h" // 20.2
@ -475,11 +475,14 @@ void misra_12_4() {
}
struct misra_13_1_t { int a; int b; };
uint8_t misra_13_1_x = 0;
void misra_13_1_bar(uint8_t a[2]);
void misra_13_1(int *p) {
volatile int v;
int a1[3] = {0, (*p)++, 2}; // 13.1
int a2[3] = {0, ((*p) += 1), 2}; // 13.1
int a3[3] = {0, ((*p) = 19), 2}; // 13.1
misra_13_1_bar((uint8_t[2]){ misra_13_1_x++, misra_13_1_x++ } ); // 13.1
int b[2] = {v,1};
struct misra_13_1_t c = { .a=4, .b=5 }; // no fp
volatile int vv;