misra.py: Fix 12.3 FP for variables defined in headers (#2773)

When we include the header file with variables definitions, Cppcheck
will write `variables` entries with line numbers from the header to the
dump file.

If the line number in the header file and the source file are equal,
misra.py performs an additional check what leads to false positives.

Minimal example that demonstrates the problem:

`misra_fp.c`:
```c
void test_12_3_fp(void)
{
    //Initialize the events queue
    QEQueue_init(&me->deferred_event_queue, me->deferred_events_queue_buf, Q_DIM(me->deferred_events_queue_buf));
}
```

`misra_fp.h`:
```c

static const uint32_t timer_max_blocking_call_us;
```

This commit closes trac ticket 9874.
This commit is contained in:
Georgy Komarov 2020-09-04 21:58:32 +03:00 committed by GitHub
parent 8027f40418
commit e21bdb985c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -1690,8 +1690,9 @@ class MisraChecker:
continue
nt = v.nameToken
if nt and nt.scope and nt.scope.type not in ('Enum', 'Class', 'Struct'):
name_tokens_map.setdefault(nt.linenr, set())
name_tokens_map[nt.linenr].add(nt.column)
if nt.file == filename:
name_tokens_map.setdefault(nt.linenr, set())
name_tokens_map[nt.linenr].add(nt.column)
if not name_tokens_map:
return