misra: implement rule 5.7
This commit is contained in:
parent
859e541661
commit
cf049cb759
|
@ -1104,6 +1104,7 @@ class MisraChecker:
|
||||||
self.existing_violations = set()
|
self.existing_violations = set()
|
||||||
|
|
||||||
self._ctu_summary_typedefs = False
|
self._ctu_summary_typedefs = False
|
||||||
|
self._ctu_summary_tagnames = False
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
attrs = ["settings", "verify_expected", "verify_actual", "violations",
|
attrs = ["settings", "verify_expected", "verify_actual", "violations",
|
||||||
|
@ -1132,14 +1133,12 @@ class MisraChecker:
|
||||||
if len(summary) > 0:
|
if len(summary) > 0:
|
||||||
cppcheckdata.reportSummary(dumpfile, 'MisraTypedefInfo', summary)
|
cppcheckdata.reportSummary(dumpfile, 'MisraTypedefInfo', summary)
|
||||||
|
|
||||||
def misra_2_3(self, data):
|
def _save_ctu_summary_tagnames(self, dumpfile, cfg):
|
||||||
dumpfile = data[0]
|
if self._ctu_summary_tagnames:
|
||||||
typedefInfo = data[1]
|
return
|
||||||
self._save_ctu_summary_typedefs(dumpfile, typedefInfo)
|
|
||||||
|
self._ctu_summary_tagnames = True
|
||||||
|
|
||||||
def misra_2_4(self, data):
|
|
||||||
dumpfile = data[0]
|
|
||||||
cfg = data[1]
|
|
||||||
summary = []
|
summary = []
|
||||||
# structs/enums
|
# structs/enums
|
||||||
for scope in cfg.scopes:
|
for scope in cfg.scopes:
|
||||||
|
@ -1158,6 +1157,16 @@ class MisraChecker:
|
||||||
if len(summary) > 0:
|
if len(summary) > 0:
|
||||||
cppcheckdata.reportSummary(dumpfile, 'MisraTagName', summary)
|
cppcheckdata.reportSummary(dumpfile, 'MisraTagName', summary)
|
||||||
|
|
||||||
|
def misra_2_3(self, data):
|
||||||
|
dumpfile = data[0]
|
||||||
|
typedefInfo = data[1]
|
||||||
|
self._save_ctu_summary_typedefs(dumpfile, typedefInfo)
|
||||||
|
|
||||||
|
def misra_2_4(self, data):
|
||||||
|
dumpfile = data[0]
|
||||||
|
cfg = data[1]
|
||||||
|
self._save_ctu_summary_tagnames(dumpfile, cfg)
|
||||||
|
|
||||||
def misra_2_7(self, data):
|
def misra_2_7(self, data):
|
||||||
for func in data.functions:
|
for func in data.functions:
|
||||||
# Skip function with no parameter
|
# Skip function with no parameter
|
||||||
|
@ -1384,6 +1393,11 @@ class MisraChecker:
|
||||||
typedefInfo = data[1]
|
typedefInfo = data[1]
|
||||||
self._save_ctu_summary_typedefs(dumpfile, typedefInfo)
|
self._save_ctu_summary_typedefs(dumpfile, typedefInfo)
|
||||||
|
|
||||||
|
def misra_5_7(self, data):
|
||||||
|
dumpfile = data[0]
|
||||||
|
cfg = data[1]
|
||||||
|
self._save_ctu_summary_tagnames(dumpfile, cfg)
|
||||||
|
|
||||||
|
|
||||||
def misra_6_1(self, data):
|
def misra_6_1(self, data):
|
||||||
# Bitfield type must be bool or explicitly signed/unsigned int
|
# Bitfield type must be bool or explicitly signed/unsigned int
|
||||||
|
@ -3307,6 +3321,7 @@ class MisraChecker:
|
||||||
self.executeCheck(504, self.misra_5_4, cfg)
|
self.executeCheck(504, self.misra_5_4, cfg)
|
||||||
self.executeCheck(505, self.misra_5_5, cfg)
|
self.executeCheck(505, self.misra_5_5, cfg)
|
||||||
self.executeCheck(506, self.misra_5_6, (dumpfile, cfg.typedefInfo))
|
self.executeCheck(506, self.misra_5_6, (dumpfile, cfg.typedefInfo))
|
||||||
|
self.executeCheck(507, self.misra_5_7, (dumpfile, cfg))
|
||||||
self.executeCheck(601, self.misra_6_1, cfg)
|
self.executeCheck(601, self.misra_6_1, cfg)
|
||||||
self.executeCheck(602, self.misra_6_2, cfg)
|
self.executeCheck(602, self.misra_6_2, cfg)
|
||||||
if cfgNumber == 0:
|
if cfgNumber == 0:
|
||||||
|
@ -3438,6 +3453,10 @@ class MisraChecker:
|
||||||
for old_tagname_info in all_tagname_info:
|
for old_tagname_info in all_tagname_info:
|
||||||
if old_tagname_info['name'] == new_tagname_info['name']:
|
if old_tagname_info['name'] == new_tagname_info['name']:
|
||||||
found = True
|
found = True
|
||||||
|
if old_tagname_info['file'] != new_tagname_info['file'] or old_tagname_info['line'] != new_tagname_info['line']:
|
||||||
|
self.reportError(Location(old_tagname_info['file'], old_tagname_info['line'], old_tagname_info['column']), 5, 7)
|
||||||
|
self.reportError(Location(new_tagname_info['file'], new_tagname_info['line'], new_tagname_info['column']), 5, 7)
|
||||||
|
else:
|
||||||
if new_tagname_info['used']:
|
if new_tagname_info['used']:
|
||||||
old_tagname_info['used'] = True
|
old_tagname_info['used'] = True
|
||||||
if not found:
|
if not found:
|
||||||
|
|
|
@ -9,3 +9,8 @@ MISRA_2_3_A misra_2_3_a;
|
||||||
// cppcheck-suppress misra-c2012-5.6
|
// cppcheck-suppress misra-c2012-5.6
|
||||||
typedef int MISRA_5_6_VIOLATION;
|
typedef int MISRA_5_6_VIOLATION;
|
||||||
|
|
||||||
|
// cppcheck-suppress misra-c2012-5.7
|
||||||
|
struct misra_5_7_violation_t {
|
||||||
|
int x;
|
||||||
|
};
|
||||||
|
static misra_5_7_violation_t misra_5_7_var;
|
||||||
|
|
|
@ -9,3 +9,8 @@ MISRA_2_3_B misra_2_3_b;
|
||||||
typedef int MISRA_5_6_VIOLATION;
|
typedef int MISRA_5_6_VIOLATION;
|
||||||
static MISRA_5_6_VIOLATION misra_5_6_x;
|
static MISRA_5_6_VIOLATION misra_5_6_x;
|
||||||
|
|
||||||
|
// cppcheck-suppress misra-c2012-5.7
|
||||||
|
struct misra_5_7_violation_t {
|
||||||
|
int x;
|
||||||
|
};
|
||||||
|
static misra_5_7_violation_t misra_5_7_var;
|
||||||
|
|
|
@ -12,3 +12,8 @@ int misra_5_2_field_hides_field1_31y;//5.2
|
||||||
};
|
};
|
||||||
const char *s41_1 = "\x41g"; // 4.1
|
const char *s41_1 = "\x41g"; // 4.1
|
||||||
const char *s41_2 = "\x41\x42";
|
const char *s41_2 = "\x41\x42";
|
||||||
|
|
||||||
|
// cppcheck-suppress misra-c2012-5.7
|
||||||
|
struct misra_5_7_violation_t {
|
||||||
|
int x;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue