Skip to content

Commit

Permalink
Fix #10747: FP: misra-c2012-8.6 (danmar#5601)
Browse files Browse the repository at this point in the history
  • Loading branch information
swasti16 authored Oct 29, 2023
1 parent 18373bc commit 915b4b6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
16 changes: 11 additions & 5 deletions addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -4630,6 +4630,9 @@ def analyse_ctu_info(self, ctu_info_files):
def is_different_location(loc1, loc2):
return loc1['file'] != loc2['file'] or loc1['line'] != loc2['line']

def is_different_file(loc1, loc2):
return loc1['file'] != loc2['file']

try:
for filename in ctu_info_files:
for line in open(filename, 'rt'):
Expand Down Expand Up @@ -4676,18 +4679,21 @@ def is_different_location(loc1, loc2):
all_macro_info[key] = new_macro

if summary_type == 'MisraExternalIdentifiers':
for s in summary_data:
for s in sorted(summary_data, key=lambda d: "%s %s %s" %(d['file'],d['line'], d['column'] )):
is_declaration = s['decl']
if is_declaration:
all_external_identifiers = all_external_identifiers_decl
else:
all_external_identifiers = all_external_identifiers_def

name = s['name']
if name in all_external_identifiers and is_different_location(s, all_external_identifiers[name]):
num = 5 if is_declaration else 6
self.reportError(Location(s), 8, num)
self.reportError(Location(all_external_identifiers[name]), 8, num)
if name in all_external_identifiers:
if is_declaration and is_different_location(s, all_external_identifiers[name]):
self.reportError(Location(s), 8, 5)
self.reportError(Location(all_external_identifiers[name]), 8, 5)
elif is_different_file(s, all_external_identifiers[name]):
self.reportError(Location(s), 8, 6)
self.reportError(Location(all_external_identifiers[name]), 8, 6)
all_external_identifiers[name] = s

if summary_type == 'MisraInternalIdentifiers':
Expand Down
2 changes: 1 addition & 1 deletion addons/test/misra/misra-ctu-1-test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Test with command:
// ./cppcheck --enable=information --addon=misra --inline-suppr addons/test/misra/misra-ctu-*-test.c
// ./cppcheck --enable=information --enable=style --addon=misra --inline-suppr addons/test/misra/misra-ctu-*-test.c

#include "misra-ctu-test.h"

Expand Down
8 changes: 6 additions & 2 deletions addons/test/misra/misra-ctu-2-test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Test with command:
// ./cppcheck --enable=information --addon=misra --inline-suppr addons/test/misra/misra-ctu-*-test.c
// ./cppcheck --enable=information --enable=style --addon=misra --inline-suppr addons/test/misra/misra-ctu-*-test.c

#include "misra-ctu-test.h"

Expand Down Expand Up @@ -43,7 +43,11 @@ extern int misra_8_5;
// cppcheck-suppress misra-c2012-8.4
// cppcheck-suppress misra-c2012-8.6
int32_t misra_8_6 = 2;

// cppcheck-suppress misra-c2012-8.4
int32_t misra_8_6_1;
// cppcheck-suppress misra-c2012-8.7
// cppcheck-suppress misra-c2012-8.4
int32_t misra_8_6_1 = 2;
// cppcheck-suppress misra-c2012-8.4
// cppcheck-suppress misra-c2012-8.7
void misra_8_7(void) {}
Expand Down

0 comments on commit 915b4b6

Please sign in to comment.