Skip to content

Commit 915b4b6

Browse files
authored
Fix #10747: FP: misra-c2012-8.6 (#5601)
1 parent 18373bc commit 915b4b6

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

addons/misra.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4630,6 +4630,9 @@ def analyse_ctu_info(self, ctu_info_files):
46304630
def is_different_location(loc1, loc2):
46314631
return loc1['file'] != loc2['file'] or loc1['line'] != loc2['line']
46324632

4633+
def is_different_file(loc1, loc2):
4634+
return loc1['file'] != loc2['file']
4635+
46334636
try:
46344637
for filename in ctu_info_files:
46354638
for line in open(filename, 'rt'):
@@ -4676,18 +4679,21 @@ def is_different_location(loc1, loc2):
46764679
all_macro_info[key] = new_macro
46774680

46784681
if summary_type == 'MisraExternalIdentifiers':
4679-
for s in summary_data:
4682+
for s in sorted(summary_data, key=lambda d: "%s %s %s" %(d['file'],d['line'], d['column'] )):
46804683
is_declaration = s['decl']
46814684
if is_declaration:
46824685
all_external_identifiers = all_external_identifiers_decl
46834686
else:
46844687
all_external_identifiers = all_external_identifiers_def
46854688

46864689
name = s['name']
4687-
if name in all_external_identifiers and is_different_location(s, all_external_identifiers[name]):
4688-
num = 5 if is_declaration else 6
4689-
self.reportError(Location(s), 8, num)
4690-
self.reportError(Location(all_external_identifiers[name]), 8, num)
4690+
if name in all_external_identifiers:
4691+
if is_declaration and is_different_location(s, all_external_identifiers[name]):
4692+
self.reportError(Location(s), 8, 5)
4693+
self.reportError(Location(all_external_identifiers[name]), 8, 5)
4694+
elif is_different_file(s, all_external_identifiers[name]):
4695+
self.reportError(Location(s), 8, 6)
4696+
self.reportError(Location(all_external_identifiers[name]), 8, 6)
46914697
all_external_identifiers[name] = s
46924698

46934699
if summary_type == 'MisraInternalIdentifiers':

addons/test/misra/misra-ctu-1-test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Test with command:
2-
// ./cppcheck --enable=information --addon=misra --inline-suppr addons/test/misra/misra-ctu-*-test.c
2+
// ./cppcheck --enable=information --enable=style --addon=misra --inline-suppr addons/test/misra/misra-ctu-*-test.c
33

44
#include "misra-ctu-test.h"
55

addons/test/misra/misra-ctu-2-test.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Test with command:
2-
// ./cppcheck --enable=information --addon=misra --inline-suppr addons/test/misra/misra-ctu-*-test.c
2+
// ./cppcheck --enable=information --enable=style --addon=misra --inline-suppr addons/test/misra/misra-ctu-*-test.c
33

44
#include "misra-ctu-test.h"
55

@@ -43,7 +43,11 @@ extern int misra_8_5;
4343
// cppcheck-suppress misra-c2012-8.4
4444
// cppcheck-suppress misra-c2012-8.6
4545
int32_t misra_8_6 = 2;
46-
46+
// cppcheck-suppress misra-c2012-8.4
47+
int32_t misra_8_6_1;
48+
// cppcheck-suppress misra-c2012-8.7
49+
// cppcheck-suppress misra-c2012-8.4
50+
int32_t misra_8_6_1 = 2;
4751
// cppcheck-suppress misra-c2012-8.4
4852
// cppcheck-suppress misra-c2012-8.7
4953
void misra_8_7(void) {}

0 commit comments

Comments
 (0)