Commit Graph

208 Commits

Author SHA1 Message Date
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
Kyle Chisholm 4e25da7b9d Misra.py fix multiple file processing (#1332)
* MISRA addon: Support multiple files with argparse

* MISRA addon fix exit code 

Fix to run all dump files then exit with error code if any error in any file found.
2018-08-09 08:51:00 +02:00
Oliver Stöneberg bb27bc280a more small *.py cleanups (#1329)
* added CLion project folder to .gitignore

* adjusted project name in CMakeLists.txt

* avoid warning when compiling "Debug" with Visual Studio via CMake

There was a GCC-style compiler flag in the common flags in compileroptions.cmake which caused the following warning:
cl : Command line warning D9002 : ignoring unknown option '-O0'

* compileroptions.cmake: restored original formatting

* daca2.py: added missing import

* misra.py: removed unnecessary escaping from regular expression
2018-08-06 22:07:58 +02:00
Oliver Stöneberg 13cf982b77 some small *.py script cleanup (#1328)
* added CLion project folder to .gitignore

* adjusted project name in CMakeLists.txt

* avoid warning when compiling "Debug" with Visual Studio via CMake

There was a GCC-style compiler flag in the common flags in compileroptions.cmake which caused the following warning:
cl : Command line warning D9002 : ignoring unknown option '-O0'

* compileroptions.cmake: restored original formatting

* some small *.py script cleanups
2018-08-05 20:36:21 +02:00
Kyle Chisholm aa831ce972 MISRA addon: Support multiple files with argparse (#1327) 2018-08-04 21:37:08 +02:00
Konrad Grochowski 3702c477c0 misra.py - rule 8.12 fixed for enums depending on other enums values (#1287) 2018-06-13 06:54:30 +02:00
Konrad Grochowski 8925a0fd81 misra.py - Rule 11.8 fixed in function arguments checks (#1288) 2018-06-13 06:51:24 +02:00
Konrad Grochowski 8290d84472 MISRA 10.4 - fixed ?: operator (#1281)
x ? a : b - only a and b has to be checked
2018-06-09 08:23:41 +02:00
Konrad Grochowski 06f19fb3a7 misra.py: template used for error reporting will now be configurable (#1279)
WARNING: breaking change - now default misra.py report style will be the
same as cppcheck itself, but previosly misra.py default template was a
little different
2018-06-06 14:53:09 +02:00
orbitcowboy 79f70cbb32 misra.py: restored previous output style. The output style was broken by 0c6d60d202. 2018-06-05 14:16:25 +02:00
Konrad Grochowski 0c6d60d202 MISRA - support for per file/line error suppression (#1275)
* cppcheckdata.py: fixed Suppression.isMatch method

* cppcheckdata.py: fixed parsing <suppressions> tag

* misra.py: now uses cppcheckdata.reportError and supports suppressions
2018-06-04 21:50:21 +02:00
Swasti Shrivastava bdb372f929 Modified rule 14.1 (#1267)
* Modified rule 14.1

* Made suggested changes

* Added findCounterTokens

* Removed hasFloatComparison

* Improved isFloatCounterInWhileLoop

* Made all required minor changes
2018-06-04 10:12:51 +02:00
Konrad Grochowski e1014253ef MISRA Rule 11.6 will no longer report violation on '(void)p;' (#1272) 2018-05-30 12:44:20 +02:00
Konrad Grochowski d46baad462 misra.py: support for and C99 keywords in isBoolExpression (#1268) 2018-05-29 06:50:32 +02:00
Swasti Shrivastava a3b9745557 Modified Rule 10.8 (#1265)
* Modified Rule 10.8

* Made suggested changes to handle unary operators
2018-05-28 12:58:19 +02:00