Skip to content

Commit

Permalink
Fix #12362: False positive: misra 8.7: taking function by address is …
Browse files Browse the repository at this point in the history
…not recognized as function usage (#5920)
  • Loading branch information
swasti16 committed Jan 31, 2024
1 parent 593cf5f commit f82790d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,7 @@ def _save_ctu_summary_usage(self, dumpfile, cfg):
for token in cfg.tokenlist:
if not token.isName:
continue
if token.function and token.scope.isExecutable:
if token.function and token != token.function.tokenDef:
if (not token.function.isStatic) and (token.str not in names):
names.append({'name': token.str, 'file': token.file})
elif token.variable:
Expand Down
4 changes: 4 additions & 0 deletions addons/test/misra/misra-ctu-1-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ extern int misra_8_5;
int32_t misra_8_6 = 1;

void misra_8_7_external(void) {}

// #12362
void misra_8_7_compliant( void ){}
static void misra_8_7_call(void) { misra_8_7_compliant(); }
3 changes: 3 additions & 0 deletions addons/test/misra/misra-ctu-2-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ static void misra_8_7_caller(void) {
misra_8_7_external();
}

// #12362
typedef void(*misra_8_7_func_ptr)( void );
static const misra_8_7_func_ptr ptrs[] = { misra_8_7_compliant, NULL };
2 changes: 2 additions & 0 deletions addons/test/misra/misra-ctu-test.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ void misra_8_7_external(void);
// cppcheck-suppress misra-c2012-2.5
#define MISRA_2_5_VIOLATION 0

// #12362
extern void misra_8_7_compliant( void );

0 comments on commit f82790d

Please sign in to comment.