Commit Graph

489 Commits

Author SHA1 Message Date
Paul Fultz II 82b725e540
Fix FP when using deferred locks (#3441) 2021-09-04 19:06:48 +02:00
chrchr-github f77d9db852
Add test case for #10383 (#3421) 2021-08-26 19:37:29 +02:00
Paul Fultz II e0de48bb1d
Fix 7524: ValueFlow: false path for 'x<3' (#3393) 2021-08-16 09:19:07 +02:00
Paul Fultz II 7f358b2bed
Format with uncrustify (#3388) 2021-08-07 20:51:18 +02:00
Paul Fultz II 3d19b33c3e
Fix 9948 and 10234: false negative: knownConditionTrueFalse and stlOutOfBounds (#3372) 2021-08-02 10:51:34 +02:00
Daniel Marjamäki 1ec7397c21 astyle formatting
[ci skip]
2021-08-01 14:05:30 +02:00
Paul Fultz II 6a81b4c17c
Fix 10264: FP invalidContainer when address of container is passed inside struct (#3368) 2021-07-30 15:52:00 +02:00
Paul Fultz II 0d3afbb954
Evaluate casts in programmemory (#3359) 2021-07-26 22:22:23 +02:00
orbitcowboy c14bb9cd2e Running astyle [ci skip] 2021-07-26 16:32:00 +02:00
Paul Fultz II 5be3f700bb
Fix 10373: ValueFlow: container in struct assumed empty (#3355) 2021-07-25 18:13:55 +02:00
Paul Fultz II f9516cf1c6
Fix issue 10378: FP derefInvalidIteratorRedundantCheck (#3353) 2021-07-24 22:44:18 +02:00
Paul Fultz II 942202aede
Evaluate container sizes in forward analysis (#3338) 2021-07-16 18:49:07 +02:00
Daniel Marjamäki 869eac5670 astyle formatting 2021-07-01 21:09:32 +02:00
chrchr-github 9be88a06fe
Add regression test for #9176 (#3319) 2021-07-01 13:58:00 +02:00
Paul Fultz II a14922ed85
Fix 10238: FP knownConditionTrueFalse std::string from const char* assumed non-empty (#3288) 2021-06-04 17:22:05 +02:00
Paul Fultz II 537fb5bcd9
Fix 10264: FP invalidContainer when address of container is passed inside struct (#3286) 2021-06-04 17:20:47 +02:00
Paul Fultz II 3e78e76fe8
Fix issue 10076: ValueFlow: False positive after address of var is taken 'T t = {{{&var}}};' (#3283) 2021-06-03 07:31:46 +02:00
Paul Fultz II 8541e0503e
Fix 10290: false negative: container out of bounds (#3269) 2021-05-22 23:33:13 +02:00
Paul Fultz II c63aa2f2cc
Fix 10263: FP containerOutOfBounds when container is accessed via pointer (#3265) 2021-05-22 08:36:51 +02:00
Paul Fultz II c1bb1d771b
Fix issue 10012: False positive: mismatching container, not containers (#3222)
* Fix issue 10012: False positive: mismatching container, not containers
2021-04-19 09:17:02 +02:00
Paul Fultz II e0f9627201
Fix issue 10226: FP: redundant condition or invalid iterator (#3195) 2021-04-06 11:04:37 +02:00
Paul Fultz II e65ea8575f
Fix issue 10207: FP: derefInvalidIteratorRedundantCheck with ternary operator (#3197) 2021-04-05 11:10:43 +02:00
Paul Fultz II 5077663684
Fix issue 9979: false positive: containerOutOfBounds with conditional resize (#3136) 2021-03-30 14:02:28 +02:00
Daniel Marjamäki 42437277dc Update Copyright year 2021-03-21 20:58:32 +01:00
PKEuS 141d2ac215 Refactorization: Improved internal implementation of severity and certainty levels
Backported from LCppC.
2021-02-24 22:00:06 +01:00
PKEuS cf1937294a Refactorization: Removed unnecessary \n and spaces in strings
Merged from LCppC.
2021-02-20 12:58:42 +01:00
PKEuS 25678a9faf Refactorized CheckStl::string_c_str(), fixing some false negatives by supporting member functions and overloads
Merged from LCppC.
2021-02-20 12:52:39 +01:00
Ken-Patrick Lehrmann 4e35f19659
10153: Check that string.find() is compared with 0 before recommending starts_with() (#3099) 2021-01-31 12:05:38 +01:00
Simon Martin 9d10f4f572
Ticket #10028: Properly simplify auto variables' initialization. (#3079) 2021-01-23 17:56:58 +01:00
Paul Fultz II d05acf3c41
Fix issue 10120: FP: containerOutOfBounds, regression (#3064) 2021-01-21 19:50:57 +01:00
abhijit-sawant b97387db66
Made missing comparison in loop check more generic (#3048) 2021-01-18 08:11:37 +01:00
Daniel Marjamäki 55262f03ec Fixed #9218 (False positive: Searching before insertion is not necessary (stlFindInsert)) 2021-01-14 22:31:43 +01:00
Paul Fultz II b1c56d33ac
Fix issue 9133: Invalid iterator; vector::push_back, functions (#3008) 2021-01-11 18:47:38 +01:00
Paul Fultz II 3b5c558414
Fix issue 10076: ValueFlow: False positive after address of var is taken 'T t = {{&var}};' (#3027) 2021-01-08 10:29:32 +01:00
abhijit-sawant a4a225203c
Fix #9938 (false positive: StlMissingComparison) (#2989) 2021-01-04 10:07:07 +01:00
IOBYTE 765c1ace87
fix #10008 (false negative: knownEmptyContainer with alias in namespace and "using namespace") (#2979) 2020-12-26 13:45:17 +01:00
Paul Fultz II ae6f611df0
Fix issue 9973: False positive: mismatching iterator container, reference (#2893) 2020-11-10 09:38:05 +01:00
Paul Fultz II 7b6d3f8061
Fix issue 9907: False positive: knownEmptyContainer after function call with :: (#2814) 2020-09-20 22:37:28 +02:00
Paul 5033fb4418 Fix issue 9869: False positive: knownEmptyContainer when passed to constructor 2020-09-09 22:23:42 -05:00
Paul 7754449fd6 Format 2020-09-06 23:48:05 -05:00
Paul 04c85baf03 Fix issue 8869: false negative: (error) Invalid v.at() argument nr 1 2020-09-06 23:46:31 -05:00
Paul Fultz II 32df807b22
Fix issue 9783: wrong lifetime analysis temporary assigned to object (#2711) 2020-09-02 07:13:15 +02:00
Paul Fultz II dea5a23c34
Improve check: check for known empty containers passed to algorithms (#2768) 2020-09-02 07:11:23 +02:00
Daniel Marjamäki 8e79b0c8bc astyle formatting
[ci skip]
2020-09-01 20:00:04 +02:00
Paul Fultz II 1c5f496350
Fix issue 8373: false negative: invalid iterator (#2761) 2020-08-31 08:46:56 +02:00
Paul Fultz II 6ab3c93fb1
Fix issue 9756: false negative: invalid iterator from std::find_if (#2760) 2020-08-28 19:29:09 +02:00
Paul Fultz II 494fff65b7
Add outOfBounds check for iterators to containers (#2752) 2020-08-26 21:05:17 +02:00
Paul Fultz II 46bf2d7d52
Dont diagnose impossible values for iterators (#2755) 2020-08-26 06:58:53 +02:00
Paul Fultz II ac846b96d1
New check: Iterating a known empty container (#2740) 2020-08-22 09:16:26 +02:00
Paul 7776fb82a2 Fix issue 737: new check: Dereference end iterator 2020-08-17 16:36:45 -05:00
Paul a5b0a1c9e2 Evaluate container size in program memory 2020-08-10 20:08:49 -05:00
Paul 26693df788 Use forward analyzer for container forward 2020-08-08 00:10:03 -05:00
Paul 56affc9080 Fix issue 9780: FP: invalidContainer calling push_back after getting the address of the vector 2020-08-06 21:08:30 -05:00
Daniel Marjamäki 25ad22c6af astyle formatting
[ci skip]
2020-07-23 10:09:06 +02:00
Paul abeea7b32b Merge branch 'main' into fp-invalid-container-pointer 2020-07-21 13:31:13 -05:00
Paul 831690f89b Use parseDecl instead 2020-07-16 14:33:39 -05:00
Paul 423dcfd005 Fix issue 9796: False positive: lifetime, pointer item is not deallocated by pop_back 2020-07-15 12:22:36 -05:00
Paul caabe56f14 Handle FPs: mutexes being locked at different scopes 2020-07-12 21:31:53 -05:00
Daniel Marjamäki 27841d6b81 Fixed #9795 (False positive: Local lock is not ineffective, mutex is locked in thread also.) 2020-07-10 19:24:45 +02:00
Paul 82b91869ee Extend mutex checking for more locking patterns 2020-06-26 15:06:20 -05:00
Daniel Marjamäki af6e76d623 Fixed #9787 (Better handling of user defined literals) 2020-06-25 22:06:34 +02:00
Paul 3c10a9c659 Update message 2020-06-24 18:09:30 -05:00
Paul f7029e62ac Check for mor FPs 2020-06-17 17:06:06 -05:00
Paul 18225ee27e Update text and change to warnings 2020-06-16 10:32:39 -05:00
Paul 172537807b Add check for incorrect usage of mutexes and lock guards 2020-06-15 19:40:54 -05:00
Paul Fultz II 86ed860d26
Fix issue 9548: False negative: Mismatching iterators when inserting into a vector (#2595) 2020-06-06 17:54:56 +02:00
Paul Fultz II 3109d16b42
Fix issue 9742: FP iterators3 for address of reference to vector in struct (#2668) 2020-06-01 08:53:08 +02:00
Paul Fultz II 4270819728
Fix issue 9713: FP invalidContainerLoop when modifying container and immediately exiting the loop (#2659) 2020-05-23 07:14:45 +02:00
Paul Fultz II 6162ebd608
Fix issue 9714: FP invalidContainer related to auto and std::string::insert (#2660) 2020-05-23 07:13:55 +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
Paul Fultz II efdc5f5c4e
Fix issue 9435: False negative: invalidContainer when using range for loop (#2587)
* Fix issue 9435: False negative: invalidContainer when using range for loop

* Use ast

* Make string const
2020-04-04 11:47:02 +02:00
Daniel Marjamäki 1fd85c0ae8 Fixed #9630 (False positive: in stlIfFind checking, if with initializer is not handled properly) 2020-02-18 19:02:54 +01:00
Paul Fultz II 95a48eac67
Fix issue 9598: False positive: Using iterator to local container that may be invalid for loop handling (#2539) 2020-02-16 15:56:52 +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
Ken-Patrick Lehrmann 5f73e1cb32 Fix 9546: properly check that the bound is the size (#2475)
Previously, as the check was done on the token and not on the ast,
`i <= v.size()` and `i <= v.size() - 2` would both raise the same
warning.

This patch fixes this, but this mean the check is only done when the
condition if `i <= v.size()`. Any other (more complex) condition is
ignore, and so we have false negative for instance with
 `i <= v.size() + 1`.
2020-01-05 16:24:25 +01:00
orbitcowboy ce0f7e201d Formatted 'wxwidgets.cfg: Added support for more interfaces.' 2020-01-04 00:26:39 +01:00
orbitcowboy 1e0f8ae9b4 Running astyle [ci skip]. 2020-01-04 00:06:27 +01:00
Paul Fultz II 30b9455e89 Fix issue 9556: FP mismatchingContainers: raw pointer comparison (#2465)
* Fix issue 9556: FP mismatchingContainers: raw pointer comparison

* Formatting
2020-01-01 12:02:21 +01:00
Paul Fultz II 82c91f9484 Fix issue 9550: False positive: Same iterator is used with containers 'x' that are defined in different scopes (#2463) 2019-12-31 08:09:04 +01:00
Daniel Marjamäki 31bddb6ae0 astyle formatting
[ci skip]
2019-12-26 15:48:29 +01:00
Paul Fultz II 42d44f02a2 Use lifetime analysis for checking mismatching containers (#2456)
* Use lifetimes to check for mismatching containers

* Fix error messages

* Format

* Remove unused variables

* Fix configuration and track iterators through algorithms

* Fix iterator value types in qt config

* Fix library issue with QStringList

* Remove unused functions

* Fix cppcheck errors
2019-12-25 09:32:50 +01:00
Daniel Marjamäki 252c3a17fa Fixed #7107 (False positive iterators - using alias for container) 2019-12-20 12:13:26 +01:00
Paul Fultz II f77347d7b4 Fix crash 9492: Crash in FwdAnalysis::checkRecursive() (condTok is nullptr) (#2411)
* Fix crash 9492: Crash in FwdAnalysis::checkRecursive() (condTok is nullptr)

* Formatting
2019-12-01 14:53:03 +01: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
Paul Fultz II dc201d110d Fix issue 9274: false negative: (error) Buffer is accessed out of bounds (std::string, std::wstring) 2019-09-03 06:43:54 +02:00
Paul Fultz II 88d194214f Fix FP with invalidContainerRef (#2141) 2019-09-03 06:41:35 +02:00
Paul Fultz II cb509f1a8b Fix issue 4845: alias to vector element invalid after vector is changed (#2113)
* Try harder to track ref lifetimes

* Dont add lifetimes for references

* Use correct token

* Check for front and back as well

* Improve handling of addresses

* Formatting

* Fix FP
2019-09-02 06:58:09 +02:00
Paul Fultz II 121093658d Fix issue 9202: False positive: std::array, size is a constant (#2132) 2019-09-01 09:44:34 +02:00
Daniel Marjamäki 996daaee4e STL: Fixed outOfBounds false positive 2019-08-24 15:40:29 +02:00
Paul Fultz II ef714225bb Use library to track container lifetimes 2019-08-15 21:14:54 +02:00
Paul Fultz II 13df5b2413 Fix FP with negative index and negated condition (#2081) 2019-08-14 06:32:31 +02:00
Paul Fultz II c0c6f92221 Fix issue 8431 and 8776: Size of constant string
Fixes these cases:

```cpp
void f(void) {
        const std::string msg="xyz";
        if(!msg.empty()){} // Always true
}
```

And out of bounds access:

```cpp
#include <string>
char fstr1(){const std::string s = "<a><b>"; return s[42]; }
wchar_t fwstr1(){const std::wstring s = L"<a><b>"; return s[42]; }
```
2019-08-12 20:24:16 +02:00
Paul Fultz II 68e8253920 Fix issue 8313 and 7326: Track values of pointer aliases in valueflow 2019-08-12 12:58:53 +02:00
Paul Fultz II 3ec3bd52e0 Fix FP when using a pointer to a container (#2029) 2019-07-24 00:04:49 +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 90a215af0e Rephraze performance message. /would be faster/could be faster/ to indicate that Cppcheck is not _sure_ that it would be faster 2019-07-17 16:06:10 +02:00
Daniel Marjamäki 4d9b1e6c3d Fixed #9094 (Tokenizer::createLinks2 problem with 'x%x<--a==x>x') 2019-05-11 19:11:40 +02:00