Commit Graph

378 Commits

Author SHA1 Message Date
Georgy Komarov b9bc5d6d78 cert.py: Add ENV33-C (#2377) 2019-11-21 06:46:46 +01:00
Sebastian c990d10ffa
Check for JSON error when parsing addon .json files + fixes (#2374)
* cppcheck.cpp: Check for JSON error when parsing addon .json files

This fixes that errors in JSON files given via `--addon=*.json` are
silently ignored and maybe only a part of the JSON file is used.
Now the error message which picojson can return is checked and a
corresponding error message is returned again by getAddonInfo().

* naming.json: Fix missing comma

* CLI: Fix naming violations detected by addon naming.py via naming.json

* Addon naming: Add argument for validating names of constants

* LIB: Rename functions/variables so they are valid, loosen naming rules

* GUI: Fix naming violations
2019-11-20 15:37:09 +01:00
Sebastian 4f1db90367
naming.py: Fix FP for constructors/destructors (#2375) 2019-11-18 18:41:57 +01:00
versat 0dd180d5a2 misra-test.cpp: Remove redundant unused function argument
The unused argument causes the new check for rule 2.7 to output an error
here.
I verified that the regression test still works without the unused
argument (misra.py would still crash).
Travis should be happy again.
2019-11-18 15:57:53 +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
Georgy Komarov da163ae0e8 misra.py: Add regression test for R21.1 crash (#2356) 2019-11-13 20:36:31 +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 4398cf0dec
addons/namingng.py: Fix some PEP 8 and Inspections warnings (#2351) 2019-11-12 09:47:48 +01:00
Sebastian bd5d82c9bd
cppcheckdata.py: Fix PEP 8 and Inspection warnings (#2350) 2019-11-12 09:30:43 +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
Sebastian 0a38b1b511 pylintrc_travis: Enable more messages and fix issues (#2332)
The plan is to enable more and more useful messages and fix the issues
step by step to improve the code quality.
2019-11-05 21:05:43 +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
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