Daniel Marjamäki
bbcffce529
Fixed #9062 (False positive "condition is always true")
2019-07-24 19:16:35 +02:00
Daniel Marjamäki
6c82685fbf
Fixed compiler warnings
2019-07-24 11:01:38 +02:00
Paul Fultz II
bb52a63c4e
Add check for const variables
...
When a local reference is declared, this will check if that local reference can be declared as `const`.
2019-07-24 09:59:01 +02:00
Paul Fultz II
a08a9c1349
Switch to use lifetime analysis for iterators and pointers to invalid containers
...
This will diagnose more issues such as:
```cpp
void f(std::vector<int> &v) {
auto v0 = v.begin();
v.push_back(123);
std::cout << *v0 << std::endl;
}
```
2019-07-18 10:56:44 +02:00
Daniel Marjamäki
9973db3a71
Modernize: Use enum class for Library::Action and Library::Yield
2019-07-17 11:39:30 +02:00
Daniel Marjamäki
0014fe880e
Mark members and arguments with 'nonneg'
2019-07-14 12:22:33 +02:00
Daniel Marjamäki
5d853bcb58
Avoid 'unsigned' in astutils
2019-07-13 16:13:21 +02:00
Paul Fultz II
b0d10273ed
Fix issue 3695: Handle class pointers
...
This switches to use lifetime analysis to check for assigning to non-local variables:
```cpp
class test
{
public:
void f()
{
int x;
this->ptr = &x;
}
protected:
int *ptr;
};
```
2019-07-07 10:16:19 +02:00
Ken-Patrick
d6f6e68fa2
Fix false positive 9167 ( #1904 )
...
Skip returns from local class/struct definition in FwdAnalysis.
2019-07-03 08:17:06 +02:00
Daniel Marjamäki
beea7fa8d2
Token::index(): Created Token member that indicates the Token position in the token list. It can be used to quickly check if tok1 precedes tok2.
2019-06-21 22:16:23 +02:00
Ken-Patrick
44d6066c6f
FP on assignment through pointer ( #1887 )
...
* Fix FP when assigning through pointers
* Add test case for false positive
cppcheck would faulty warn:
"Condition '*b>0' is always true"
2019-06-17 21:25:15 +02:00
Daniel Marjamäki
5d10b57b04
Fixed #8997 (False positive redundantAssignment when pointer is updated with +=)
2019-05-31 12:24:31 +02:00
orbitcowboy
79ab9cf84d
Running astyle [ci skip].
2019-05-31 10:14:52 +02:00
Paul Fultz II
108cdaa485
Fix FP with unreadVariable ( #1859 )
2019-05-31 08:06:36 +02:00
Rikard Falkeborn
ada881ccdf
Fix #9130 (FP memory leak with NULL pointer cast) ( #1839 )
2019-05-18 06:22:25 +02:00
Daniel Marjamäki
fd4e371091
Refactoring: Use stl algorithm
2019-04-28 07:40:00 +02:00
Daniel Marjamäki
253f2c9e9d
Fixed #9043 (false positive & regression: Variable '*s' is reassigned a value before the old one has been used.)
2019-04-16 19:07:26 +02:00
Paul Fultz II
a90caa7e5a
Fix issue 9006: False positive: Return value of function std::move() is not used.
...
This is trying to fix the issue by fixing the ast and symbol database. First, the ast nodes will be created for the init list and the symbol database will not mark it as a scope. I am not sure if this is the correct approach as I dont really understand how the AST part works.
It did change the AST for `try {} catch (...) {}` but that is because it incorrectly treats `try {}` as an initializer list.
2019-04-15 06:37:27 +02:00
Daniel Marjamäki
51b64191e5
Fixed slow checking in FwdAnalysis
...
Credit to OSS-Fuzz for reporting this!
2019-03-30 14:22:24 +01:00
Sebastian
29815b2dd8
Fix #8922 (SIGSEGV below exprDependsOnThis - stack overflow?) ( #1761 )
...
This limits the recursion depth as a last line of defense to avoid stack
overflows when there are really huge arrays.
See https://trac.cppcheck.net/ticket/8922
2019-03-26 18:57:01 +01:00
Daniel Marjamäki
7995b2fb86
getArguments: Avoid too deep recursion in array initialization
2019-03-24 11:51:28 +01:00
Daniel Marjamäki
418eb43d45
Fixed #9032 (False-positive detection of reassigned value before used for pointer parameter)
2019-03-23 19:01:02 +01:00
Paul Fultz II
774464eabb
Fix issue 8996: False positive duplicateCondition
...
This fixes issue 8996 by improving the alias checking by using lifetime analysis. It also extends the lifetime checker to handle constructors and initializer lists for containers and arrays.
2019-03-19 06:25:10 +01:00
Sebastian
0934577dda
Library configuration: function argument direction fixes and enhancements ( #1722 )
...
* std.cfg: Add further argument directions (in, out, inout).
* testlibrary.cpp: Add test for function argument direction configuration.
* std.cfg: runastyle and add some more direction configurations.
* library.h: Add documentation for function argument direction enum.
* Do not use "direction" library information for pointer arguments.
Also fix further unmatched uninitvar messages in std configuration
tests.
* std.cfg: Add more argument direction configurations.
* test/cfg/std.c: Add test for argument direction configuration.
* astutils.cpp: Only ignore pointer arguments for out/inout arguments.
* library.h: Use suggested documentation for argument direction enum.
2019-03-04 22:57:40 +01:00
Sebastian
9a5fcddb5d
Library configuration: Enable configuring the direction of arguments. ( #1717 )
...
This enhances the library configuration so the direction of function
arguments can be specified (in, out, inout).
isVariableChangedByFunctionCall() uses this information now to avoid
guessing.
2019-03-01 15:47:08 +01:00
Daniel Marjamäki
845c407ab7
Fixed pattern matching in isVariableChanged() to handle normal token list better
2019-03-01 13:23:03 +01:00
Daniel Marjamäki
4f5a426fe5
Improved isVariableChangedByFunctionCall, better logic when parameter might be passed by reference
2019-02-28 17:02:46 +01:00
Daniel Marjamäki
494dd2ba3a
Revert "Improved isVariableChangedByFunctionCall, better logic when parameter might be passed by reference"
...
This reverts commit 14a0031e88
.
2019-02-28 15:56:25 +01:00
Daniel Marjamäki
14a0031e88
Improved isVariableChangedByFunctionCall, better logic when parameter might be passed by reference
2019-02-28 10:26:47 +01:00
Daniel Marjamäki
857681a049
Make quick fix for uninitialized variable false positive. Will look more at this soon.
2019-02-28 09:52:52 +01:00
Paul Fultz II
941dd79f0d
Fix FP issue 8986: constArgument check warns for elements of const array ( #1683 )
2019-02-22 06:39:59 +01:00
Daniel Marjamäki
bd7790fd8c
Update copyright year
2019-02-09 07:24:06 +01:00
Paul Fultz II
d7c20b15e7
Fix FP with const argument when doing a variable and cast ( #1649 )
2019-02-07 14:59:09 +01:00
Daniel Marjamäki
8c07be136a
Fixed #8949 (False Positive: Variable 'f' is assigned a value that is never used.)
2019-01-22 21:16:27 +01:00
Daniel Marjamäki
d50c3de740
Remove inline suppression and fix false positive.
2019-01-13 07:59:41 +01:00
Daniel Marjamäki
2b1b8f8fe9
Fix Cppcheck warnings
...
[ci skip]
2019-01-12 18:29:08 +01:00
Daniel Marjamäki
0f9ce5edd5
Fixed #8365 (False positive on memory leak when assigned inside if statement)
2019-01-08 20:54:39 +01:00
Daniel Marjamäki
2b63997c2c
Fixed #8928 (false positive: (style) Variable 'x' is assigned a value that is never used.)
2019-01-02 20:23:02 +01:00
Daniel Marjamäki
236c88151f
Fixed #8926 (false positive: (style) Condition 's.x<=y' is always true)
2019-01-02 18:05:55 +01:00
Daniel Marjamäki
115be7dfc8
ValueFlow: better FwdAnalysis for complex expressions
2019-01-01 18:23:47 +01:00
Daniel Marjamäki
a73e989d1a
isConstVarExpression: Fix FPs when there is C++ cast
2019-01-01 11:34:44 +01:00
Daniel Marjamäki
ed514644b8
Renamed FwdAnalysisAllPaths to FwdAnalysis
2018-12-31 18:00:47 +01:00
Daniel Marjamäki
141ce7cd63
ValueFlow: Use FwdAnalysisAllPaths in ValueFlow to track complex expressions
2018-12-31 17:05:46 +01:00
rikardfalkeborn
036fcf7827
Fix warnings ( #1541 )
...
* Fix reorder warning
* Fix override warnings
Clang warns about missing overrides.
* Remove unused function
* Add missing argument to function calls
2018-12-28 12:59:05 +01:00
Daniel Marjamäki
6fef02498c
Fixed #7263 (False negative: redundant assignment using +=)
2018-12-27 17:27:53 +01:00
Daniel Marjamäki
ddbe5c129c
Clarify FwdAnalysis. It is useful for checks that need data flow analysis of ALL paths.
2018-12-25 11:56:06 +01:00
Daniel Marjamäki
e2c433a0f8
Fixed #8914 (False positive with unary_function argument)
2018-12-19 19:43:05 +01:00
Daniel Marjamäki
bf4e850e11
Fixed #4475 (New check: struct member is assigned a value that is not read)
2018-12-17 15:40:15 +01:00
Daniel Marjamäki
858d9a18a7
Fixed #3857 (false negative: (style) Variable 'var' is assigned a value that is never used)
2018-12-17 15:16:47 +01:00
Paul Fultz II
9b973e652c
Issue 8830: New check: Function argument evaluates to constant value
...
Add a check for function arguments that can be constant:
```cpp
extern void bar(int);
void f(int x) {
bar((x & 0x01) >> 7); // function 'bar' is always called with a '0'-argument
}
```
2018-12-17 06:04:24 +01:00
Daniel Marjamäki
c8d688607a
Fixed #8901 (Unused value: const variable initialization)
2018-12-16 19:01:05 +01:00
Daniel Marjamäki
21eb1c5e22
FwdAnalysis: Fix false negatives for struct members
2018-12-16 18:32:34 +01:00
Daniel Marjamäki
46a0172480
FwdAnalysis: fix FP in loop
2018-12-16 16:43:04 +01:00
Daniel Marjamäki
97d2075007
FwdAnalysis: better handling of loops
2018-12-16 11:42:11 +01:00
Daniel Marjamäki
3af0d73f82
Unused value: Fixed false negatives for loops
2018-12-16 11:18:37 +01:00
Daniel Marjamäki
1bfe98447a
FwdAnalysis: Tweak possiblyAliased
2018-12-15 11:54:00 +01:00
Daniel Marjamäki
37416010ef
Unused value: Fix false positive (ast, {})
2018-12-14 18:56:09 +01:00
Paul Fultz II
be6782d386
Fix FP 8891: Incorrect return scope when using uniform initialization
...
This fixes the FP in:
```cpp
std::string f(const std::string& data)
{
if (data.empty())
return {};
data[0];
}
```
2018-12-14 18:31:10 +01:00
Daniel Marjamäki
8464085535
UnusedVariables: Fix FP for unknown variable
2018-12-13 21:37:21 +01:00
Daniel Marjamäki
092d434f91
UnusedVar: Fix FP for array arguments
2018-12-13 21:08:18 +01:00
Daniel Marjamäki
1f27cd56c0
FwdAnalysis; Code cleanup, isNullOperand
2018-12-13 21:01:33 +01:00
Daniel Marjamäki
0b4e08cac9
Use FwdAnalysis in UnusedVar. This is still work-in-progress. Merging to master branch so it can be tested.
2018-12-13 18:52:56 +01:00
Daniel Marjamäki
452318dfa4
Remove FwdAnalysis::reads: It is not finished
2018-12-04 18:46:23 +01:00
Daniel Marjamäki
c03c262058
Preparing FwdAnalysis for ValueFlow usage where we want to fetch read locations
2018-12-02 18:29:16 +01:00
Daniel Marjamäki
d8fada6702
Refactoring FwdAnalysis
2018-12-02 17:42:18 +01:00
Daniel Marjamäki
6734571f06
Refactoring: Create FwdAnalysis class in astutils
2018-12-02 17:01:52 +01:00
Daniel Marjamäki
ecb3c04fba
astutils: Add function that visits nodes in AST tree
2018-11-23 06:53:43 +01:00
Paul Fultz II
7ef119cbfc
Fix FPs in lifetime checker
...
This fixes several FPs in the lifetime checker. It also fixes issue [8846](https://trac.cppcheck.net/ticket/8846 ):
```cpp
int * f(int a[])
{
return a;
}
```
2018-11-17 09:41:59 +01:00
Paul Fultz II
54453c5802
Fix FP when copying pointer to string ( #1479 )
2018-11-14 06:59:25 +01:00
Paul Fultz II
0e11bb07c8
Extend lifetime analysis to pointer usage ( #1477 )
...
* Use lifetime analysis for pointers as well
* Fix issue 1143: Pointer to local array
* Update message when using pointers
* Avoid infinite loop in tracing lifetimes
2018-11-12 10:08:17 +01:00
Paul Fultz II
68d6b96878
Diagnose invalid lifetimes ( #1475 )
...
* Add check for invalid lifetimes
* Fix FP with member variables
* Dont forward lifetime values in subfunction
* Update message to use out of scope
2018-11-11 16:43:54 +01:00
Daniel Marjamäki
d5a478d5c5
astyle formatting
...
[ci skip]
2018-11-10 21:30:01 +01:00
Paul Fultz II
1ffcc6b730
Add initial lifetime checker ( #1448 )
...
* Inital valueflow lifetime checker
* Forward values
* Add initial tests
* Fix deplicate messages
* Fix traversing nested lambdas
* Turn test case into a todo
* Skip if returning a container
* Fix FP when using references
* Add missing header
* Fix FP from broken scopes
* Fix FP with static variable
* Add test for more FPs
* Parse lambda functions
* Check for capture by value
* Add tests for using a container and lambda together
* Fix cppcheck errors
* Add test for nextAfterAstRightmostLeaf
* Add valueflow tests
* Update error message
* Check for correct lambda token
* Improve error path reporting
* Fix hang when parsing arrays that look almlost like lambdas
2018-11-10 16:40:40 +01:00
Paul Fultz II
7373be2bfa
Add a pass in valueflow for terminating conditions ( #1323 )
...
* Add valueflow for terminating conditions
* Add valueflow test
* Dont check for same expressions for now to avoid double diagnostics
* Check nesting
* Add more tests
* Ensure conditions happen in order
* Check for null
* Add error path
* Support same expression check as well
* Use early continue
* Skip checking the same token
* Avoid double condtion diagnosis
* Fix FP when in switch statements
* Fix FP when time function
* Skip conditional escapes
* Use simpleMatch
* Fix naming
* Fix typo
2018-11-07 06:49:07 +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
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
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
64fbffc90d
astyle formatting
...
[ci skip]
2018-10-21 20:28:46 +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
e2ea8bc2b0
astyle formatting
...
[ci skip]
2018-10-20 09:28:28 +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
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
Daniel Marjamäki
f961324d45
Fixed #8735 (FP oppositeInnerCondition - regression)
2018-10-07 18:30:29 +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
1fe1ec09a8
Reenable follow var for logical conjunction ( #1400 )
2018-10-01 14:40:03 +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
orbitcowboy
2f032d8fa7
Improved const correctness of local variables. ( #1396 )
...
* Improved const correctness of local variables.
* Running astyle [ci-skip].
* Removed duplicate 'const'-keyword.
2018-09-24 15:08:16 +02:00
Paul Fultz II
5bebeec224
Fix issue 8775: Dont follow aliased variables ( #1390 )
2018-09-24 06:37:47 +02:00
Daniel Marjamäki
afe09f4d7a
Temporarily comment out the followVariable() handling
2018-09-23 16:03:18 +02:00
orbitcowboy
a812da2cf1
Formatted the code.
2018-09-17 17:16:32 +02:00
Paul Fultz II
4e7ed9ea6e
More robust checking for crashes in followVar ( #1375 )
...
More robust checking for crashes in followVar
2018-09-13 09:19:15 +02:00
Paul Fultz II
90a29d986b
Fix issue 8730: Dont follow variables with unknown symbols ( #1374 )
2018-09-12 17:30:18 +02:00
Paul Fultz II
f4f3f81e8f
Fix issue 8741: Require pure when following variables in isSameExpression ( #1373 )
2018-09-09 07:08:32 +02:00
Daniel Marjamäki
df9df70ba7
astyle formatting
...
[ci skip]
2018-09-08 09:07:59 +02:00
Paul Fultz II
cb03b9883f
Fix issue 8737: FP with identical inner condition due to followVar ( #1371 )
2018-09-07 20:16:38 +02:00
Paul Fultz II
b46e25c18e
Fix issue 8730: False positive: Opposite expression on both sides of && ( #1366 )
2018-09-05 18:07:01 +02:00