Commit Graph

334 Commits

Author SHA1 Message Date
Paul Fultz II 3874c546cc
Fix 10641: FP invalidLifetime with compiler-generated constructor (#3609) 2021-12-07 07:43:25 +01:00
Rikard Falkeborn 1a50146745
autovarInvalidDeallocation: Fix fp with impossible value (#3604)
daca reports new false positives after db4f94fdfe on the form:

	void f() {
	    char *ptr = malloc(10);
	    char *empty_str = "";
	    if (ptr == NULL)
	        ptr = empty_str;
	    if (ptr != empty_str)
	        free(ptr);
	}

Add a check that the value is not impossible to avoid this.
2021-12-05 15:47:21 +01:00
Paul Fultz II a03e731930
Track lifetimes of lambdas that capture the 'this' variable (#3594) 2021-12-04 17:00:55 +01:00
Rikard Falkeborn db4f94fdfe
Fix #7341: Dealloc string literal (#3586) 2021-11-30 07:31:28 +01:00
chrchr-github ca311ebcdf
ASSERT() on calls to Tokenizer::tokenize() in test code (#3501) 2021-11-29 07:34:39 +01:00
Paul Fultz II 57f5b19b34
Fix 7812: False negative: return pointer of local variable (#3583)
* Fix 7812: False negative: return pointer of local variable

* Format

* Add test case for 3029

* Format
2021-11-28 15:25:21 +01:00
chrchr-github 9c31e0ce54
Fix #10393 FP returnDanglingLifetime (#3562) 2021-11-15 20:36:38 +01:00
Paul Fultz II c057dcce0f
Fix 10592: False positive: returnDanglingLifetime (#3557) 2021-11-11 08:00:05 +01:00
chrchr-github 629f883408
Fix #10097: autovarInvalidDeallocation with pointer to std::array (#3529) 2021-11-08 20:31:16 +01:00
Paul Fultz II 6338c2396c
Fix 10589: False positive: danglingLifetime for moved unique ptr (#3547) 2021-11-06 19:08:19 +01:00
Paul Fultz II b835744a81
Fix 10585: FP danglingTemporaryLifetime recent regression (#3544)
Fix 10585: FP danglingTemporaryLifetime recent regression
2021-11-04 09:24:24 +01:00
Paul Fultz II d3f0aa5b34
Fix 10033: false negative: danglingTemporaryLifetime with usage of reference from nested object not detected (#3542) 2021-11-01 19:23:15 +01:00
Paul Fultz II 7d7584b456
Fix 10575: Improve check; lifetime, struct member points to local data (#3541) 2021-11-01 19:22:21 +01:00
Paul Fultz II e998cd13ca
Partial fix for 10393: FP returnDanglingLifetime when constructing string from iterators [inconclusive] (#3536) 2021-10-30 09:06:36 +02:00
Paul Fultz II 876702c4f2
Fix 10098: false negative: 'Reference to temporary returned.' not detected with class (#3509) 2021-10-15 10:59:40 +02:00
Paul Fultz II 25eb0ab5bc
Find dangling pointers to unique_ptr (#3486) 2021-10-06 08:46:25 +02:00
Paul Fultz II 8668d445c7
Add support for string_view (#3480) 2021-10-05 08:28:19 +02:00
KenPatrickLehrmann 61cddabe74
Fix FP due to namespace scope (#3475) 2021-10-04 23:16:16 +02:00
chrchr-github 2d3b8d7003
Add regression test for #10473 (#3457) 2021-09-13 20:46:39 +02:00
Paul Fultz II 28bc717cbe
Fix 10163: false positive: lifetime for r is not same as for seq 'for (auto& r: seq)' (#3442) 2021-09-04 19:53:14 +02:00
Paul Fultz II a9a6e4c086
Regression test for 9811: False positive: Reference to temporary returned (#3434) 2021-08-31 09:48:50 +02:00
Paul Fultz II 7ce17f076a
Fix 10318: iterator converted to type, wrong scope check (#3433) 2021-08-31 09:48:23 +02:00
Paul Fultz II 8ddc5764f8
Fix 10425: False positive: returnDanglingLifetime when taking address of captured variable (#3415) 2021-08-25 04:06:03 +02:00
Paul Fultz II fdaeaacc40
Symboldatabase: Improve valuetypes for containers, iterators, and smart pointers (#3398) 2021-08-14 19:00:58 +02:00
Paul Fultz II 7f358b2bed
Format with uncrustify (#3388) 2021-08-07 20:51:18 +02:00
Paul Fultz II 4626f9ed76
Fix FP when returning a pointer to a container (#3379) 2021-08-04 08:16:31 +02:00
Daniel Marjamäki b1547a387e astyle formatting
[ci skip]
2021-07-21 20:13:38 +02:00
Paul Fultz II 8efe1d4ab4
Find reference to dangling unique ptr (#3344) 2021-07-20 21:30:27 +02:00
Paul Fultz II f55a4563f9
Fix 10308: danglingTemporaryLifetime confused by function parameter (#3292) 2021-06-09 09:21:03 +02:00
Paul Fultz II 95c872b1ec
Fix todo test for returning a dangling reference (#3284) 2021-06-04 17:15:39 +02:00
Paul Fultz II db5f00a16a
Fix issue 10214: FP: danglingTempReference doesn't account for reference lifetime extension (#3220)
* Fix issue 10214: FP: danglingTempReference doesn't account for reference lifetime extension
2021-04-19 14:20:29 +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
Paul Fultz II 0ecac8e23b
Fix issue 10090: ValueFlow: Wrong lifetime, pointer member is not allocated on stack (#3109) 2021-02-03 10:22:31 +01:00
shaneasd 53734a3da1
Test for return address of reference (#2991) 2020-12-28 10:50:42 +01:00
Daniel Marjamäki 9c27ba835d astyle formatting 2020-11-19 21:25:49 +01:00
Paul Fultz II e8c1c792a5
Fix issue 9987: false positive: danglingTempReference with && variable and assignment (#2907) 2020-11-17 06:52:12 +01:00
Paul Fultz II 372161c89b
Fix issue 9939: False positive: Reference to temporary returned (static variable) (#2840) 2020-10-06 09:16:54 +02:00
Daniel Marjamäki bf236e91d7 Fixed #9918 (False positive: autoVariable pointer is NULLed later) 2020-09-28 22:48:57 +02:00
Paul Fultz II 857722f859
Fix issue 9711: FP knownConditionTrueFalse for variable modified via pointer (#2813) 2020-09-20 14:27:09 +02:00
Paul Fultz II e5d0ffdbe7
Fix issue 9900: False positive: Returning lambda that captures local variable 'x' that will be invalid when returning. (#2809) 2020-09-17 08:33:52 +02:00
Paul Fultz II 782684a7cc
Fix issue 9530: False positive: Reference to temporary returned when using initializer lists (#2796) 2020-09-17 08:33:16 +02:00
Paul Fultz II 11c99d7387
Fix issue 9880: False positive: danglingLifetime (#2810) 2020-09-17 07:23:38 +02:00
Paul Fultz II ebbff08932
Fix issue 9899: False positive: Non-local variable will use object that points to local variable (#2808) 2020-09-15 07:11:52 +02:00
Daniel Marjamäki d46b9cec5f
Merge pull request #2795 from pfultz2/fp-lifetime-temp-function-obj
Fix issue 9889: False positive: Using reference to dangling temporary with function object
2020-09-11 09:05:43 +02:00
Paul 71bc79ac28 Fix issue 9889: False positive: Using reference to dangling temporary with function object 2020-09-10 22:58:17 -05:00
Paul b26c581556 Fix issue 9888: False positive: Using reference to dangling temporary with std::move 2020-09-10 22:38:31 -05:00
Paul Fultz II 34d65e25d6
Merge branch 'main' into lifetime-subfunction 2020-09-09 12:02:02 -05:00
Daniel Marjamäki b1401c6536
Merge pull request #2789 from pfultz2/smart-ptr-constructor
Fix issue 9496: False negative: Dereferencing returned smart null-pointer
2020-09-09 08:16:30 +02:00
Paul 382408f59e Fix issue 9496: False negative: Dereferencing returned smart null-pointer 2020-09-08 21:54:38 -05:00
Paul 8d7088aa24 Fix issue 9835: False negative: Return reference to temporary with const reference 2020-09-08 18:30:45 -05:00
Paul 1be67ea008 Merge 2020-09-08 11:00:57 -05:00
Paul Fultz II 362ab44c40
Fix issue 9646: False negative: Return reference to temporary with const reference (#2782) 2020-09-07 10:52:54 +02:00
Paul 786672e19d Format 2020-09-06 21:59:21 -05:00
Paul c7a5d3c5f1 Fix FPs 2020-09-06 21:58:36 -05:00
Paul Fultz II cc2bc74084
Track lifetime for lambdas with explicit capture (#2776) 2020-09-05 07:56:01 +02:00
Paul 264c0cae8b Formatting 2020-09-04 11:59:30 -05:00
Paul bb37b07def Extend lifetimes to subfunctions 2020-09-04 11:56:34 -05:00
Paul Fultz II 03cefd5d70
Fix issue 9853: False positive: returnReference when using a pointer to container (#2765) 2020-09-02 20:01:08 +02: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 0a718694af
Fix issue 9852: False positive: danglingTemporaryLifetime when returning a vector of vectors (#2766) 2020-09-01 11:21:29 +02:00
Paul 0cc1f69862 Fix issue 9770: FP returnDanglingLifetime for class method taking const char* and returning std::string 2020-08-05 23:17:35 -05:00
Paul f7029e62ac Check for mor FPs 2020-06-17 17:06:06 -05:00
Paul Fultz II bbe6157e16
Fix issue 9712: False positive: Returning pointer to local variable when return line implicitly cast to return type (#2662) 2020-05-23 23:12:00 +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 453a69dd8c
Fix issue 9677: False positive: returning pointer to oject that will not be invalid (#2607)
* Fix issue 9677: False positive: returning pointer to oject that will not be invalid

* Formatting
2020-04-18 09:23:10 +02:00
Paul Fultz II 8fd0839fea
Add regression test for 9534: False positive: Returning pointer to local variable 'x' that will be invalid when returning. (#2596) 2020-04-06 16:02:10 +02:00
Paul Fultz II 71deaaeb18
Fix issue 9608: False Positive: returnDanglingLifetime with braced-init-list (#2583) 2020-04-02 10:17:58 +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 5462e43161
Fix issue 9639: False positive: Returning object that points to local variable that will be invalid when returning (#2576)
* Follow reference when tracking local variables

* Fix issue 9639: False positive: Returning object that points to local variable that will be invalid when returning
2020-03-23 22:54:53 +01:00
Paul Fultz II e55ddacd18
Fix issue 9597: False positive: Reference to temporary returned if explicitly casted to base class (#2531) 2020-02-11 11:41:41 +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
Paul Fultz II 9cb39b1d7e Fix issue 9482: False positive: Reference to temporary returned using trailing return type (#2413) 2019-12-01 15:10:02 +01:00
Daniel Marjamäki 937c82efbe AST: initializer list with lambda 2019-11-27 06:44:58 +01:00
Daniel Marjamäki ab2274b8ad AST: lambdas and scopes in expressions 2019-11-23 21:36:36 +01:00
Paul Fultz II 4ebf54d090 Fix issue 9437: Dont assume init list constructor for strings (#2366)
* Fix issue 9437: Dont assume init list constuctor for strings

* Update the schema

* Add documentation
2019-11-17 03:22:04 +01:00
Rikard Falkeborn af170c8e3f Add regression test for #8923 (#2348)
This was fixed in 5a32d2d017. Add a regression test
with array arguments.
2019-11-11 07:15:24 +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 650408a210 Improve librarys config of substr to improve checking cases in issue 8021 (#2338) 2019-11-08 08:02:33 +01:00
Paul Fultz II 2e955d0f22 Fix issue 9453: False positive: danglingLifetime, address of array argument (#2335) 2019-11-07 09:33:17 +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
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 62d972061b astyle formatting
[ci skip]
2019-10-14 19:41:51 +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
Daniel Marjamäki 9f40341ba8 SymbolDatabase: Hardcoded handling for std::make_shared and std::make_unique , todo: library configuration would be better than hard coding 2019-10-08 17:19:24 +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 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 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 1afd56e964 Fix issue 8785: ValueFlow: Track pointer alias
This fixes the issue by making `ProgramMemory` keep track of values based on the conditions.

It also removes the `deadpointer` check since it duplicates the `invalidLifetime` check.
2019-09-03 17:16:15 +02:00
Paul Fultz II 4f76588f98 Fix issue 9275: False positive: Non-local object uses local variable (#2084) 2019-08-14 20:09:33 +02:00
Paul Fultz II b049fd9303 Improve propogation of lifetimes of function arguments
This will now warn for cases like this:

```cpp
int* f(int * x) {
    return x;
}
int * g(int x) {
    return f(&x);
}
````
2019-07-26 07:02:07 +02:00
Paul Fultz II 60b670babd Fix issue 9219: False positive, returnDanglingLifetime (#2026)
* Check for pointer deref for container methods

* Formatting
2019-07-23 21:59:05 +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
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
Paul Fultz II 66e0f06494 Fixx issue 9163: FP returnDanglingLifetime - returning std::string::find (#1912)
* Fixx issue 9163: FP returnDanglingLifetime - returning std::string::find

* Use simpleMatch
2019-06-24 18:52:17 +02:00