Commit Graph

407 Commits

Author SHA1 Message Date
Armin Müller bdd41151ed Typos found by running "codespell" (#2314) 2019-10-31 15:03:18 +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
Georgy Komarov d1fce6b7ad addons: fixup image in README (#2277) 2019-10-17 07:08:10 +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
Sebastian 3b3ff2bb62
misra-test.c: Rule 4.1: Add another compliant test example (#2212) 2019-09-24 20:05:57 +02:00
versat dc1cdd2b76 addons/test/test-*.py: Improve documentation about running the tests 2019-09-20 13:39:38 +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
IOBYTE e5220bdf0c make ellipsis ... a single token (#2143)
* make ellipsis ... a single token

Using cppcheck -E to preprocess code with ellipsis produces output that
can't be compiled because ... is split into 3 tokens.

* try to fix addon
2019-09-04 08:07:30 +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 f33a8a417f Put 'isExpandedMacro' info in the dump files 2019-08-15 14:24:56 +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
Armin Müller 785cc69644 Typos found by running "codespell" (#2072) 2019-08-08 21:05:28 +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 e88e024509 Addons: Add README (#2047)
* Addons: Add README

* fix
2019-07-28 07:51:03 +02:00
Georgy Komarov fe2885e430 cert.py: Refactor arguments handling (#2044)
* cert.py: Add '--quiet' option and test

Main sentinel also was required.

* travis.yml: Install pytest with --user

To avoid possible conflicts with system packages later.

* Quickfix
2019-07-26 15:40:25 +02:00
Georgy Komarov fbd7b5180b Update addons structure. Make Y2038 addon works. (#2024)
* Update addons structure. Make Y2038 addon works.

All addons are now located in same directory, where cppcheck-gui is
looking for them.

Y2038 addon has been updated to latest cppcheck version. Output is same
as 303622f01c commit as it described in
README: 303622f01c/addons/y2038/README.

* Clean up .travis.yml

* Update travis.yml paths.

* misra.py: Bring back -P argument for backward compatibility

* Fix paths

* Normalize dumpfile paths tpo cppcheck format

* Fixup 3 test.

* Add arguments regression test.

* Fixing travis build
2019-07-26 06:38:03 +02:00
Sebastian 8f92c43567
.travis.yml: Check more Python scripts with pylint (#2019)
Use renamed pylintrc file that is only meant for Travis checks.

Check all Python scripts in 'addons', 'htmlreport' and 'tools'

Errors for `_socketobject` class are disabled, see
https://stackoverflow.com/questions/10300082/how-to-prevent-python-pylint-complaining-about-socket-class-sendall-method

Install imported modules `unittest2` and `pexpect` via pip.

Add "./addons" to search-path for modules because
"tools/compare-ast-clang-and-cppcheck.py" imports cppcheckdata.py from
addons. Pylint does not seem to evaluate
`sys.path.insert(0, '../addons')` in the script. So an `init-hook` is
necessary in pylintrc_travis.
2019-07-24 21:09:53 +02:00
fuzzelhjb cc63728d6a add support for CERT-API01-C check (#1980)
* add support for CERT-API01-C check

* remove extra ident and simplify check
2019-07-24 10:39:31 +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
amai2012 453de18101
Run pylint on addons providing a buld breaker on travis (#2011)
* Run pylint (using a pylintrc file) on the addon Python scripts. It serves as a build breaker for severe issues.
* Skip y2038 addon for now until it's fixed.
2019-07-18 20:51:58 +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
fuzzelhjb 999aa407f4 add CERT MSC24-C check (#1903)
* add CERT MSC24-C check

* make check a bit more robust

* fix cert tester

* finetune MSC24 check
2019-07-04 12:19:52 +02:00
fuzzelhjb 1887bd3cf0 add CERT STR11-C check (#1902)
* add CERT STR11-C check

* fix some logical checks

* fix merge issue

* update str11 check
2019-07-02 11:44:24 +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
fuzzelhjb 9a7ecd622c add CERT exp15-c check (#1897)
* add CERT exp15-c check

* fix false positive

* remove useless check

* fine tune check and test
2019-06-26 18:49: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
Sebastian d1386112a9
addons/cppcheckdata.py: Fix missing self, and wrong assignment. (#1919)
I am not sure but it looks like "self." is missing here.
And the attribute "inconclusive" is initialized as a "bool", so i guess
"True" should be assigned here?
2019-06-25 19:16:57 +02:00
Georgy Komarov 5d58b14db8 misra.py: Update output according c97dc79 (#1917) 2019-06-25 00:42:13 +02:00
Daniel Marjamäki c97dc79815 --addon: Use json for addon output 2019-06-24 19:29:43 +02:00
fuzzelhjb f36d671bc5 add CERT STR03-C check (#1898)
* add CERT STR03-C check

* fix cert test
2019-06-24 18:41:43 +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
Daniel Marjamäki bd59999fd0 cert.py: Use cppcheck.getArguments instead of local implementation 2019-06-23 14:05:24 +02:00
fuzzelhjb 8fcfe0ceb0 add CERT STR07-C check 2019-06-23 13:59:24 +02:00
Daniel Marjamäki 63bd29d644 addons/cppcheckdata.py: Add 'cppcheckdata.getArguments' function 2019-06-23 13:54:33 +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
fuzzelhjb 5e3da9e82a add CERT STR05-C check (#1899)
* add CERT STR05-C check

* update check
2019-06-17 20:42:23 +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 1584e62367 cppcheckdata: Added 'simpleMatch' function 2019-06-06 15:38:15 +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 e0da316759 cppcheckdata.py: fix sys.errout 2019-04-16 08:26:58 +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
Daniel Marjamäki b5d9313663 naming.py: Unify addon output 2019-04-10 21:11:50 +02:00
Daniel Marjamäki 7b6d7b9335 threadsafety.py: allow execution with --addon 2019-04-10 21:06:40 +02:00
Daniel Marjamäki 05fcfc85fa findcasts: Unify output 2019-04-10 18:29:46 +02:00
Daniel Marjamäki bf5ad56dba cert.py: Removed CLI 2019-04-10 18:09:27 +02:00
Daniel Marjamäki 466caabbf2 Fixed misc.py test 2019-04-10 07:31:52 +02:00
Daniel Marjamäki 4509b25f97 replace tabs with spaces in cppcheckdata.py 2019-04-10 06:48:16 +02:00
Daniel Marjamäki 4415992a62 Addons: Remove the xml output. You can get xml output from the GUI/command line clients. 2019-04-09 20:42:17 +02:00
Daniel Marjamäki f2889d5c82 Try to unify addon output 2019-04-09 20:36:24 +02:00
Daniel Marjamäki 44dcbda88e Addons: Fixed handling of addon configuration 2019-04-08 19:42:16 +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 d2949adff1 misc.py: Make it possible to run this addon from cppcheck 2019-04-07 21:07:08 +02:00
Daniel Marjamäki bf9006737a Addons: Adding support in Cppcheck CLI to execute addons 2019-04-07 17:01:59 +02:00
eivindt 0debd8d520 Misra xml output (#1787)
* Add (very) simple XML output support

* Removed xml top and tail, better handled outside
2019-04-05 12:36:58 +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
Sebastian 4735b6ca1b
addons/naming.py: Fix crash on unnamed arguments, add regex validation. (#1762)
Crash has been reported in the forum:
https://sourceforge.net/p/cppcheck/discussion/development/thread/138788ac6b/
A small test has been added to avoid regression.
2019-03-26 18:54:09 +01:00
versat 68dd203f43 addons/namingng.py: Fixed typos, no functional changes intended. 2019-03-26 15:21:49 +01: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
Servando 7c168fa850 Feature/ros naming check (#1511)
* Added script to check ROS naming style

* Added header to script

* Enhanced namingng.py and added ROS_naming.json

* Correction of style bugs

* Removed trailing whitespace

* Removed trailing whitespace

* Removed path

* Remove path from file name

* Check if the token belongs to the current file or is included

* Reverted

* Fixed msg errors
2019-01-09 18:16:51 +01:00
practicalswift 0a1b3a9d6f Fix typos (#1568) 2019-01-06 17:15:57 +01:00
Thorsten Sick 43b6a391d8 Added a new naming check addon. Also verifies variable and function p… (#1456)
* Added a new naming check addon. Also verifies variable and function prefixes

* Verification added to code

* added naming checks ng selftest to travis file

* Ensure zero exit value for tests if tests succeed

* Expected values adjusted

* Fixed copy and paste error
2018-11-06 20:46:07 +01:00