Commit Graph

1341 Commits

Author SHA1 Message Date
Daniel Marjamäki 29feaa5a51 Tokenizer: Avoid constant folding 2018-10-20 10:51:50 +02:00
Daniel Marjamäki 4983a6a5dc astyle formatting 2018-10-18 20:08:32 +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
Daniel Marjamäki 1245a036f7 Add check for shadow variables 2018-10-16 20:17:27 +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 aa58f41e6d Fixed #7152 (False positive for redundantAssignment after calling a lambda function) 2018-10-08 21:07:21 +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
Paul Fultz II 4598995564 Enable followVar for duplicate ternary expressions (#1406) 2018-10-01 14:31:06 +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
Daniel Marjamäki 7591616f43 Fixed #8710 (Update message duplicateExpression when operand is integer literal) 2018-08-30 18:28:34 +02:00
Daniel Marjamäki ad0ebd8f1a astyle formatting
[ci skip]
2018-08-25 21:32:52 +02:00
Paul Fultz II a5f4c5d0eb Improve message for same expressions (#1349)
* Improve message for same expressions

* Update message
2018-08-25 14:25:31 +02:00
Daniel Marjamäki e442bc47b1 astyle formatting
[ci skip]
2018-08-17 19:55:21 +02:00
Paul Fultz II bbf876256c Add error path to more diagnostics that rely on isSameExpression (#1342) 2018-08-17 09:25:07 +02:00
Paul Fultz II 80290a15e0 Fix FP with duplicate assign (#1330) 2018-08-08 08:31:31 +02:00
Daniel Marjamäki c3a44ce56b astyle formatting
[ci skip]
2018-08-07 18:06:51 +02:00
Paul Fultz II f603b529df Fix issue 8413: Condition is always false 'i=expr; if (i != expr) {}' (#1295)
* Follow variables when comparing same expression

* Remove assert include

* Dont follow function arguments

* Improve the checking to check more cases

* Add more tests

* Check if the variable is used inside a loop

* Follow both variables

* Only skip loops when variable is modified in scope

* Fix FP when followed variable is modified

* Dont follow arrays

* Skip pointer indirection

* Make recursive

* Improve checking more variables

* Fix test with sizeof

* Skip following operators

* Fix test when using sizeof

* Dont check every step

* Use early returns

* Update test to use a loop instead of conditional

* Add static

* Check variables are global

* Check local variables in another scope

* Fix issue with const pointers

* Distinguish between pointer indirection and multiply

* Use simple match

* Prevent crash with uniform initialization

* Use unary op and ast to detect pointer indirection

* Expand error message when expression do not match exactly

* Add errorpath to issameexpression

* Revert "Clarify warning message for 'Same expression on both sides of operator'"

This reverts commit 0e491b41a8.

* Check if the tokens are the same

* Report the operator and not the expressions
2018-08-07 09:32:16 +02:00
Daniel Marjamäki 0e491b41a8 Clarify warning message for 'Same expression on both sides of operator' 2018-08-05 10:48:02 +02:00
Daniel Marjamäki f9a5a114bb astyle formatting
[ci skip]
2018-07-25 07:44:06 +02:00
lordylike 12e58c8521 fix ticket 8570: passedByValue with member initializer list and std::move (#1316)
* fix ticket 8570

allow member initializer list variables that are moved to be non-const

* review feedback

* replace tabs with spaces in test code
2018-07-22 15:01:18 +02:00
Daniel Marjamäki 417670d947 Clarify code with continue 2018-07-20 21:44:23 +02:00
Daniel Marjamäki d00e522856 Clarify the code with Token::isUnaryOp and Token::isBinaryOp 2018-07-14 13:01:24 +02:00
Daniel Marjamäki c9a2071420 Refactoring: Use range for loop 2018-07-14 12:28:57 +02:00
Daniel Marjamäki 24dd4c9c26 Restore code in checkVariableScope. Fixes false negative 2018-07-01 22:31:45 +02:00
Daniel Marjamäki 2beeca3ca2 Refactoring; use early continue 2018-06-23 23:26:37 +02:00
Daniel Marjamäki 655a8b21b6 Fix false positive 'passedByValue' when address of argument is used 2018-06-23 23:25:06 +02:00
Daniel Marjamäki 697aee143f CheckOther: Use Variable::valueType() instead of Variable::typeStartToken 2018-06-23 16:52:40 +02:00
Daniel Marjamäki fc78530b3f CheckOther: Use Variable::valueType() instead of Variable::typeStartToken 2018-06-23 16:49:26 +02:00
Daniel Marjamäki 2a8296879c CheckOther: Use Variable::valueType() instead of Variable::typeStartToken 2018-06-23 16:42:36 +02:00
Daniel Marjamäki ee335e5151 Fix compiler error 2018-06-23 16:07:02 +02:00
Daniel Marjamäki 911020f601 Refactoring, use range for loop 2018-06-23 15:58:44 +02:00
Daniel Marjamäki d811a07aa3 CheckOther: Use Variable::valueType() instead of typeStartToken etc 2018-06-22 23:04:36 +02:00
Daniel Marjamäki d0614b9b36 varScope: Fix false negatives for references 2018-06-22 22:51:03 +02:00
Daniel Marjamäki 439d4a4900 Use Variable::valueType() instead of Variable::typeStartToken() 2018-06-20 19:08:09 +02:00
Daniel Marjamäki 79ffe1d4fc Rename _tokenizer, _settings, _errorLogger 2018-06-16 16:10:28 +02:00
Daniel Marjamäki b9d03d0e23 astyle formatting
[ci skip]
2018-06-10 21:59:24 +02:00
Paul Fultz II daacf27c2e Fix false positive from issue 8612 (#1285) 2018-06-10 00:05:23 +02:00
Paul Fultz II 8d53bcfd63 Fix FP when using non-const members and also check return type of function (#1283) 2018-06-09 08:05:19 +02:00
Daniel Marjamäki 84f0a18053 passedByReference: avoid false positives for std::pair 2018-06-08 10:19:02 +02:00
Daniel Marjamäki 44c78d1770 passedByReference: avoid false positives for std::function 2018-06-08 08:40:14 +02:00
Daniel Marjamäki de09c117bf Fixed #8618 (False positive: shared_ptr is passed by reference by intention) 2018-06-07 22:39:21 +02:00
Sebastian 7c9b6d9bb0
checkother.cpp: Fix typo in symbol placeholder in error message. (#1276) 2018-06-05 10:24:19 +02:00
orbitcowboy 33777c5b72 Improved const correcntess of local variables. 2018-05-29 13:24:48 +02:00
Paul Fultz II 7ef714b0c6 Fix FP with duplicate assignments by checking if the expression is unique (#1223)
* Fix FP with duplicate assignments by checking if the expression is unique

* Use array of pointers

* Reorder scope condition
2018-05-13 20:20:55 +02:00
IOBYTE 184537884f Don't remove the volatile keyword so we can properly overload functions. (#1218)
* Don't remove the volatile keyword so we can properly overload functions.

I fixed all the checks that had tests that use volatile.  There will
probably be more changes needed due to lack of test coverage for
volatile in some checks.

* Fix unused private function warning.
2018-05-10 07:40:01 +02:00
Paul Fultz II f191a3e753 Improve checking of opposite expressions (#1199)
* Improve checking of opposite expressions

* Fix some formatting
2018-05-02 06:32:33 +02:00
Daniel Marjamäki ca8e19c96d SymbolDatabase: Refactor SymbolDatabase: variable list 2018-04-28 09:38:33 +02:00
Daniel Marjamäki f336c2efe7 Refactoring; Renamed Scope::classStart and Scope::classEnd 2018-04-27 22:36:30 +02:00
Daniel Marjamäki b6e89f85d0 CheckOther: Use isLikelyStreamRead 2018-04-22 17:14:28 +02:00
Daniel Marjamäki e1db4c0e2c astyle formatting
[ci skip]
2018-04-21 13:28:31 +02:00
Paul Fultz II d939c6015a Report opposite expressions (#1182)
* Report opposite expressions

* Skip assignment operator
2018-04-21 11:28:21 +02:00
Daniel Marjamäki 46bb63ceaf Refactoring: Use range for loop 2018-04-20 22:08:22 +02:00
Daniel Marjamäki d5fb529d4f Fixed #8492 (Improve message: parameter should be passed by reference) 2018-04-20 17:33:42 +02:00
Daniel Marjamäki 313b2a1755 Refactoring: Use ranged for loops 2018-04-19 22:31:36 +02:00
Daniel Marjamäki e95ff8c7b6 Avoiding emplace 2018-04-14 19:24:35 +02:00
PKEuS d2146844dd Refactorizations:
- Replace several push_back-calls by emplace_back
- Replace some x = x.substr(0, y) calls by x.erase(y)
2018-04-11 09:44:35 +02:00
PKEuS b15cc3f236 Refactorization: Replace several push_back-sequences by initializer lists 2018-04-09 09:54:39 +02:00
Daniel Marjamäki a0906140a6 Suppressions: New extensible Suppressions xml format that allow more attributes. To start with it also allows symbolName. 2018-04-09 06:43:48 +02:00
PKEuS e2002db78d Replaced make_container by C++11 initializer lists 2018-04-08 23:03:44 +02:00
Daniel Marjamäki ae3e649cc4 astyle formatting
[ci skip]
2018-04-08 20:29:52 +02:00
Paul Fultz II 95fc84a26b Find duplicate expressions assigned to the same variable (#1129)
* Check for duplicate assignments

* Improve checking of expression

* Add more tests

* Use simple match

* Improve robustness of check

* check for null

* Reduce side effects by checking for side effects

* Improve verbose message

* Reword the error message
2018-04-08 14:43:19 +02:00
jrp2014 15b5b7ebf4 Refactor lib/checkother.cpp 2018-04-06 08:00:10 +02:00
jrp2014 b6504c70ca Improve constness 2018-04-04 21:51:31 +02:00
Paul Fultz II bce5fe5cef Improve duplicate expressions in the ternary op by checking for equal values as well (#1134)
* Improve duplicate expressions in the ternary op by checking for equal values as well

* Use value instead of expression
2018-04-03 21:43:55 +02:00
orbitcowboy 27d9aaa8f5 checkother: Removed statement that is always true. (#1059) 2018-01-26 22:49:07 +01:00
Daniel Marjamäki c4caee6b18 Updated copyright year 2018-01-14 15:37:52 +01:00
Matthias Krüger eb58df236e CheckOther::accessMovedError() / accessMoved, accessForwarded warnings: put variable name into single quotes. 2018-01-07 10:57:19 +01:00
Dmitry-Me f4ddf43cba Break loop early, simplify check 2017-12-20 03:55:43 +03:00
Daniel Marjamäki fbccb3ae55 Add errorpath for accessMoved message 2017-10-10 15:49:15 +02:00
Daniel Marjamäki 5e618418d5 Refactoring, use early continue in loop 2017-09-21 22:53:15 +02:00
Daniel Marjamäki 411c5e5f7e Fixed #8190 (False positive constStatement - return (struct media_frames_per_second) {0};) 2017-09-21 22:50:46 +02:00
Daniel Marjamäki ba8222de1c ValueFlow: Put 'inconclusive' state in the ValueKind. A value can't be both known and inconclusive. 2017-09-20 22:41:36 +02:00
Dmitry-Me d7b91a9e92 Fix CID 1378763
Defensive check recovered from earlier version of this code
2017-09-05 00:17:51 +03:00
Daniel Marjamäki e74e4c6934 Fixed #8030 (False positive 'constStatement' when indexing with {}) 2017-08-26 11:59:09 +02:00
Ayaz Salikhov b8cd7dbb5c Use nullptr instead of 0 or NULL (#936) 2017-08-09 20:00:26 +02:00
orbitcowboy 0e575ce12c Modernize: make use of 'nullptr' and added a rule-file for finding non-nullptr (zero) initializations. 2017-07-28 15:20:43 +02:00
Andreas Pokorny b802b98136 Do not warn when unique pointers are passed by value
A unique pointer should only be passed by value or by const reference.
Passing by value means transferring ownership it makes no sense to have a pass by value Warning for unique_ptr

Signed-off-by: Andreas Pokorny <andreas.pokorny@siemens.com>
2017-07-25 11:17:56 +02:00
Stas Cymbalov ff38cc5c13 Set struct size cutoff in passedByValue check to 2*sizeof_pointer
Struct arguments are either pushed to the stack or passed in the
registers. Since both methods operate on machine words it is logical to
tie the maximum size of a struct argument that doesn't trigger
passedByValue diagnostic to the size of the machine word.

Also guessed size of STL classes is set to 3*sizeof_pointer, this better
represents reality and ensures that structs containing them will still
trigger passedByValue.
2017-06-06 08:48:11 +02:00
Ayaz Salikhov 28aa939d69 iwyu - include what you use 2017-05-27 04:33:47 +02:00
Daniel Marjamäki f7cda81c0c Refactoring: ValueFlow::Value::errorSeverity() will have the logic if value is 'error' or 'warning' 2017-05-23 11:43:56 +02:00
Daniel Marjamäki 55ae206ecc ErrorPath: better output 2017-05-19 17:29:16 +02:00
Matthias Krüger a2c716fa3b CheckOther::checkDuplicateExpression(): be lazier if style-reports are not enabled. NFCI. 2017-05-19 00:54:55 +02:00
Daniel Marjamäki c617851567 ErrorLogger: Added ErrorPath where each item has token and info 2017-05-16 22:38:13 +02:00
Daniel Marjamäki f92e7b3bfc Emit better errorpath in CheckBufferOverrun::negativeIndexError 2017-05-16 19:08:47 +02:00
Daniel Marjamäki 8d75d1b920 Partial fix for #8028 (ValueFlow: Origin/callstack of value) 2017-05-15 20:05:11 +02:00
Daniel Marjamäki 101dc28afa Refactoring: Moved checkMemset.. from CheckOther to CheckFunctions 2017-04-23 07:53:41 +02:00
Daniel Marjamäki f6ab204dc6 Refactorings in CheckOther 2017-04-23 07:19:44 +02:00
PKEuS b1f4bd7504 Refactorization: Reimplemented Settings::_enabled as a bitfeld instead of std::set (#7995) 2017-04-11 11:49:26 +02:00
Roberto Martelloni 35d1479d05 CWE mapping of funcArgOrderDifferent, funcArgNamesDifferent (#885)
Add an optional extended description…
2017-04-01 08:36:46 +02:00
PKEuS 3c8f5b85ae Refactorization: Allocate Token::_values (ValueFlow information) dynamically, reducing size of each token by around 10% 2017-03-27 18:48:34 +02:00
Daniel Marjamäki f5d56fd303 Fixed #7961 (Hang in CheckOther::checkFuncArgNamesDifferent) 2017-03-24 22:01:05 +01:00
PKEuS 00904ba32a Fixed false negatives in CheckOther::checkPassByReference() when assignment operator is used. 2017-03-07 21:49:28 +01:00
PKEuS 3da1de7893 Do not exclude std::shared_ptr and std::unique_ptr from checkPassByReference() (#7834)
These two types are larger than one pointer. Hence, passing by reference is faster.
2017-03-07 21:18:08 +01:00
PKEuS 1c3f010935 Fixed false positive: Exclude STL shared pointers from checkPassByReference() (#7834) 2017-03-07 21:04:19 +01:00
Daniel Marjamäki ecc59859e1 Don't simplify _Bool in TokenList 2017-03-04 11:13:28 +01:00
Daniel Marjamäki b1ce229006 Small refactoring 2017-03-03 19:09:32 +01:00
Daniel Marjamäki 59c1c76a97 Fixed #7466 (Reference variable does not count side-effects (FP variableScope)) 2017-03-03 19:07:00 +01:00