Commit Graph

428 Commits

Author SHA1 Message Date
Daniel Marjamäki 33388217a5 new default branch is main 2020-06-15 20:04:57 +02: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
Ken-Patrick Lehrmann a96a879b6d
Fix crash in addons/test/test-misra.py (#2652) 2020-05-20 16:02:13 +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
Daniel Marjamäki 75a369d217 cppcheckdata: Set Function.nestedIn attribute 2020-04-16 12:25:03 +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
fuzzelhjb 9267182d8c
False positive fix (#2593)
* only report cert-STR07-C for C11

* fix false positive for checking c89/c99 code with cert-STR07-C
2020-04-07 07:29:49 +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 88a3b4c685 addons: Fix __repr__ methods (#2448)
This commit fixes __repr__ methods introduced in d538315268. Fields that recursively links to other cppcheckdata objects was removed to avoid max recursion depth crash on printing.
2019-12-15 19:46:54 +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 40aefa1ba4 [windows] cannot run test-misra (binary not found) (#2441)
set PYTHONPATH=addons
    python -m pytest addons/test/test-misra.py
2019-12-10 18:32: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
Sebastian fb96e5433a
y2038 addon: Fix that check can never return True, add tests (#2417)
* y2038 addon: Fix that check can never return True, add tests

At the beginning of `check_y2038_safe()` the variable `y2038safe` should
be initialized with `True` and only be set to `False` if there are any
issues. Otherwise it could never become `True`.
In the unit tests the return value of `check_y2038_safe()` is now
verified. But it does not yet work for the "good" example. The "good"
example also returns `False` since it finds warnings in the include
file. So this verification is marked with a "FIXME" comment.

* y2038 tests: Add "good" test file that does not use time functionality

The test file y2038-test-5-good-no-time-used.c does not use any time
functionality so the y2038 addon is not allowed to issue any warnings
and the check must return with `True` (code is safe).
2019-12-03 18:49:11 +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
Sebastian 8d114a40e4
misra-test.c: Add more tests for rule 14.2 (including FP and FN) (#2399)
Adding more tests for rule 14.2 revealed a false negative when the
loop counter is changed inside the loop.
Corresponding line in the example suite:
https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/blob/master/R_14_02.c#L39
Also a false positive has been revealed when the loop counter is
initialized in a function that is called in the first `for` clause.
Corresponding line in the example suite:
https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/blob/master/R_14_02.c#L43
2019-11-30 11:27:31 +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
Sebastian e46191e6e8
misra-test.c: Add more tests for rule 10.1 (including FP and FN) (#2398)
Add some more tests for rule 10.1. They are given as examples in the
MISRA document. The 10.1 test that causes a false positive for 10.6 can be
found under the 10.6 tests.
Track ticket for false positive:
https://trac.cppcheck.net/ticket/9488
Trac ticket for the false negative:
https://trac.cppcheck.net/ticket/9489
2019-11-27 09:09:17 +01:00
Georgy Komarov 2c28440f15 cert.py: Add ENV33-C-EX1 exception (#2396)
* cert.py: Add ENV33-C-EX1 exception

ENV33-C-EX1: It is permissible to call system() with a null pointer
argument to determine the presence of a command processor for the
system. [1]

[1]: https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152177

* Handle different null-pointer constants
2019-11-24 10:31:08 +01:00
Georgy Komarov 14469aced8 cert.py: Fix EXP05C crash (#2392)
* cert.py: Fix EXP05 crash

* Fix arguments check
2019-11-23 17:41:47 +01:00