Commit Graph

359 Commits

Author SHA1 Message Date
amai2012 738fef6c27 Run astyle 2019-01-12 21:51:39 +01:00
Daniel Marjamäki 5276fd68b2 Remove unused test functions
[ci skip]
2019-01-12 18:32:18 +01:00
Daniel Marjamäki 8dd641b8be Use OVERRIDE in test 2019-01-12 15:45:25 +01:00
Daniel Marjamäki 5636497c0b Fixed #8863 (false positive: (warning) Accessing an item in container 's'. Either the condition 's.empty()' is redundant or 's' can be empty.) 2019-01-06 12:21:55 +01:00
Paul Fultz II bba6dfb8b2 Fix issue 4744: ValueFlow: known integer result
This fixes valueflow to have a value for `||` operator here:

```cpp
bool f()
{
	bool a = (4 == 3); // <-- 0
	bool b = (3 == 3); // <-- 1
	return a || b; // <-- 1
}
```
2019-01-03 07:05:31 +01:00
Daniel Marjamäki 39a96a5a16 ValueFlow: Temporarily comment out valueFlowTerminatingCondition 2019-01-02 19:42:08 +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 be7afac875 ValueFlow: remove handling of == for complex expressions it did not work properly 2019-01-01 17:23:46 +01:00
rikardfalkeborn 13ffefc8b8 Valueflow: Fix right shift with more than 31 bits (#1553)
When comparing if the shift is large enough to make the result zero, use
an unsigned long long to make sure the result fits. Also, a check that
avoids setting the value if the shift is equal to or larger than the
number of bits in the operand (this is undefined behaviour). Finally,
add a check to make sure the calculated value is not too large to store.

Add test cases to cover this.

This was detected by an MSVC warning.

valueflow.cpp(1350): warning C4334: '<<' : result of 32-bit shift implicitly
                     converted to 64 bits (was 64-bit shift intended?)
2019-01-01 14:15:50 +01:00
Daniel Marjamäki 4918a18bfb ValueFlow: Value of expression after condition 2018-12-31 17:37:38 +01:00
Daniel Marjamäki 141ce7cd63 ValueFlow: Use FwdAnalysisAllPaths in ValueFlow to track complex expressions 2018-12-31 17:05:46 +01:00
Daniel Marjamäki a40fe3c67f Fixed #7872 (ValueFlow: static_cast) 2018-12-27 21:33:01 +01:00
Daniel Marjamäki bc34f0239d Disable the subfunction value flow analysis. It does not work well and needs to be rewritten. There are false positives. 2018-12-18 14:36:49 +01:00
Paul Fultz II 3262a3bebe Add isSameExpression to valueflow analysis
Check for same expressions in valueflow analysis.
2018-12-16 07:35:27 +01:00
Daniel Marjamäki 88c61e8d1e ValueFlow: Avoid FP when lambda is used 2018-12-04 18:54:26 +01:00
Daniel Marjamäki f5a94ed300 ValueFlow: Fix FP when lambda is called 2018-12-04 18:46:00 +01:00
Igor 61878c5e11 Add null pointer check to fix SEGFAULT (#1499)
* Add null pointer check to fix segfault

* Add first test case to reproduce problem
2018-12-02 14:36:01 +01:00
Daniel Marjamäki 2887ee10c0 Fixed #8800 (Possible variable assignment ignored in boolean expression) 2018-11-26 14:00:03 +01:00
Paul Fultz II a3921ea861 Refactor valueFlowAfterCondition
So this unifies the `valueFlowAfterCondition` so it re-uses more code between checking for integers and container sizes. This should make valueFlowContainer more robust.

It also extends valueflow to support container comparisons such as `if (v.size() < 3)` or `if (v.size() > 3)` using the same mechanism that is used for integers.
2018-11-24 10:07:12 +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
Daniel Marjamäki 00340efc57 ValueFlow: Refactoring valueFlowCallFunction 2018-11-06 06:38:26 +01:00
Daniel Marjamäki ca19894a04 ValueFlow: In evaluate handle correlated values 2018-11-05 18:07:35 +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 6878de2c5e ValueFlow: getExpressionRange, valueFlowRightShift 2018-11-03 23:25:46 +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 c03d32b429 ValueFlow: Improve containerSize handling of string like classes 2018-10-28 19:14:00 +01:00
Daniel Marjamäki 06ede9c239 ValueFlow: handle x+=y for containers 2018-10-27 18:38:04 +02:00
Daniel Marjamäki d7de46f50e ValueFlow: Fix false positive for container size 2018-09-08 10:43:08 +02:00
Daniel Marjamäki c6d43506b6 ValueFlow: Fix FP in switch 2018-09-04 20:28:48 +02:00
Daniel Marjamäki cc402869a6 Fixed #8689 (False positive: containerOutOfBounds after function call) 2018-09-02 14:08:34 +02:00
Daniel Marjamäki 6223204a06 Fixed #8708 (FP: Accessing an item in container that is empty) 2018-08-27 13:49:47 +02:00
Paul Fultz II fc135e1087 Check if member function modifies the variable (#1350)
* Check if member function modifies the variable

* Check for const pointer

* Add test for const condition

* Add more null checking

* Add todo assert for FN
2018-08-27 11:09:09 +02:00
Daniel Marjamäki 866d198756 Fixed #8697 (noreturn output stream) 2018-08-21 06:32:33 +02:00
Daniel Marjamäki 2f834c3c3b Fixed #8688 (False positive: containerOutOfBounds) 2018-08-13 21:27:29 +02:00
Daniel Marjamäki 55ab842083 valueFlowSizeForward: Bailout when function calls modify the container size 2018-08-13 06:54:18 +02:00
Daniel Marjamäki 183345a939 valueFlowContainerSize: Fix FP when container size is changed 2018-08-12 22:23:19 +02:00
Daniel Marjamäki 7074eeb869 valueFlowContainerSize: assignment of string-like containers 2018-08-12 22:01:58 +02:00
Daniel Marjamäki 189ea5003a valueFlowContainerSize: empty container variables 2018-08-12 14:41:00 +02:00
Daniel Marjamäki 811a71aa06 valueFlowContainerSize: Handle guard logic 2018-08-11 15:08:54 +02:00
Daniel Marjamäki 6008bbdfb4 valueFlowContainerSize: Fix wrong value after condition if conditional code escapes 2018-08-11 13:49:42 +02:00
Daniel Marjamäki 10461e5429 valueFlowContainerSize: forward analysis inside conditional code 2018-08-10 22:18:38 +02:00
Daniel Marjamäki 4a502a7f6b valueFlowContainerSize: add simple forward analysis 2018-08-10 22:06:23 +02:00
Daniel Marjamäki 2b10e38eec valueFlowContainerSize: handling of 'v.size() == 10' 2018-08-10 21:43:47 +02:00
Paul Fultz II 3947c23290 Fix issue 8369: False negative: Condition 'condition' is always true (#1325)
* Fix issue 8369: False negative: Condition 'condition' is always true

* Use simpleMatch

* Add iterator header

* Cleanup

* Remove unused variable
2018-08-10 18:05:23 +02:00
Daniel Marjamäki 907f81d059 ValueFlow: Improved analysis of container size 2018-08-10 11:53:56 +02:00
Daniel Marjamäki 81f54f7094 Fixed #8681 (ValueFlow: Container size) 2018-08-10 11:29:16 +02:00