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.
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
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.
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.
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.
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.
* 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
* 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
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
* 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
* 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
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
* 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.
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.
* 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
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.
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
* 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
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
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.
* 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
* 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
* 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
* 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.
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.
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.
* 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
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.