Commit Graph

317 Commits

Author SHA1 Message Date
Daniel Marjamäki f5e3dc9a38 Improved fix for #8978 (False positive: Variable assigned value that is never used when assigning via iterator) 2019-11-17 12:08:21 +01:00
Paul Fultz II c1da6c7dd2 Fix issue 9461: False positive: Reference to temporary returned using trailing return type (#2345) 2019-11-10 09:44:04 +01: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
IOBYTE 8f46bb3ef6 fix #9392 (SymbolDatabase: Weird default constructor outside class) (#2243) 2019-10-06 07:21:12 +02:00
Paul Fultz II cf1c766292 Fix issue 9317: False positive returnDanglingLifetime when using reference to constant inside if statement (#2241) 2019-10-05 16:32:20 +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
Oliver Stöneberg de9f489b08 use range loops / constness (#2181)
* use range loops / constness

* platform.cpp: avoid shadowed variable
2019-09-19 20:29:33 +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 ebcca4edd1 Improve --debug-warnings output for 'auto' tokens without type. Do not report that prematurely before the type is set properly. 2019-08-05 13:42:06 +02:00
Paul Fultz II ffdd2dc793 Fix issue 8924: Re-enable valueFlowTerminatingCondition 2019-08-05 07:18:06 +02:00
Daniel Marjamäki c03df8e6b4 SymbolDatabase: Improved matchParameter for containers 2019-08-03 10:10:40 +02:00
amai2012 f02636e995 Refactoring: Convert enums to enum classes 2019-08-02 21:14:29 +02:00
Daniel Marjamäki a3dc2db77a SymbolDatabase: Use ValueType::matchParameter for variable address parameters 2019-07-31 12:38:36 +02:00
Daniel Marjamäki ed5ae7c5fa SymbolDatabase::findFunction: Use ValueType::matchParameter for float literal parameters 2019-07-29 21:53:39 +02:00
Daniel Marjamäki 3066c0653c Fixed #8668 (SymbolDatabase: Wrong findFunction match for const pointer argument) 2019-07-29 18:14:23 +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
Daniel Marjamäki 4fb6c27276 Modernize: Use enum class 2019-07-23 14:29:02 +02:00
Daniel Marjamäki a81c39af09 Replace 'unsigned' with 'nonneg' 2019-07-22 11:25:51 +02:00
Daniel Marjamäki c9906125de Safe functions: Check more possible function argument values 2019-07-10 16:59:05 +02:00
Daniel Marjamäki a0b22410cf SymbolDatabase: Better handling of smart pointers 2019-07-07 21:52:49 +02:00
Paul Fultz II e0ced1c415 Parse lambdas as functions (#1955)
* Parse lambdas as functions

* Fix issue with missing paren

* Fix error when parsing non-existent args

* Remove unused function variable
2019-07-05 12:30:42 +02:00
shaneasd 7e54f989f9 Update symbol database such that the override keyword implies that the function is also virtual (#1907)
* Update symbol database such that the override keyword implies that the function is also virtual

* Add test case for implicit override

* change isVirtual to hasVirtualSpecifier

* fix method documentation for getVirtualFunctionCalls and getFirstVirtualFunctionCallStack

* Fix isImplicitlyVirtual to consider the override keyword and document logic

* Fix getFirstVirtualFunctionCallStack and getVirtualFunctionCalls to use isImplicitlyVirtual instead of isVirtual so new test case passes
2019-07-04 12:32:32 +02:00
Paul Fultz II 091f4bcf8d Add check for unnecessary search before insertion
This will warn for cases where searching in an associative container happens before insertion, like this:

```cpp
void f1(std::set<unsigned>& s, unsigned x) {
    if (s.find(x) == s.end()) {
        s.insert(x);
    }
}

void f2(std::map<unsigned, unsigned>& m, unsigned x) {
    if (m.find(x) == m.end()) {
        m.emplace(x, 1);
    } else {
        m[x] = 1;
    }
}
```

In the case of the map it could be written as `m[x] = 1` as it will create the key if it doesnt exist, so the extra search is not necessary.

I have this marked as `performance` as it is mostly concerning performance, but there could be a copy-paste error possibly, although I dont think thats common.
2019-05-02 11:04:23 +02:00
Rikard Falkeborn 1cc5f3abe7 Set wchar_t type (#1807)
This is necessary for valueflow to know the size, for example when
calculating sizeof(wchar_t).
2019-05-01 16:34:28 +02:00
Paul Fultz II 39f4374446 Improve diagnostics with null smart pointers (#1805)
* Warn when dereferencing null smart pointers

* Improve tracking of smart pointer values

* Use library isSmartPointer
2019-04-26 11:30:09 +02:00
Daniel Marjamäki 92f4113b59 Array index: Checking array index out of bounds for dynamic buffers 2019-03-17 13:09:15 +01:00
Daniel Marjamäki a2a216bbe3 SymbolDatabase: Improved handling of 'normal' non simplified token list 2019-03-15 19:00:42 +01:00
Daniel Marjamäki bd7790fd8c Update copyright year 2019-02-09 07:24:06 +01:00
Paul Fultz II 3975913637 Extend lifetime checking for references
This will use the lifetime checker for dangling references. It will find these cases for indirectly assigned reference:

```cpp
int &foo()
{
    int s = 0;
    int& x = s;
    return x;
}
```

This will also fix issue 510 as well:

```cpp
int &f( int k )
{
    static int &r = k;
    return r;
}
```
2019-01-23 07:29:16 +01:00
Lauri Nurmi f267900257 Fix spelling of "overridden" in function names.
One 'd' was missing.
2019-01-15 06:22:14 +01:00
IOBYTE 0f83aff3b8 Improve trailing return type support. (#1520)
* Improve trailing return type support.

* Partial fix for #8889 (varid on function when using trailing return type)

* Handle operators in templates.
2018-12-13 06:34:10 +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
Daniel Marjamäki efd92fd714 Refactoring: reuse utility function in SymbolDatabase 2018-11-04 13:29:29 +01:00
Daniel Marjamäki 929725f3aa Code cleanup 2018-06-20 10:39:21 +02:00
Daniel Marjamäki b4cb2505c3 SymbolDatabase: Add Variable::valueType(). First step to reuse ValueType handling in Variable 2018-06-20 10:00:15 +02:00
Daniel Marjamäki eb978ee192 Refactoring: delete assignment operator 2018-06-19 14:00:50 +02:00
Daniel Marjamäki ad4ce84cf7 Rename private member variables 2018-06-17 17:20:16 +02:00
Daniel Marjamäki d9aeeb1d09 Renamed private member cpp to mIsCpp 2018-06-16 23:30:00 +02:00
Daniel Marjamäki 306b2a9810 Renamed private member defaultSignedness 2018-06-16 23:25:35 +02:00
Daniel Marjamäki 678e3271d4 Rename private flags member to mFlags 2018-06-16 23:11:45 +02:00
Daniel Marjamäki 15f7c26706 Renamed _blankTypes 2018-06-16 20:33:07 +02:00
Daniel Marjamäki 56126d6e2d Renamed _variableList to mVariableList 2018-06-16 20:31:47 +02:00
Daniel Marjamäki e8a00a38ac Rename _scope to mScope 2018-06-16 20:29:17 +02:00
Daniel Marjamäki 78974e9267 Rename _type to mType 2018-06-16 20:25:54 +02:00
Daniel Marjamäki fc6f17ed87 Rename _dimensions to mDimensions 2018-06-16 20:23:58 +02:00
Daniel Marjamäki 363f4ca939 rename _flags to mFlags 2018-06-16 16:14:34 +02:00
Daniel Marjamäki 67b111f11e SymbolDatabase: rename _constness to mConstness 2018-06-16 16:13:26 +02:00
Daniel Marjamäki 5154eb10c6 SymbolDatabase: rename _access 2018-06-16 16:12:27 +02:00
Daniel Marjamäki 7dfd4f61a1 SymbolDatabase: rename _index 2018-06-16 16:11:40 +02:00