Commit Graph

10086 Commits

Author SHA1 Message Date
IOBYTE 9b67e680ae Fix template simplifier namespace support. (#1464) 2018-11-05 19:55:21 +01:00
Daniel Marjamäki ca19894a04 ValueFlow: In evaluate handle correlated values 2018-11-05 18:07:35 +01:00
Daniel Marjamäki da44ce0b5d ValueFlow: evaluate strlen and char literals better 2018-11-05 16:52:12 +01:00
Daniel Marjamäki 307a19d17e Refactoring: Use range for loop 2018-11-05 09:49:28 +01:00
IOBYTE 2275f05f65 Fixed #8833 (false negative: No 'return' statement in non-void function causes undefined behavior.) (#1463) 2018-11-05 06:55:30 +01:00
Daniel Marjamäki 977fdd88a9 ValueFlow: Fix a few issues in 'evaluate' 2018-11-05 06:53:48 +01:00
Daniel Marjamäki 8a54420274 ValueFlow: Try to handle multiple argument values in <returnValue> evaluation 2018-11-04 20:52:12 +01:00
Daniel Marjamäki dd9a1e890b valueFlowRightShift: Do not perform analysis when rhs is negative 2018-11-04 17:13:23 +01:00
Daniel Marjamäki efd92fd714 Refactoring: reuse utility function in SymbolDatabase 2018-11-04 13:29:29 +01:00
Daniel Marjamäki 6878de2c5e ValueFlow: getExpressionRange, valueFlowRightShift 2018-11-03 23:25:46 +01:00
Daniel Marjamäki 8a05be34f8 Fix Cppcheck shadow variable warning 2018-11-03 19:41:25 +01:00
Daniel Marjamäki f8b0584f6a replace 'constexpr' with 'const' 2018-11-03 19:22:51 +01:00
Daniel Marjamäki fb76ef1db1 Fixed testrunner 2018-11-03 18:59:55 +01:00
Daniel Marjamäki 66ca03fa0c Fixed #8826 (false negative: Invalid memory address freed) 2018-11-03 18:55:20 +01:00
Daniel Marjamäki ef35b86b4a Multipass Valueflow 2018-11-03 15:53:24 +01:00
Daniel Marjamäki 6138294e3d Fixed #8818 (AST broken: restrict) 2018-11-03 11:05:38 +01:00
Daniel Marjamäki 9741239b2f Fixed #8824 (False positive: uninitialized variable (regression)) 2018-11-03 10:31:55 +01:00
Armin Müller acf2035a53 Typos found by running "codespell" (#1461) 2018-11-03 07:34:27 +01:00
Daniel Marjamäki a4afcb5995 Revert "Fixed #8818 (AST broken: restrict)"
This reverts commit e7d61f399a.
2018-11-02 21:07:37 +01:00
Daniel Marjamäki 0cc4555337 Revert "Tokenizer: Do not remove 'constexpr'"
This reverts commit 2f400b40ba.
2018-11-02 21:07:24 +01:00
Daniel Marjamäki 2f400b40ba Tokenizer: Do not remove 'constexpr' 2018-11-02 20:32:12 +01:00
Daniel Marjamäki e7d61f399a Fixed #8818 (AST broken: restrict) 2018-11-02 20:28:49 +01:00
Daniel Marjamäki 614a252704 Fix Match warning 2018-11-02 20:14:34 +01:00
Daniel Marjamäki 5de683ec49 Container size: Fix false positive 2018-11-02 20:10:40 +01:00
Daniel Marjamäki 16cc20a232 ValueFlow: Better handling of container size values 2018-11-02 18:28:32 +01:00
Daniel Marjamäki 3798feecad TemplateSimplifier : Remove 'class|struct' in template arguments 2018-11-02 14:49:40 +01:00
rikardfalkeborn 869e4ba6ab Add check for return value of boolean function (#1451)
* Add check for return value of boolean function

The rule for converting an integer to a boolean is that 0 is mapped to
false and everything else is mapped to true. There is nothing wrong with
the following code (according to the standards):

    bool f()
    {
        return -1;
    }

and neither gcc nor clang will warn about it. However, it's a bit
confusing. This commit adds a check that warns when a value other than 0
or 1 is returned from a boolean function (similar to the existing check
that functions with boolean arguments are only passed 0 or 1). Since the
code is perfectly legal, set the severity to "Style".

* Use early continue and remove some braces

* Add testcase with multiple returns

* Avoid null pointer dereference in case of return without operand

* Skip lambdas

Add TODO-test cases that shows FPs when the return type of lambdas are
specified explicitly (this is a problem with findLambdaEndToken).

* Enable testcases
2018-11-01 11:08:16 +01:00
rikardfalkeborn 88008fedb1 findLambdaEndToken handle explicit type (#1458)
* findLambdaEndToken: Add tests

* Add handling of explicit return in findLambdaEndToken()

* Use AST in findLambdaEndToken()

* Fix ast when lambda is mutable
2018-10-31 12:36:08 +01:00
Paul Fultz II fafd0742d4 Fix FPs with return conditions (#1455)
* Fix 8815: FP with identical inner conditions

* Fix issue 8801: FP when not returning a bool

* Fix FP

* Add missing semicolon

* Move returnVar
2018-10-31 09:47:48 +01:00
Daniel Marjamäki c03d32b429 ValueFlow: Improve containerSize handling of string like classes 2018-10-28 19:14:00 +01:00
Daniel Marjamäki 8beb42cc90 astyle formatting
[ci skip]
2018-10-28 17:37:19 +01:00
Paul Fultz II 2b6cc33dc6 Fix issue 8757: Throw syntax error on invalid code (#1378)
* Fix issue 8757: Throw syntax error on invalid code

* Fix FP with lambda returns

* Remove double percent

* Check more keywords

* Skip preprocessor directives

* Check for valid PP directive

* Fix preprocessor check

* Dont check for preprocessor directives
2018-10-28 17:17:53 +01:00
Paul Fultz II f5811c6818 Fix issue 8732: Syntax error when using enable_if (#1453)
* Fix issue 8732: Syntax error when using enable_if

* Fix FPs

* Use simpleMatch
2018-10-28 17:16:31 +01:00
Daniel Marjamäki 06ede9c239 ValueFlow: handle x+=y for containers 2018-10-27 18:38:04 +02:00
IOBYTE adbbadec7f Fixed #8798 (template simplifier: wrong simpifications for namespaces) (#1452) 2018-10-26 14:20:13 +02:00
Kamil Dudka d206047b84 Fixed #8794 - Memory leak false positive triggered by !(x != NULL) (#1450) 2018-10-26 06:21:45 +02:00
Daniel Marjamäki 86782af43c Fix Cppcheck warning 2018-10-25 07:15:32 +02:00
Daniel Marjamäki 044c4b7fbb Refactoring: Use range for loop 2018-10-25 06:14:27 +02:00
Daniel Marjamäki b8e8b12783 Fixed #8797 (exprDependsOnThis handle method call in non-inline method) 2018-10-24 20:17:00 +02:00
Daniel Marjamäki 2348dcde6c #8801: Quick fix for false positives 2018-10-24 19:57:50 +02:00
IOBYTE ea4e6a60f7 Fix template simplifier from deleting the same declaration multiple times (#1449)
Found by running valgrind on testrunner. May fix #8808.
2018-10-24 19:32:37 +02:00
IOBYTE 0763fdbfad Copy template default argument values from forward declaration to declaration. (#1447)
It is possible to define default template parameter values in forward
declarations and not define any in the actual declaration.  Cppcheck
ignores forward declarations and only uses the default values in the
actual declaration so default values in forward declarations are copied
to the actual declaration when necessary.
2018-10-24 14:38:59 +02:00
Daniel Marjamäki be1ff268c0 Refactoring: Use range for loops 2018-10-24 11:29:15 +02:00
Daniel Marjamäki 2e4f317c0b Revert "Remove FIXME"
This reverts commit 749699c632.
2018-10-22 21:03:30 +02:00
Daniel Marjamäki 15160f1691 Fixed #8788 (AST Broken error from assigning lambda to variable) 2018-10-22 17:25:01 +02:00
Daniel Marjamäki 749699c632 Remove FIXME 2018-10-22 12:45:34 +02:00
Daniel Marjamäki dc38681a56 Remove FIXME in AST validation. Ticket #8749 2018-10-22 11:37:24 +02:00
Daniel Marjamäki c483bcb12b Fixed testrunner 2018-10-22 00:28:09 +02:00
Daniel Marjamäki f9b132e831 Tokenizer::simplifyTypedef: Fix bug with arrays 2018-10-21 21:15:34 +02:00
Daniel Marjamäki 64fbffc90d astyle formatting
[ci skip]
2018-10-21 20:28:46 +02:00
Paul Fultz II edde0eedaa Fix FP issue 8801: Condition 'a+b' is always true (#1444) 2018-10-21 08:04:00 +02:00
Paul Fultz II 2989c44f59 Enable checking duplicate expressions across associative operators (#1445)
* Enable checking duplicate expressions across associative operators

* Remove bitshift operators and check for streamRead
2018-10-21 07:09:20 +02:00
Daniel Marjamäki 14afc3fd3a Fixed #8796 (Tokenizer::simplifyCompoundAssignment: Wrong simplification of return) 2018-10-20 21:33:43 +02:00
Daniel Marjamäki 277e0f1a8f Fix Cppcheck error message 2018-10-20 15:28:34 +02:00
Daniel Marjamäki 29feaa5a51 Tokenizer: Avoid constant folding 2018-10-20 10:51:50 +02:00
Daniel Marjamäki d265a0d6ab Fixed #8798 (SymbolDatabase: Inner unnamed union) 2018-10-20 09:43:08 +02:00
Daniel Marjamäki e2ea8bc2b0 astyle formatting
[ci skip]
2018-10-20 09:28:28 +02:00
orbitcowboy 0858488825
insecureCmdLineArgs: Fixed FN in case strdup() copies argv[]. (#1438)
* insecureCmdLineArgs: Fixed FN in case strdup() copies argv[].

* Formatted the code. There are no functional changes intended.

* Changes due to review comments from Daniel.
2018-10-19 11:04:15 +02:00
rikardfalkeborn 402d0c565f Fix false positive: Invalid string argument with array (#1439) 2018-10-19 07:48:47 +02:00
Paul Fultz II 40cb9cb1bc Check conditions in return statements (#1411)
* Identify return conditions in multiconditions

* Improve error messages

* Check return statements are always true or false

* Add more tests for FPs

* Fix FP when returning const like variables

* Fix FP when returning pointers or classes

* Fix FP with member variable access

* Check non-local variables

* Use simplematch

* Check for null
2018-10-18 21:01:47 +02:00
Daniel Marjamäki 465db2dff7 Fixed #8786 (internalAstError on valid code with C style cast) 2018-10-18 20:17:23 +02:00
Daniel Marjamäki 4983a6a5dc astyle formatting 2018-10-18 20:08:32 +02:00
Daniel Marjamäki 58b21e3071 Refactoring: Reuse Token::expressionString() logic for finding right-most leaf in tree 2018-10-18 12:09:55 +02:00
Paul Fultz II 16c62281d0 Use followVar in checking duplicateBranch (#1423)
* Use isSameExpression for duplicate branches

* Add errorPath

* Add another test
2018-10-18 11:56:23 +02:00
Paul Fultz II 58d1de5814 Expand the duplicate variable assignment warnings when the inconclusive flag is used (#1433)
* Warn for more duplicate var expressions when inconclusive is set

* Fix issue with missing function name
2018-10-17 06:57:33 +02:00
Igor 0a9be3e734 Improve STL iterators checking (#1380)
* Improve STL interators checking

* Improve error messages for container iterators from different scopes

* Mini refactoring

* Replace hardcoded pattern to ValueType::Type::ITERATOR

* Error messages improvements, more tests and refactoring

* Refactoring after code review

* Put getting operand data into separate function

* Update getErrorMessages and iterator errors ids

* Refactoring

* Fix error

* Refactoring, early return implementation

* Delete redundant code

* Tiny changes in comments
2018-10-17 06:36:51 +02:00
Daniel Marjamäki 1245a036f7 Add check for shadow variables 2018-10-16 20:17:27 +02:00
rikardfalkeborn f1074ea1ab Fix false positive: Invalid string argument with pointer to pointer (#1427)
If the address is taken inside an array, the address is not of a single
character, so do not warn about this.
2018-10-16 06:54:25 +02:00
IOBYTE 290563b964 Fix specialized template regression. (#1425)
* Fix specialized template regression.

Only check for instantiation of template being processed rather than
count of all instantiations.

* Add 2 more tests.
2018-10-15 19:35:26 +02:00
orbitcowboy a6e8270474
insecureCmdLineArgs: Fixed false negatives in case arguments are const. (#1419)
* insecureCmdLineArgs: Fixed false negatives in case arguments are const.

* Formatted the code, there are functional changes.

* Simplified matching as suggested by Daniel.
2018-10-15 10:05:43 +02:00
rikardfalkeborn 613dc19b68 #4241: Check for address of single character passed as string (#1381)
* #4241: Check for address of single character passed as string

Add a check that address of a single character is not passed as argument
to argument marked as strings (using strz). The check does not warn if
the address of a character with known value '\0'.

Since ValueFlow currently does not handle global constants (see #7597),
do not warn if the variable is global to avoid FPs when the address of
a global variable assigned to '\0' is passed to a function expecting a
string.

Remove comment in docs saying strz is unused.

* Change asdf to Hello world

* Add test of address to first element in string

* Add error reporting function to getErrorMessages

* Fix strings in test
2018-10-14 18:49:34 +02:00
IOBYTE 0a30768b59 Fixed #8693 (Template specialization: Constructor detected as normal … (#1418)
* Fixed #8693 (Template specialization: Constructor detected as normal function (functionStatic error))

Refactor template simplifier to remove the existing full specialization
function expandSpecialized and allow full specializations to use the
existing function expandTemplate.  The function expandTemplate was
modified to either expand the template like it originally did by copying
it or to modify the template in place.  Both instantiated and
uninstantiated full specializations are modified in place.  This also
fixes #8692 and probably other related tickets as well.

The function simplifyTemplates now tries twice to simplify templates so
more templates can be simplified.  We should try as many times as
necessary to find all possible templates.  We can't do that now because
uninstantiated templates are left unchanged.  It is relatively straight
forward to have the new code also expand in place uninstantiated
templates with their symbolic types but namespaces are not handled
properly (ticket #8671) and it would introduce regressions.

* Fix travis warnings.
2018-10-14 16:57:07 +02:00
Daniel Marjamäki 895772711a 1.85: Set version 2018-10-13 18:55:19 +02:00
Paul Fultz II 9cf092657c Skip some ast errors to avoid regressions (#1422)
* Skip some ast errors to avoid regressions

* Use simpleMatch

* Skip operator functions

* Add a test for issue 8788
2018-10-13 18:38:44 +02:00
Daniel Marjamäki 7833ade128 Updated copyright year 2018-10-13 18:20:31 +02:00
Daniel Marjamäki 936c627307 Fix --doc output. * must be escaped. 2018-10-11 13:59:21 +02:00
Daniel Marjamäki 7eb5ebe17e Fixed #7887 (User function 'search' is wrongly mixed with std function) 2018-10-10 17:35:53 +02:00
Daniel Marjamäki 25cbfe27cf Partial fix for #7887, Improved tokenizer simplification of 'using namespace std;' - do not simplify user functions 2018-10-10 14:28:53 +02:00
Daniel Marjamäki 053b0d1654 STL: enable inconclusive warnings with --inconclusive 2018-10-09 20:10:43 +02:00
alex babafd75e3 Added support for -U option to the GUI. 2018-10-09 15:05:05 +02:00
rikardfalkeborn 75caf8e4de Fix #8230: FP unknown evaluation order on comma expression in while clause (#1415)
The while part of a do-while loop looks almost like a function call, so
extend the check for function calls to ignore while-statements.

Note that there was only an FP when checking c-code, since the check is
disabled for c++-code. Therefore, make sure the test cases are run on a
c-file.
2018-10-09 14:44:01 +02:00
Daniel Marjamäki 20121b34d8 Fixed #7718 (False positive: out of bounds of already resized std::string) 2018-10-09 06:53:26 +02:00
Daniel Marjamäki aa58f41e6d Fixed #7152 (False positive for redundantAssignment after calling a lambda function) 2018-10-08 21:07:21 +02:00
PKEuS 86a1b84b0c Fixed handling of macros with known value defined in header file in configuration splitting (#8404)
Added proper unit test for configuration validation to ensure that it actually works when cppcheck is executed
2018-10-08 16:38:47 +02:00
orbitcowboy c312bbad78 Fixed a typo. There are no functional changes intended. 2018-10-08 13:58:21 +02:00
Daniel Marjamäki c3e6e7c338 Fixed #8664 (setVarId: Wrongly set varid for lambda argument) 2018-10-07 20:40:59 +02:00
Daniel Marjamäki f961324d45 Fixed #8735 (FP oppositeInnerCondition - regression) 2018-10-07 18:30:29 +02:00
Carlo Marcelo Arenas Belon d66c92edc3 Remove unused parameters for CheckOther::oppositeExpressionError (#1412) 2018-10-05 08:36:49 +02:00
Paul Fultz II 26a8435d76 Use knownConditionTrueFalse when is duplicate expression is true or false (#1410) 2018-10-05 06:00:24 +02:00
Paul Fultz II e170a45230 Enable followVar for opposite expressions (#1404)
Enable followVar for opposite expressions
2018-10-04 21:17:47 +02:00
orbitcowboy c98c7a2ebf suppressions: Avoid duplicate comparison. 2018-10-04 17:13:11 +02:00
Daniel Marjamäki a31db92918 Fixed #8669 (operator>> causes wrong style message) 2018-10-03 13:00:11 +02:00
Daniel Marjamäki de621eab99 Refactoring; use range for loop 2018-10-03 12:54:59 +02:00
Paul Fultz II 1fe1ec09a8 Reenable follow var for logical conjunction (#1400) 2018-10-01 14:40:03 +02:00
Paul Fultz II 2c91b95d2a Reenable followVar for multicondition (#1401) 2018-10-01 14:34:55 +02:00
Paul Fultz II 4598995564 Enable followVar for duplicate ternary expressions (#1406) 2018-10-01 14:31:06 +02:00
rikardfalkeborn b3fef7957a Fix FP with fclose after comma (#7525) (#1407) 2018-10-01 11:58:27 +02:00
Daniel Marjamäki 3a186b5bff astyle formatting 2018-10-01 11:53:32 +02:00
Paul Fultz II 4ed22f1ff8 Fix some FPs in mismatchingContainerExpression (#1402) 2018-09-30 14:49:58 +02:00
Paul Fultz II f65cf220ba Fix false positives in unknownEvaluationOrder when using followVar (#1391)
Fix false positives in unknownEvaluationOrder when using followVar
2018-09-28 08:38:24 +02:00