Commit Graph

422 Commits

Author SHA1 Message Date
Armin Müller 0de0a954d2
Typos found by running "codespell" (#3042) 2021-01-12 20:48:25 +01:00
kskjerve d4860f500a
MISRA 9.2 to 9.5 (#2954) 2020-12-16 17:28:54 +01:00
Daniel Marjamäki a810678b83 Addons: handle inline suppressions internally in cppcheckdata 2020-12-05 11:37:09 +01:00
Daniel Marjamäki 649a754cfd Revert "Addons: handle inline suppressions internally in cppcheckdata"
This reverts commit 1ce78a1086.

There was regressions in handling of suppressions.
2020-12-04 18:05:47 +01:00
Ivar Andreas Bonsaksen 9029fff59d
Fixed #9993 (false positive: misra-c2012-9.2) (#2908) 2020-11-18 10:50:35 +01:00
Ivar Andreas Bonsaksen 0e7ec1eddf
Fixed #9988 (false positive: misra-c2012-9.2) (#2904) 2020-11-16 17:31:00 +01:00
kskjerve 4d3f76b63c
MISRA rule 9.2 The initializer for an aggregate or union shall be enclosed in braces (#2899) 2020-11-16 09:27:17 +01:00
Daniel Marjamäki c7f816f986 Misra refactorings 2020-11-13 07:21:34 +01:00
Lars Even Almaas 3a91b998d6
MISRA rule 10.2 Expressions of essentially character type in additions and subtraction (#2897) 2020-11-12 11:37:28 +01:00
Daniel Marjamäki 1ce78a1086 Addons: handle inline suppressions internally in cppcheckdata 2020-11-11 20:01:58 +01:00
Daniel Marjamäki 7e8839a991 Addons: Reuse cppcheckdata.simpleMatch 2020-11-11 14:24:55 +01:00
Lars Even Almaas 9d70926fcd
MISRA rule 15.4 Only one break/goto from iteration statement (#2892) 2020-11-09 15:11:08 +01:00
Georgy Komarov 9cbb09076c
misra.py: Fix R7.2 crash on va_args (#2886) 2020-11-05 23:54:12 +01:00
Lars Even Almaas c1212f823f
MISRA rule 7.2 Require 'u' prefix when using large unsigned integer constants (#2881) 2020-11-05 13:38:09 +01:00
Georgy Komarov 6f7f508967
misra.py: Fix 7.4 false positive (#2883)
Fix false positives for the function calls with "const pointer to const
value" arguments: https://trac.cppcheck.net/ticket/9967.

The variable.valueType.constness have same encoding as encoding as
ValueType::constness in Cppcheck.
2020-11-05 08:13:23 +01:00
Lars Even Almaas 05b804d126
MISRA Rule 7.4 Check if variables assigned as string literals are const (#2866) 2020-11-04 13:45:02 +01:00
Georgy Komarov b87aaaac52
Fix and impove MISRA 6.1 and 6.2 rules (#2863) 2020-10-28 20:54:43 +01:00
Lars Even Almaas 79b9dd5345
MISRA Rule 6.1/6.2 Bit field check (#2861) 2020-10-27 16:00:19 +01:00
Georgy Komarov 3944e70e02
misra.py: Treat enum constants as constant known at compile time (#2823)
C89 standard defines enum members as enumeration contants at ch.
6.4.4.3, and they are always known at compile time.

This commit fix false positives for rule 18.8 (and possible other rules
that check "constentess") with enumeration members.

Fix Trac#9913
2020-09-25 21:02:34 +02:00
Daniel Marjamäki 687b44dbb7 Token: add flag for splitted variable declaration with initialization 2020-09-09 16:22:47 +02:00
Daniel Marjamäki 6e4085f3d8 Misra: Write 12.3 warnings in structs/classes 2020-09-08 09:29:57 +02:00
Daniel Marjamäki 9a943e7616 misra: rewrote rule 12.3 2020-09-06 11:33:37 +02:00
Georgy Komarov 4738da3d69
misra.py: Fix R12.3 FP on calling functions in function arguments (#2778) 2020-09-05 07:53:56 +02:00
Georgy Komarov e21bdb985c
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.
2020-09-04 20:58:32 +02:00
Daniel Marjamäki c6d2e0fae1 Fixed #9830 (Addons should return 0 when success) 2020-08-29 07:44:32 +02:00
Georgy Komarov 3bae716fd4
misra.py: Fix 20.7 false positive for multi-character arguments
See: https://trac.cppcheck.net/ticket/9633#comment:3
2020-08-08 13:03:19 +03:00
Georgy Komarov dc1faa71ed
misra.py: Fix false negatives in string concatenation for rule 20.7
This will fix Trac#9633
2020-07-24 07:15:40 +03:00
Georgy Komarov fc504ed6c3
misra.py: Fix false positives on macro expansion
This will fix Trac#9634
2020-07-21 20:03:04 +03:00
Richard A. Smith 41a846d8a7 misra.py: Squelch duplicate violation messages
When checking multiple files if the same violation is encountered from
an included file then the violation is both displayed and counted in the
error summary.

Track each violation by location and error number and if the violation
has been previously encountered then do not report it again.
2020-07-19 08:42:35 -03:00
Carl-Oskar Larsson 2abf542838
Misra severity (#2674) 2020-06-08 15:58:17 +02:00
Georgy Komarov 90550d24c4
misra.py: Fix crash on volatile macro argument (#2654) 2020-05-21 08:34:28 +02:00
Georgy Komarov 61926ed7c3
misra.py: Fix false positive for rule 15.6 (#2631) 2020-05-07 16:54:27 +02:00
felwolff b65d72aeb6
misra.py: Fix 5.1 and 5.2 FP for c99 (#2625) 2020-04-28 07:18:54 +02:00
Georgy Komarov 20b02bff30
misra.py: Fix 20.7 FP for struct members (#2624)
This will close Trac#9673
2020-04-27 09:10:58 +02:00
amai2012 3be79aee98
Cure invalid constant
https://lgtm.com/projects/g/danmar/cppcheck?mode=list poined out this "implicit string concatenation"
2020-04-14 15:47:44 +02:00
Georgy Komarov 4e5a8fac4a
misra.py: Handle stdint.h essential types (#2555)
Add stdint.h essential types to misra.py checks. This will fix false
negatives for rules 10.6 and 10.8.
2020-02-27 11:28:48 +01:00
Armin Müller 75b1ade316
Typos found by running "codespell" (#2542) 2020-02-17 18:28:58 +01:00
Georgy Komarov 9155f3a83a
misra.py: Check switch-clauses in R15.3 (#2538)
* misra.py: Check switch-clauses in R15.3

* break on violation
2020-02-16 00:03:18 +01:00
Georgy Komarov 2138091fa3
misra.py: Fix rule 20.2 false negative (#2534) 2020-02-12 17:11:56 +01:00
Georgy Komarov 403a61bc11
misra.py: Handle spaces in directive arguments (#2532) 2020-02-11 20:59:11 +01:00
Daniel Marjamäki 099dd57eb8 Fixed #9625 (false negative: misra-c2012-13.1) 2020-02-11 18:00:41 +01:00
Georgy Komarov 583d5e5958
misra.py: Add standard library functions for C90 and C99 (#2524)
This is required to add additional analysis for some MISRA rules.

This commit improve R21.1 check and close trac ticket 9603.
2020-02-11 11:10:54 +01:00
Georgy Komarov 0ff23dbd0b misra.py: Handle more cases in Rule 20.3 check (#2529)
This commit add two additional cases for rule 20.3:

1. Support violations in the following format: `#include file.h`
2. Better multiline include directives and inline comments support.

See added test cases for examples.
2020-02-10 08:56:26 +01:00
Georgy Komarov f438cc6105
misra.py: Fix rule 21.1 false positives (#2526)
According MISRA standard, rule 21.1 should hanlde define/undef
directives only. There are no mentions of other C identifiers in the
standard document.
2020-02-09 16:22:26 +01:00
Georgy Komarov 6d4eff46be
misra.py: Fix false negative for rule 20.4 (#2528)
Define different sets of reserved keywords for C90 and C99.
This will fix false negative for compliant example, defined in MISRA
document, and close trac 9506.
2020-02-09 10:46:13 +01:00
Georgy Komarov 5eaf437c44
misra.py: Fix R5.4 false positives with C99 (#2516)
* parser: Parse standards node at start event

This required, because we can loose data at the end event.

* misra.py: Fix 5.4 standard-dependent error

By default Cppcheck use C11 standard, so this change fix false positives
for rule 5.4 with C99.

* travis: force --std=c89 for misra.py
2020-01-31 23:38:41 +01:00
Georgy Komarov 86d0f62d36 misra.py: Fix 12.3 FP in initializer lists (#2489)
See: trac 9581
2020-01-15 09:55:59 +01:00
mlambacher 3ada7672f3 Fix potential typo: use token.next.linenr instead of token.linenr (#2483)
Also make use of defaultdict to minimize risk of similar typos in the future and to clean up the code
2020-01-09 19:31:18 +01:00
elfel19 a288ea3c1f improve misra analysis perf for misra_5_4, misra_5_5, misra_20_1 (#2329)
fix bad indent
2020-01-08 06:54:43 +01:00
Daniel Marjamäki 33c8b71467 Revert "addons; import cppcheckdata from local folder"
This reverts commit 05b96d42e9.
2019-12-30 17:30:17 +01:00
Daniel Marjamäki 05b96d42e9 addons; import cppcheckdata from local folder 2019-12-30 09:13:04 +01:00
Georgy Komarov d977761e76 addons: Reduce memory consumption (#2395)
* addons: Reduce memory consumption

Parse dump files incrementaly using ElementTree.iterparse. Clean unused
resources during parsing.  This method is explained in following
article: https://www.ibm.com/developerworks/xml/library/x-hiperfparse/

Memory consumption was reduced about 30% (measured with mprof),
execution time increased about 5% (measured with time utility).
More description available in PR.

* Switch to lxml and update iterparse routines

Use lxml module instead default xml.etree. Lxml provides convenient
wrappers around iterparse method that accepts `tag` argument. That
easer incremental parsing routines to select specific tags from roottree
like `dump` and `dumps`.

Element.clear() method was replaced by `lxml_clean` because lxml
keeps additional information to nodes that should be removed.

Added note about large consumption RAM on large dump files.
This commit doesn't solve this problem completely, but provides a way
to improve current parser to add incremental Configuration serialization
later.

* Working on iterative parser

* Added iterative Configurations parser

* fix

* Fix varlist iteration

* make sure that standards node was loaded
2019-12-27 08:50:56 +01:00
Georgy Komarov 730ea4163b misra.py: Handle essential type categories for ternary operations (#2455)
This commit will add feature to detect essential type categories
for operators of ternary operation.

This fixes issues with rule 10.1 and close the following ticket:
https://trac.cppcheck.net/ticket/9543
2019-12-21 07:40:15 +01:00
Georgy Komarov aadb35888f misra.py: Fix 12.3 FP (#2454)
This will close https://trac.cppcheck.net/ticket/9544
2019-12-19 15:55:51 +01:00
Georgy Komarov d0dd200444 misra.py: Fix R12.3 false negative in variables declaration (#2453)
Make rule 12.3 check detect commas in the variables declaration code.
2019-12-19 08:36:10 +01:00
Daniel Marjamäki 7977bbf456 Revert "misra.py: Fix R12.3 false negative in variables declaration (#2431)"
This reverts commit 7ce8ae408a.
2019-12-18 13:31:52 +01:00
Georgy Komarov 7ce8ae408a misra.py: Fix R12.3 false negative in variables declaration (#2431)
* misra.py: Allow executeCheck take multiple args

* misra.py: Fix R12.3 FN in variables declaration

Make rule 12.3 check detect commas in variables declaration code.

* Fix excluded lines

* Add support for global variables

* Fix FN when linenr from other file was excluded

* Add a few more tests

* Handle more cases

Handle additional cases to check commans in variables declaration
including:
* multiline variables declaration
* functions and structures initialized in the same line
* expanding macroses in initialization

* Fix FP in global struct initialization

* Add another test
2019-12-18 11:05:57 +01:00
Georgy Komarov c46e44e39e misra.py: R14.2: Verify for loop counter modification (#2409)
* misra.py: R14.2: Verify for counter modification

Add additional check to detect modification of loop counter in loop
body. Related issue: https://trac.cppcheck.net/ticket/9490

Add small fix that treat all assignment operators defined in N1750
6.5.16 as has side affects. This will affects rules 13.1, 13.3, 13.5
and allow to catch some false negatives.

* Add tests for fixed FPs for R13.{1,5,6}

* fix

* use isAssignmentOp from cppcheck data

* remove unused set

* handle case with empty body or syntax error

* add test with outer variable

* Fix FP in nested loops, add tests

* Fix FP on outer variables

* Fixup false positives for not loop counters
2019-12-15 18:23:12 +01:00
Georgy Komarov f87cd9818c misra.py: Fix false negative for rule 10.1 (#2449)
This will close Trac 9489.
2019-12-15 18:10:22 +01:00
Daniel Marjamäki 5e07528af5 Fixed #9505 (MISRA 20.7 check suggests code change that leads to invalid code) 2019-12-14 16:31:41 +01:00
Francesc Elies d538315268 [python] classes are missing __repr__ methods (#2437)
* [python] classes don't have a __repr__ method

* [python] removes unused import
2019-12-09 19:08:45 +01:00
Daniel Marjamäki 3d3e6f384c Fix #9505 (MISRA 20.7 check suggests code change that leads to invalid code) 2019-12-08 20:07:52 +01:00
Daniel Marjamäki 61c2c5a5f0 Misra: rule 5.3 is implemented in Cppcheck 2019-12-08 19:06:34 +01:00
Daniel Marjamäki 4a4b6fe39b MISRA: Remove rule 5.3, Cppcheck core has these warnings 2019-12-08 19:01:51 +01:00
Daniel Marjamäki 55afaebdac Fixed #9506 (false positive: MISRA 12.4) 2019-12-08 18:52:52 +01:00
Georgy Komarov 6bacc1987c misra.py: Fix R12.4 and R13.1 crashes on large initializer lists (#2410)
Fixed usage of hasSideEffectsRecursive which was causes crashes
of rules 12.4 and 13.1.

Add more tests for these rules.

See trac ticket: https://trac.cppcheck.net/ticket/9487
2019-12-01 15:03:33 +01:00
Georgy Komarov c1770414ba misra.py: Fix crash on c++ code (#2414) 2019-12-01 14:51:12 +01:00
Georgy Komarov bd6f236481 misra.py: Fix 5.3 FP (#2405)
* misra.py: Fix 5.3 FP

This will close https://trac.cppcheck.net/ticket/9497

* fix names conflict

* fix naming
2019-11-30 10:05:57 +01:00
Mathias Schmid 8c22b2a316 Add check for MISRA-C 2012 Rule 2.7 and test cases. (#2340)
* Add check for MISRA-C 2012 Rule 2.7 and test cases.

* Cast unused function parameters of some test patterns to "void".

* Fix function parameter void cast in "misra_17_6". Add comment to "misra_11_7_extra" to make all function parameter void casts look alike.
2019-11-18 06:56:30 +01:00
Sebastian 8a32a210f8
addons: Change shebang to use Python 3 instead of Python 2 (#2361)
Use Python 3 instead of Python 2 if addons are executed directly.
Running cert.py and misra.py against test/cfg/std.c.dump shows that
Python 3 needs only half the time compared to Python 2. I have tested
it repeatedly and the results are always the same. This is no surprise
at all. The memory footprint is very likely also significantly better
but i have not tested it.
2019-11-15 21:38:20 +01:00
Georgy Komarov 3bd126486f addons: Clean up and clarify addons usage. (#2359)
* addons: Add '--recursive' arg. Clean up and clarify errors messages.

This commit introduce '--recursive' option for cppcheck addons.
Iff this option is set addon will recursively traverse directories in
given input files to find files with '.dump' suffix that would be
checked. Otherwise it will treat input directory as error (current
behaviour).

Add additional error handling with more clear error messages, clean up
the code.

* Add regex specifier

* Roll back --recursive option

* Update addons section in manual
2019-11-15 20:14:30 +01:00
Sebastian 2b1a1a2a38
misra.py: Fix mutable default argument in "misra_17_2()" (#2355)
PyCharm inspection warns for argument `visited=set()` with
"Default argument is mutable".
According to different sources one should nearly never use mutable
default arguments:
https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments
https://dev.to/florimondmanca/python-mutable-defaults-are-the-source-of-all-evil-6kk
2019-11-13 14:45:34 +01:00
Georgy Komarov dbe23f878b misra.py: Fix R21.1 crash on C++ code (#2354)
Variables from cppcheckdata.Variable have no nameToken if they are
objects of user-defined classes.
2019-11-13 07:58:26 +01:00
Sebastian 3e0ecc8bed
misra.py: Fix typos, PEP 8 and Inspection warnings (#2352) 2019-11-12 15:32:05 +01:00
Sebastian 1daf076d63
pylintrc_travis: Add check for bad-indentation, fix issues in misra.py (#2349) 2019-11-11 13:53:19 +01:00
Georgy Komarov 16e8016259 misra.py: Fix R21.1 FalsePositive on standard functions and errno (#2339)
Rule 21.1 now doesn't report errors on usage of library functions
started from underscore (e.g. `_exit') and valid errno assignment.

See added tests for examples.
2019-11-08 17:20:37 +01:00
Georgy Komarov ba217815cb misra.py: Fix R16.3 FN in last case/default statement (#2325)
Fix R16.3 state machine which doesn't report errors in last case/default
statemenet. See added tests for examples.

Issue on trac: https://trac.cppcheck.net/ticket/8548
2019-11-08 08:06:10 +01:00
Sebastian 828a3fda1f
pylintrc_travis: Enable more checks, fix anomalous-backslash-in-string issues (#2334) 2019-11-06 17:49:37 +01:00
Sebastian 2ce6167894 pylintrc_travis: Enable check for unnecessary-semicolon and fix issue (#2333) 2019-11-06 13:40:15 +01:00
Georgy Komarov c207828a11 misra.py: Fix large memory usage with suppressions (#2321)
* misra.py: Fix large memory usage with suppressions

Don't save whole lxml locations when collecting rules suppressions
statistics. This fixes the problem with large memory usage when
some rules are suppressed.

See issue description:
https://sourceforge.net/p/cppcheck/discussion/development/thread/51fc053626/

* don't override 'file' builtin
2019-11-04 06:58:33 +01:00
Georgy Komarov ff61d8e370 misra.py: Skip execution for globally suppressed checks (#2301)
These changes will improve misra.py execution time in the
case where we use globally suppressed checks. For example, when using
single MISRA rule and suppress others, we could get about twice the
execution speed, since most of `MisraChecker' class methods will not
be started at all.

Some measurements and discussion are available at:
https://github.com/danmar/cppcheck/pull/2301
2019-11-04 06:57:41 +01:00
Georgy Komarov b35091b827 misra.py: Fix 18.8 crash on checking undefined id (#2299) 2019-10-26 17:29:38 +02:00
Georgy Komarov 72f07c8a33 Add MISRA checks for rules 21.1 and 21.12 (#2284)
* Add MISRA 21.1 check

This also required add static field for functions in symboldatabase.

* Add MISRA R21.12

* Use newer ASSERT macroses in tests
2019-10-26 08:32:46 +02:00
Mathias Schmid 387132389a Add check for MISRA-C 2012 rule 3.2 and test cases. (#2269)
* Add check for MISRA-C 2012 rule 3.2 and test cases.

* Fix formatting of MISRA rule 3.2 example.
2019-10-16 11:31:42 +02:00
Mathias Schmid 1df97ac5c8 Add check for MISRA-C 2012 rule 4.2 - Trigraphs should not be used - as well as some test cases. (#2253) 2019-10-09 08:26:05 +02:00
Conrado Gouvea 40f136ac78 MISRA: add exception to rule 3.1 (#2231)
* misra: add exception to rule 3.1

* misra: add parenthesis for clarity in rule 3.1
2019-10-03 21:15:00 +02:00
Conrado Gouvea 67971db58f misra: fix false positive in 11.7 (#2233) 2019-10-03 10:15:50 +02:00
Armin Müller b4af8bdc2e Typos found by running "codespell" (#2227) 2019-09-29 21:23:19 +02:00
Georgy Komarov 846f356db4 misra.py: Fix Rule 4.1 (#2216)
* misra.py: Use standard string module

* misra.py: Fixup R4.1

References:
* https://trac.cppcheck.net/ticket/9370
* https://sourceforge.net/p/cppcheck/discussion/development/thread/7274ed3842/?limit=25#799a

* Add more examples from @matzeschmid PR

* Add more out-of-bounds tests

* Fix R4.1.

* Compress hex condition

* Add more test cases

* Fix python3 zip import
2019-09-28 20:16:10 +02:00
Richard A. Smith 2b44fb57bc Loosen restrictions on MISRA rules text structure (#2157)
Version 1.88 changed the parsing of the MISRA rules file adding a
severity setting.  This caused a regression in rule parsing.

In particular the following format used to parse cleanly and produce
rule output that would show the severity as part of the rule text.

    Rule 1.2

    Advisory

    Rule text goes here.

    Rule 1.3

    Required

    More rule text goes here.

As of 1.88 a file structured like above would parse as having no rules.

The problem is the use of blank lines as a rule delimiter.   The
modified rule parser wants to see a rules formatted like below:

    Rule 3.1 Required
    R3.1 text.
    Rule 4.1 Required
    R4.1 text.

or:

    Rule 1.1
    Add this rule and parse to next, skipping empty lines.

    Rule 1.2
    Rule text.

Any rule text that did not fall into one of the above formats would
result in incomplete rule text parsing.

Change the parsing of the rule text file so that blank lines are ignored
instead of treating them as a delimiter between rules. Instead use the
start of the next rule as a delimiter for the end of the previous rule.
This allows both of the newer formats but also supports the behavior of
pre-1.88 versions.

Change units tests that were specifically forbidding the use of blank
lines to ones that allow blank lines.
2019-09-09 21:43:44 +02:00
Conrado Gouvea 3740c57160 misra: fix rule 5.4 false positive when macro is defined 'twice' inside #if/#else (#2125) 2019-08-31 07:53:16 +02:00
Daniel Marjamäki 2d9a131817 Refactoring: Rename variables. Do not use leading _. Renamed 'col' to 'column' 2019-08-18 12:19:05 +02:00
Daniel Marjamäki 2e9e3ed2f1 Fixed #8823 (false positive: MISRA rule 16.3) 2019-08-11 19:08:57 +02:00
Daniel Marjamäki 016340f77d Fixed #8657 (false postive: MISRA rule 15.7) 2019-08-11 17:54:02 +02:00
Daniel Marjamäki 46c93779d8 misra: updated getEssentialType 2019-08-11 10:15:07 +02:00
Daniel Marjamäki 43aabcd318 Fixed #8656 (false positive: MISRA rule 10.1) 2019-08-11 09:47:37 +02:00
Daniel Marjamäki 8c7ae14f0b misra: python refactorings 2019-08-10 18:12:23 +02:00
Daniel Marjamäki 996000da52 Fixed #9208 (MISRA addon crashes on enum with constant expression) 2019-08-04 12:24:45 +02:00
Georgy Komarov 6bd1c92c24 misra.py: Bring back -P argument for backward compatibility (#2030)
* misra.py: Bring back -P argument for backward compatibility

* Restore --file-prefix logic

* Add arguments regression test
2019-07-24 07:16:48 +02:00
Georgy Komarov 413a5a4865 MISRA: Fix rules suppression, add tests (#1996)
* MISRA: Fix suppressed rules line numbers

Line numbers represented as strings in lxml ETree, but we use it in
integer comparison later.

* MISRA: Use standard library function instead file_prefix.

* MISRA: Use pytest's capsys for capturing, add suppressions tests.

* travis.yml: Update pytest version
2019-07-16 22:32:41 +02:00
Daniel Marjamäki bd6f2c17fa Misra: Fix my code 2019-07-13 15:17:19 +02:00
Daniel Marjamäki f524bf79ad Misra: Added 17.2 checker 2019-07-13 15:10:07 +02:00
Daniel Marjamäki 29f5f59242 Revert "Revert "Add MISRA 18.4 check (#1966)""
This reverts commit 9b674fa306.
2019-07-09 15:57:12 +02:00
Georgy Komarov 4eb362352d Fixup MISRA 5.1 (#1969) 2019-07-09 15:53:23 +02:00
Daniel Marjamäki 9b674fa306 Revert "Add MISRA 18.4 check (#1966)"
This reverts commit 3ff7ef0918.
2019-07-08 08:10:25 +02:00
Georgy Komarov 3ff7ef0918 Add MISRA 18.4 check (#1966)
* Add MISRA 18.4 check

* Fixup

* Quickfix
2019-07-07 21:54:08 +02:00
Georgy Komarov f8c350fc70 misra.py: Add R18.7 check (#1934)
* misra.py: Add 18.7 check

* Simplify R18.7 check

* use token.link

* Remove isStruct method
2019-07-01 07:00:43 +02:00
Sebastian 2c71b47d4e
Addons scripts: Remove redundant code/characters, fix indentation. (#1926) 2019-06-27 06:59:47 +02:00
Georgy Komarov be5778c416 misra.py: Expand ~ in file paths (#1924) 2019-06-26 07:30:08 +02:00
Sebastian ba0ca5d087
addons/misra.py: Fix comparison instead of assignment (#1920) 2019-06-25 19:18:31 +02:00
Georgy Komarov 5d58b14db8 misra.py: Update output according c97dc79 (#1917) 2019-06-25 00:42:13 +02:00
Georgy Komarov 05bb4a0c8f misra.py: Fixup rules severity (#1911)
* misra.py: Fixup rules severity

* Divide cppcheck and MISRA severity.
2019-06-23 14:08:05 +02:00
Georgy Komarov 02cc9ffcd8 misra.py: Add --verify-rule-texts option. (#1909)
* misra.py: Add verify-rule-texts option.

* Capture stdout output in travis.
2019-06-19 21:57:27 +02:00
Georgy Komarov e979b0652c misra.py: Fix up and improve load rules parser. (#1895)
* misra.py: Fixup load rules parser.

* misra.py: Report when rule text is missing in rule-texts file

* misra.py: Allow to skip misra checks not specified in rule-texts.

* misra.py: Remove top-level control flow.

Create separate class that stores settings, instead of global variables.

This is required to perform imports from misra.py for testing purposes.

* misra.py: Add simple pytest test for load rules.

* misra.py: Add document structure tests.

* misra.py: Exit after show rules table.

* misra.py: Add document structure tests.

* misra.py: Fixup import pitfall with python2

* misra.py: Minor fixes
2019-06-17 21:17:29 +02:00
eivindt 44670005ea Record C/CPP/Posix Standard used for cppcheck in dump file / use this for misra checking (#1782)
* Add cmd parameter for choosing between C90 and C99

Misra specifies different requirements to the uniqueness of
macros/enums/variables depending on what C standard
that's being used.

* Add standards configuration to each dump file

Read standards config from misra addon to decide what rules to use.

* Posix as standard setting should be deprecated.  Don't include this in the xml

* Rewritten to use a switch
2019-06-14 12:06:57 +02:00
Daniel Marjamäki 784f2951fb misra: generating misra table 2019-06-01 15:57:19 +02:00
Daniel Marjamäki 7c6d15bb81 Fixed #8658 (false positive: MISRA rule 8.12) 2019-06-01 13:10:20 +02:00
Daniel Marjamäki f204ab88d6 misra feature matrix: I believe Cppcheck handle rule 14.3 2019-05-27 17:28:59 +02:00
Daniel Marjamäki d594b195d4 Misra feature matrix: Cppcheck has checks for 18.2 and 18.3 2019-05-26 20:45:21 +02:00
Daniel Marjamäki d039c388ec Fixed #8582 (Regression MISRA Rule 5.1) 2019-05-26 18:46:35 +02:00
Daniel Marjamäki 54be0bc3cf Misra: Added checker for misra rule 17.7 2019-05-22 21:39:33 +02:00
Mathias Schmid 149c07f475 Fix misra addon rule 4 1 (#1846)
* Modifiy check for MISRA rule 4.1 to avoid skipping constant character literal enclosed by single quotes.
Add test for MISRA rule 4.1 which contains non-compliant cases defined by MISRA C 2012 document.

* Moved additional test cases for MISRA rule 4.1 to appropriate test case section.
2019-05-22 14:33:59 +02:00
Daniel Marjamäki 48dfba429a Fixed #8822 (false positive: MISRA rule 13.4) 2019-04-27 17:43:26 +02:00
Daniel Marjamäki 146326bfaf misra.py: Rewrote rule texts parser 2019-04-16 10:57:31 +02:00
Daniel Marjamäki 7f19a9a255 addon/misra.py: fix problem with summary 2019-04-16 08:45:06 +02:00
Daniel Marjamäki 97157046f7 addons: /reportErrorCli/reportError/ 2019-04-14 08:54:53 +02:00
Daniel Marjamäki b1b5b27b4e addons: write column in error message(s) 2019-04-13 10:22:13 +02:00
Daniel Marjamäki 8bacfafd01 misra.py: Advisory=>style 2019-04-12 12:30:06 +02:00
Daniel Marjamäki 76e64dce8c misra: fix crash if Misra severity Required/Mandatory/Advisory is not set 2019-04-12 12:28:44 +02:00
Daniel Marjamäki a1c30b834c misra.py: Added rule 20.10 2019-04-11 10:50:07 +02:00
Daniel Marjamäki 3e3c805a66 misra.py: Add rule 20.7 2019-04-11 10:36:02 +02:00
Daniel Marjamäki cb55ccb9b0 misra.py: Fix dereference of None 2019-04-10 21:21:17 +02:00
eivindt ff1114e3c7 Misra explicitly allows spaces between # and the preprocessing tokens (#1781)
* Misra explicitly allows spaces between # and the preprocessing tokens

* Added tests illustrating need for changing preprocessor checking
2019-04-08 18:26:17 +02:00
eivindt 253986bc31 List the number of violations per rule (#1786)
* List the number of violations per rule

* Avoid using 'id' as variable name
2019-04-08 18:10:40 +02:00
Daniel Marjamäki bf9006737a Addons: Adding support in Cppcheck CLI to execute addons 2019-04-07 17:01:59 +02:00
eivindt 76bf5ecb06 Map MISRA violation categories to cppcheck categories (#1775) 2019-04-03 19:39:05 +02:00
eivindt 480284d428 Show number of hits per suppression rules entry (#1776) 2019-04-03 19:38:03 +02:00
Armin Müller f4b5b156d7 Typos found by running "codespell" (#1715) 2019-03-01 01:01:39 +01:00
Sebastian 72c9646be9
misra.py: Possible fix for problematic code (#1613)
Without the `for scope in data.scopes:` loop, scope is not assigned anything.
From the context a loop over `data.scopes` could be intended. But other things like indentation would be possibly correct too. Not sure how this code should be.
We try this fix.
2019-01-22 07:28:29 +01:00
Sebastian c106dd2939
misra addon: Fix issue with unexpected encodings in loadRuleTexts() (trac 8946) (#1608)
https://trac.cppcheck.net/ticket/8946
Add tests to travis script for verifying rule text loading.
Add dummy rule text files.
misra.py: Try to find a suitable codec for rule texts file.
2019-01-18 21:30:08 +01:00
practicalswift 0a1b3a9d6f Fix typos (#1568) 2019-01-06 17:15:57 +01:00
Armin Müller acf2035a53 Typos found by running "codespell" (#1461) 2018-11-03 07:34:27 +01:00
Richard A. Smith f286325cec Fix per file excludes (#1437)
* MISRA: Allow printing of the suppressed rules to the console

--show-suppressed-rules will print rules in the suppression rule list to
the console sorted by rule number.

* MISRA: Correct rule suppression for entire file scope

The entire file scope suppression check was checking for the rule item
list to be None instead of looking for None as an entry into the list.

Correct this check and modify the documentation to explicitly state that
an entry of None in the rule item list will set the scope for that
suppression to be the entire file.

* MISRA: Tests for checking per-file rule suppressions

To run:

../../cppcheck --suppressions-list=suppressions.txt --dump misra-suppressions*-test.c
python ../misra.py misra-suppressions*-test.c.dump

There should be no violations reported

* MISRA: Allow ignoring a prefix from file paths when suppression matching

For environments that run cppcheck from the build system cppcheck may be
passed a filename that is a complete path.

Often this path will include a portion that is specific to the developer
or to the environment where the project is located.

The per-file suppression rules do filename matching based on the
filename passed to cppcheck. To match any path information also has to
be included into the suppressions file provided to cppcheck via the
--suppressions-list= option.

This limits the usefulness of the per-file based suppressions because
it requires the suppression to be customized on a per instance basis.

Add a option "--file-prefix" that allows a prefix to be excluded from
the file path when doing the suppression filename matching.

Example.

Given the following structure:

/test/path1/misra-suppressions1-test.c
/test/path1/misra-suppressions2-test.c

specifying --file-prefix /test/path1 will allow the use of
misra-suppressions1-test.c and misra-suppressions2-test.c as filenames
in the suppressions file without leading patch information but still
match the suppression rule.

* MISRA: Tests for --file-prefix option

To run:

../../cppcheck --suppressions-list=suppressions.txt \
    --dump misra-suppressions*-test.c \
           path1/misra-suppressions*-test.c

python ../misra.py misra-suppressions*-test.c.dump \
                   path1/misra-suppressions*-test.c

There should be no violations reported
2018-10-18 09:17:57 +02:00
Richard A. Smith 4dbdc934b8 MISRA: Prevent exception on variadic functions (#1436)
Functions with variadic arguments trip an exception in the MISRA checker
because some of the token is None and does not have some of the members
the code is expecting.

Prevent this by checking to see if the token is None and skipping the
code that tries to use that value.
2018-10-18 09:11:51 +02:00
Daniel Marjamäki d9e1cc957b Fixed #8704 (false postive: MISRA rule 5.2) 2018-10-07 17:19:40 +02:00
Daniel Marjamäki 90a2a46959 Fixed #8657 (false postive: MISRA rule 15.7) 2018-10-01 20:16:48 +02:00
Richard A. Smith ecd2ba2ece MISRA: Support Per file excludes from cppcheck (#1393)
* MISRA: Refactor many top level functions into a class

All the checker operations were implemented as individual functions.  In
order to share data globals were used.

By refactoring all these into class methods data can be shared between
them without resorting to globals.

This change is scope only.  No functional change for any of the methods.
Data is still shared via globals.

* MISRA: Refactor non-option globals into MisraChecker class

- Move all non-option global variables into the MisraChecker class

- Allows data to be shared among the class methods without needing
  globals.

- Move global VERIFY_EXPECTED to class variable verify_expected
- Move global VERIFY_ACTUAL to class variable verify_actual
- Move global VIOLATIONS to class variable violations
- Move global suppressRules to class variable suppressedRules
- Move global suppressions to class variable dumpfileSuppressions

This refactoring is in anticipation of parsing and using the
suppressions added into the dump file by cppcheck.

Only variable naming and scope changed.  No functional change for any of the
methods.

* MISRA: Restore original summary behavior

Version 1.84 introduced a regression in the behavior of the rule summary
output due to changes in the way multiple input files were handled.

The intended behavior of the summary was to output the total number of
violations after all files have been processed.

Commit aa831ce972 restored the input file
handling behavior but left summary behavior such that a summary output
was produced for each file that caused a violation instead of the total
number of violations after all files were processed.

Move the -verify logic up into the main loop so that the exit calls are
in the top level and restore the original behavior of the summary
output.

* MISRA: Support per file rule suppressions

Parse the suppressions list from cppcheck and extract MISRA rule strings from
the suppressions class by matching for errorId strings that begin with
'MISRA' or 'misra'.  Extract the MISRA rule from those strings by
looking for a '_' or a '.' to separate rule numbers.

Store the rule number, filename, line number, and symbol name from the
suppression entry into a structure that allows for dictionary lookups
by the rule number and then the filename.  All the line number
and symbol entries for that filename are are stored in list of tuples of
(line number, symbol name).  A rule entry that has a value of None for
the filename is treated as a global suppression for all files.  A
filename entry that has None for the rule items list is treated as a
suppression for the entire file. If the rule item list exist then it is
searched for matching line numbers.

Although symbol names are parsed and added int the list of rule items
they are not used for rule matching.  Symbol names can include regular
expressions.  Adding support for symbol names and regular expressions is
left as a future feature.

The existing global suppression method provided by the --suppress-rules
option is supported.  Those rules are added into the suppressions
structure as if they were provided by the suppressions list as global
suppressions. ie A rule with a None for the filename value.
2018-09-29 09:05:13 +02:00
Daniel Marjamäki 18eff25c98 misra: fix fp for rule 3.1 2018-09-08 17:23:24 +02:00
Daniel Marjamäki 8d88f75f03 Fixed #8567 (False positive: MISRA RULE 20.3) 2018-09-02 16:31:27 +02:00
Daniel Marjamäki 8f9fa2e6a7 Fixed #8562 (false positive: MISRA rule 20.13) 2018-09-02 16:05:37 +02:00