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
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