Paul
dbb410cdae
Merge branch 'main' into condition-in-expr
2020-07-21 13:28:59 -05:00
Paul
e2a81a382f
Track reading aliases during valueflow forward
2020-07-19 23:25:35 -05:00
Daniel Marjamäki
e0be224f4e
Merge pull request #2709 from pfultz2/fp-duplicate-cond-this
...
Fix FP of duplicateCondition when modifying the this variable
2020-07-13 21:14:58 +02:00
Paul
519f2a537a
Format
2020-07-13 13:55:45 -05:00
Paul
450bdfedf3
Fix FP of duplicateCondition when modifying the this variable
2020-07-13 12:40:01 -05:00
Daniel Marjamäki
686a6c7862
Fixed compiler warning
2020-07-03 17:54:55 +02:00
Daniel Marjamäki
f34ff9325a
Fixed testrunner
2020-06-29 21:53:14 +02:00
Daniel Marjamäki
a0770f05e1
Reuse 'extractForLoopValues' in ValueFlow
2020-06-29 21:01:43 +02:00
Paul
d5b6d49d96
Fix issue 9578: false negative: (style) Condition '...' is always false
2020-06-28 15:28:08 -05:00
Daniel Marjamäki
c42c751d61
ExprEngine; Fixed testing
2020-06-28 13:41:27 +02:00
Daniel Marjamäki
262f44e76a
astyle formatting
...
[ci skip]
2020-06-26 12:56:56 +02:00
Paul
1bef6ed268
Another check for null
2020-06-25 19:12:01 -05:00
Paul
263a0364cc
Avoid null pointer dereference
2020-06-25 17:23:42 -05:00
Paul
720d882b69
Remove known arg
2020-06-25 17:20:20 -05:00
Paul
60c42b17a6
Fix known conditions
2020-06-25 15:46:30 -05:00
Paul
1676ad5f45
Fix issue 9710 and 9767: Use AST to get function from argument
2020-06-25 12:54:46 -05:00
Ken-Patrick Lehrmann
c297ed8204
Better handle noreturn or throwing functions in valueflow
...
Teaching cppcheck about `BOOST_THROW_EXCEPTION` and
`boost::throw_exception`, and using noreturn information from libraries
in value flow.
This fixes false positive nullPointerRedundantCheck with the following
code:
```
void throwexception(int * buf)
{
if (!buf)
boost::throw_exception(std::bad_alloc());
*buf = 0;
}
```
2020-06-17 19:06:14 +02:00
Paul Fultz II
03b41ac987
Fix issue 9718: False positive: Parameter can be declared const when written to via stream extraction operator ( #2677 )
2020-06-13 09:20:40 +02:00
Daniel Marjamäki
120c572252
Fixed #9750 (Chained stream operation gives uninitvar error)
2020-06-06 15:24:01 +02:00
Paul Fultz II
eb4754b7d9
Fix issue 9587: False positive: parameter can be declared with const ( #2667 )
2020-05-31 10:10:10 +02:00
Daniel Marjamäki
5c3474ec5c
Renamed hasReturnFunction to hasNoreturFunction
2020-05-23 07:30:05 +02:00
Paul Fultz II
8301fa8244
Fix issue 8144: valueFlowBeforeCondition: struct ( #2645 )
2020-05-21 08:47:48 +02:00
PKEuS
793ed68029
Refactorization: Moved code from header to source
...
- from utils.h to new utils.cpp
- from token.h to token.cpp
- from valueflow.h to valueflow.cpp
- from errorlogger.h to errorlogger.cpp
2020-05-19 08:35:12 +02:00
Daniel Marjamäki
08ddd84780
Update copyright year
2020-05-10 11:16:32 +02:00
Daniel Marjamäki
3e0218299b
Revert "Update copyright year"
...
This reverts commit 6eec6c4bd5
.
2020-05-10 11:13:05 +02:00
Daniel Marjamäki
6eec6c4bd5
Update copyright year
2020-05-10 11:11:34 +02:00
Daniel Marjamäki
54978847c5
Fixed #8916 (FP: followVar does not seem to handle non-const method call properly)
2020-04-18 19:54:55 +02:00
Paul Fultz II
02ae71917a
Fix issue 9536: False positive: Reference to temporary returned when using operator() ( #2582 )
...
* Fix issue 9536: False positive: Reference to temporary returned when using operator()
* Add more test cases
2020-04-01 22:35:41 +02:00
Paul Fultz II
921887a281
Use valueFlowGeneric for valueFlowForwardExpression ( #2537 )
2020-02-16 16:02:22 +01:00
Daniel Marjamäki
67b495fc50
Fixed #9280 (False positive: unreadVariable on assignment to fixed address volatile struct member)
2020-02-15 17:31:47 +01:00
Daniel Marjamäki
8c0ad6a1b9
Fixed #9555 (False positive (unreadVariable): struct is assigned a value that is never used)
2020-02-15 16:43:06 +01:00
Daniel Marjamäki
5f4a900f88
astyle formatting
...
[ci skip]
2020-02-13 17:04:05 +01:00
Paul Fultz II
7368a54629
Add generic valueflow forward analysis ( #2511 )
2020-02-13 16:27:06 +01:00
Paul Fultz II
d858bfc338
Fix issue 9599: False positive: Using object that points to local variable that may be invalid ( #2530 )
...
* Fix issue 9599: False positive: Using object that points to local variable that may be invalid
* Improve tests
* Skip else
2020-02-11 11:45:10 +01:00
Paul Fultz II
8fa7dd0fe0
Fix issue 9595: False positive: Using pointer to temporary doesn't account for const ref extended temporary lifetimes ( #2525 )
2020-02-10 18:01:11 +01:00
Rikard Falkeborn
b1c6f2946a
Fix redundant FP assignment with unsigned zero ( #2521 )
...
* Refactor isNullOperand out of FwdAnalysis
* Improve isNullOperand
* Fix redundantAssignment FP with unsigned zero
* isNullValue check number
* Enhance isNullOperand to handle c++ casts
Also handle cast of NULL.
2020-02-09 11:16:08 +01:00
Rikard Falkeborn
488bc9997c
Improve isSameExpression for same valued literals with followvar ( #2519 )
...
It allows (for example) cppcheck to detect that the lhs and the rhs are
the same in the following example:
double g()
{
double a = 1e1
return a & 10.0;
}
2020-02-03 09:35:24 +01:00
Daniel Marjamäki
0e0d88f65e
Refactoring; Avoid template<>
2020-02-01 08:39:58 +01:00
Rikard Falkeborn
ff9c04dc28
Improve isSameExpression for literals ( #2514 )
...
Improve isSameExpression() for literals with same value but different
representation, for example the following different ways of
representing 9 as double: 9.0, 0.9e1 and 0x1.2p3.
With this change, cppcheck can (for example) correctly detect that the
else if statements are always false in the following example:
void f(double x) {
if (x < 9.0) {}
else if (x < 0x1.2p3) {}
else if (x < 0.9e1) {}
}
2020-02-01 07:22:41 +01:00
Dmitry-Me
01e0a61ebe
Break loops earlier
2020-01-16 18:37:10 +03:00
Paul Fultz II
e1a97c524d
Fix issue 9554: False positive: The address of local variable 'x' is accessed at non-zero index. ( #2470 )
...
* Fix issue 9554: False positive: The address of local variable 'x' is accessed at non-zero index.
* Format
* Remove unnecesary condition check
2020-01-04 11:39:52 +01:00
orbitcowboy
1e0f8ae9b4
Running astyle [ci skip].
2020-01-04 00:06:27 +01:00
Paul Fultz II
dd05839a7e
Fix false positives in knownConditionTrueFalse when using expressions with const variables ( #2469 )
2020-01-03 19:35:28 +01:00
Daniel Marjamäki
235ef0a01e
Fixed #9420 (False positive - redundantInitialization)
2019-12-18 19:39:23 +01:00
Daniel Marjamäki
49d6bfbd7b
Fixed crash in harfbuzz found by daca@home
2019-11-12 18:22:11 +01:00
Paul Fultz II
c75bbbe253
Fix issue 9404: False positive: Either the condition 'if(x)' is redundant or there is possible null pointer dereference: a->x ( #2322 )
...
* Fix issue 9404: False positive: Either the condition 'if(x)' is redundant or there is possible null pointer dereference: a->x
* Use simpleMatch
* Add a test case for the FP
* Check if expression is changed
* Check for no return scope
* Use simpleMatch
2019-11-08 08:11:41 +01:00
Paul Fultz II
d1f225b8ee
Fix issue 9201: FP: returnDanglingLifetime on pointer to variable of static struct ( #2303 )
...
* Fix issue 9201: FP: returnDanglingLifetime on pointer to variable of static struct
* Fix capture of non-local variables in lambdas
2019-11-05 07:10:32 +01:00
Paul Fultz II
c38bbb75e4
Fix issue 9448: Check for temporaries from library function calls ( #2312 )
2019-11-03 22:02:10 +01:00
Daniel Marjamäki
28182084f2
Fix crash when there are too many nested scopes. Bail out after 1000 nested scopes. The crash was in gcc and was seen with daca@home.
2019-11-02 18:23:10 +01:00
Paul Fultz II
694d147097
Refactor ProgramMemory and PathAnalysis ( #2311 )
...
* Traverse conditions for container size
* Move program memory to seperate file
* Revert "Traverse conditions for container size"
This reverts commit 914783769f
.
* Move pathanalysis to seperate files
2019-10-30 17:57:46 +01:00
Paul Fultz II
1ef85f9229
Fix issue 9432 and 9433: False positive: Reference to temporary returned ( #2302 )
2019-10-29 19:12:58 +01:00
Daniel Marjamäki
68ea60d207
Try to make Travis happy
2019-10-20 07:44:56 +02:00
Daniel Marjamäki
4943771e41
Fix #9262 (False positive on variable assignment when putting enum in namespace)
2019-10-19 21:41:50 +02:00
Daniel Marjamäki
99ef64459b
Fixed #9344 (FP redundantAssignment related to increasing index variable for vector)
2019-10-17 18:31:05 +02:00
Paul Fultz II
bf5c90a2be
Fix issue 9409: FP returnTempReference ( #2266 )
...
* Fix issue 9409: FP returnTempReference
* Format
2019-10-13 19:12:46 +02:00
Paul Fultz II
a5c6ae1e08
Fix issue 9400: FP returnTempReference - triggered by cast ( #2259 )
2019-10-10 06:52:11 +02:00
Paul Fultz II
4eb4762d95
Extend lifetime checking to temporaries ( #2242 )
...
* Use lifetimes to check for returning reference to temporaries
* Check for dangling temporaries
* Check for unknown types for returining by reference
* Remove old returnTemporary check
* Format
* Check for deref op
* Ternary operator return an lvalue reference
* Warn when returning temporaries from member functions
* Improve handling of pointer to function
* Extend lifetimes of const references
2019-10-08 09:28:39 +02:00
Paul Fultz II
997803869d
Forward values after assignment in valueFlowReverse ( #2226 )
...
* Forward values after assignment in valueFlowReverse
* Rename variables
* Format
2019-10-03 09:58:57 +02:00
orbitcowboy
f05e21efa8
Formatted the code, there are no functional changes [ci skip].
2019-10-01 08:39:08 +02:00
Paul Fultz II
166bd2bafc
Fix issue 2153: valueFlowAfterCondition: struct member ( #2228 )
...
* Fix issue 2153: valueFlowAfterCondition: struct member
* Fix null pointer dereference
* Formatting
* Check for another null pointer
* Initialize variables
* Remove redundant condition
* Format
* Add missing initialization to copy constructor
* Format
2019-09-30 21:04:43 +02:00
SimonCornell1
6453a85363
Fix the following compilation error on VC142 : ( #2224 )
...
Error C2039 'inserter': is not a member of 'std' cppcheck C:\Users\simon\__Si\git_projects\cppcheck\lib\astutils.cpp 1229
2019-09-28 06:24:32 +02:00
Daniel Marjamäki
b55c587ab2
astyle formatting
...
[ci skip]
2019-09-26 10:32:49 +02:00
Paul Fultz II
597d0fa35b
Support expression in valueFlowAfterCondition ( #2219 )
...
* Add valueFlowForwardExpression function to forward values of an expression
* Use token for expression
* Fix name in bailout message
* Handle expressions
* Add more tests for more expressions
* Add more tests
* Solve the expression if possible
* Formatting
2019-09-26 10:32:25 +02:00
Paul Fultz II
068b0b246c
Fix issue 9352: FP constParameter and constVariable for auto& in combination with ternary ?: operator ( #2173 )
2019-09-13 08:33:30 +02:00
Paul Fultz II
ba037837c9
Track lifetime across multiple returns
...
This will now warn when doing something like this:
```cpp
template <class T, class K, class V>
const V& get_default(const T& t, const K& k, const V& v) {
auto it = t.find(k);
if (it == t.end()) return v;
return it->second;
}
const int& bar(const std::unordered_map<int, int>& m, int k) {
auto x = 0;
return get_default(m, k, x);
}
```
The lifetime warning is considered inconclusive in this case.
I also updated valueflow to no tinject inconclusive values unless `--inconclusive` flag is passed. This creates some false negatives because library functions are not configured to not modify their input parameters, and there are some checks that do not check if the value is inconclusive or not.
2019-09-11 19:25:09 +02:00
Daniel Marjamäki
bee30b0ca2
astyle formatting
...
[ci skip]
2019-09-10 19:42:17 +02:00
Paul Fultz II
dc0b3527ad
Fix issue 9311: False positive duplicateCondition "same if condition" with pointer inside array of struct ( #2166 )
...
* Check for typeOf through an array
* Handle array constructors
* Format
* Fix compile error on gcc 4.8
2019-09-10 19:41:35 +02:00
Paul Fultz II
2595b82634
Fix issue 9348: FP uninitvar for pointer passed to memcpy ( #2167 )
2019-09-10 19:40:08 +02:00
Paul Fultz II
27ebff7ae4
Add deeper analysis of when a function changes a containers size ( #2149 )
...
* Add deeper analysis of when a function changes a containers size
* Fix issues
* Track addressOf
2019-09-06 21:18:45 +02:00
Paul Fultz II
70cad280ea
Fix issue 9319: FP knownConditionTrueFalse related to aggregate initialization of struct ( #2147 )
2019-09-05 19:36:45 +02:00
Paul Fultz II
e657cf4073
Fix issue 9320: False positive knownConditionTrueFalse related to truncation ( #2144 )
2019-09-05 15:15:58 +02:00
Paul Fultz II
0b9e823fc8
Fix issue 9305: False positive uninitvar - struct initialized via function ( #2123 )
2019-08-30 18:32:45 +02:00
Paul Fultz II
03fe6795bf
Fix issue 9302: FP uninitvar - struct accessed via pointer ( #2121 )
2019-08-29 08:38:50 +02:00
Daniel Marjamäki
324e5e581b
Redundant assignments: Fix false positive when reassignment expression contains assembler
2019-08-24 20:15:52 +02:00
Paul Fultz II
c0a8d628b9
Fix issue 6010: Uninitialized inner struct ( #2098 )
...
* Fix issue 6010: Uninitialized inner struct
* Show to root variable that is unitialized
* Warn on pointer dereferences
2019-08-23 06:23:20 +02:00
Paul Fultz II
3aef0c9bd3
Fix issue 8715: regression uninitvar not detected ( #2092 )
2019-08-16 07:48:54 +02:00
Paul Fultz II
ef714225bb
Use library to track container lifetimes
2019-08-15 21:14:54 +02:00
Paul Fultz II
af214e8212
Fix issue 8825: ValueFlow: uninitialized struct member ( #2087 )
...
* Pass uninit value across pointers
* Add more testing
2019-08-15 10:44:55 +02:00
Armin Müller
785cc69644
Typos found by running "codespell" ( #2072 )
2019-08-08 21:05:28 +02:00
Paul Fultz II
bd02ca5ccb
Fix issue 9207: Not detected 'always true' and unreachable code
2019-08-08 07:46:47 +02:00
Daniel Marjamäki
3ad9d6a1ad
Make the code a bit more robust
2019-07-29 20:57:16 +02:00
Daniel Marjamäki
607b3daca8
ValueFlow: Improve bailout for structs etc in loops
2019-07-29 15:51:48 +02:00
Paul Fultz II
ee28a45db4
Fix issue 9235: new crash in astutils isVariableChanged from endless recursion ( #2040 )
2019-07-26 07:03:21 +02:00
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