Commit Graph

870 Commits

Author SHA1 Message Date
Paul Fultz II 904d52acac
Fix issue 10004: ValueFlow: pointer value, wrongly set known value (#2931) 2020-12-03 07:15:31 +01:00
IOBYTE 43ce1607c7
fix a large number of valgrind warnings in testrunner (#2920)
Co-authored-by: Robert Reif <reif@FX6840>
2020-11-24 18:21:07 +01:00
Daniel Marjamäki 5e69def679 Code cleanup; Remove unused functions 2020-11-18 20:27:51 +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
Rikard Falkeborn 324e267559
getSizeOf: Handle long double (#2888) 2020-11-11 22:51:17 +01:00
Daniel Marjamäki 7182da5c8e astyle formatting 2020-11-11 09:17:54 +01:00
Paul Fultz II bd7e915c20
Add generic reverse valueflow (#2878) 2020-11-10 16:00:55 +01:00
Daniel Marjamäki 88a35d2253 Fix CodeQL warning, Multiplication result converted to larger type 2020-11-06 19:50:05 +01:00
Rikard Falkeborn d7a8e25d92
Fix #9647: Set correct enum value (#2856)
* Tokenize: Set varId for variables in enum

Set varIds in enum values. It was previously disabled in 5119ae84b8
to avoid issues with enums named the same as global variables. Take care
to only set varids to variables used to set the value of an enumerator,
not the enumerator itself. This is somewhat complicated by the fact that
at the time this happens, astOperand1(), astOperand2(), astParent() etc
are not set. The current implementation is not perfect, for example in
the code below, y will not have a varid set, but x and z will. This is
deemed sufficient for now.

            int x, y, z;
            enum E { a = f(x, y, z); };

* Fix #9647: Value of enums with variables as init values

C++ allows enum values to be set using constexprs, which cppcheck did
not handle before. To solve this, add a new pass to valueflow to update
enum values after global consts have been processed. In order to do so,
I moved all settings of enum values to valueflow. After setting the enum
values, we need another call to valueFlowNumber() to actually set users
of the enums.

There is still room for improvements, since each pass of
valueFlowGlobalConstVar() and valueFlowEnumValue() only sets variables
that are possible to set directly, and not if setting the value of a
variable allows us to set the value of another. For example

	constexpr int a = 5;
	constexpr int b = a + 5;
	enum E { X = a };
	constexpr E e = X;

Here both b and e will not have their values set, even though cppcheck
should be possible to figure out their values. That's for another PR
though.

This was tested by running test-my-pr.py with 500 packages. The only
difference was one error message in fairy-stockfish_11.1, where cppcheck
now printed the correct size of an array instead of 2147483648 which I
assume is some kind of default value. In that package, using a constexpr
when setting enum values is common, but as mentioned, there was no
change in the number of warnings.
2020-10-22 07:45:04 +02:00
Paul Fultz II 64638d82bb
Fix issue 9945: FP: containerOutOfBounds (#2845) 2020-10-22 07:41:52 +02:00
Armin Müller 08cef9e815
Typos found by running "codespell" (#2846) 2020-10-15 19:24:13 +02:00
Paul Fultz II 047c3ed6ba
Fix issue 9935: FP: knownConditionTrueFalse value flow doesn't account for virtual functions (#2839) 2020-10-09 17:21:27 +02: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 17e562a87f astyle formatting
[ci skip]
2020-10-03 11:02:11 +02:00
Paul 828a5e2326 Fix issue 9930: valueFlowLifetime hang 2020-10-03 11:01:53 +02:00
Paul Fultz II d9eacaecbb
Fix issue 9842: ValueFlow: wrong handling of ?, seems to think that the whole expression is a condition (#2821) 2020-09-23 07:45:03 +02:00
Oliver Stöneberg 7189b303ae
fixed some modernize-loop-convert clang-tidy warnings (#2815) 2020-09-21 19:30:47 +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 c2e8051196
Fix issue 9904: False positive: duplicateCondition when modifying variable in lambda (#2811) 2020-09-18 07:44:26 +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 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
Paul Fultz II bb7164171c
Fix issue 9894: ValueFlow: wrong known value below while with assignment (#2804)
* Fix issue 9894: ValueFlow: wrong known value below while with assignment
2020-09-14 08:03:25 +02:00
Daniel Marjamäki 600538a325
Merge pull request #2793 from Ken-Patrick/mixedoperators
Fix false positives with condition with || and &&
2020-09-11 10:11:31 +02:00
Daniel Marjamäki 92d65a1824 astyle formatting 2020-09-11 08:51:12 +02:00
Ken-Patrick Lehrmann a114bf0293 Fix false positives with condition with || and &&
The value of something in the middle of a condition with mixed || and &&
gives no information on which branch will be taken.
For instance with:
```
int f(int a, int b, bool x) {\n"
  if (a == 1 && (!(b == 2 && x))) {
  } else {
    if (x) {
    }
  }

  return 0;
}
```
We can enter the if part whether x is true or false, and similarly,
enter the else part whether x is true or false. Same thing with the
value of b.

This fixes the following false positive with above code:
```
:4:13: style: Condition 'x' is always true [knownConditionTrueFalse]
        if (x) {
            ^
:2:33: note: Assuming that condition 'x' is not redundant
    if (a == 6 && (!(b == 21 && x))) {
                                ^

```
2020-09-10 23:27:39 +02:00
Paul bb9dbaa8f5 Format 2020-09-09 21:32:07 -05:00
Paul 75b955b9c6 Fix issue 9833: False positive: Division by zero when using pointer to struct 2020-09-09 21:29:26 -05:00
Paul Fultz II 34d65e25d6
Merge branch 'main' into lifetime-subfunction 2020-09-09 12:02:02 -05:00
Daniel Marjamäki 687b44dbb7 Token: add flag for splitted variable declaration with initialization 2020-09-09 16:22:47 +02: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 965fea370f Formatting 2020-09-08 21:55:53 -05: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 8c425790f4 Merge branch 'main' into lifetime-subfunction 2020-09-08 13:18:01 -05:00
Daniel Marjamäki 18e99176e5
Fix issue 9883: endless recursion in getLifetimeTokens (#2786) 2020-09-08 20:14:54 +02:00
Paul Fultz II 5099ca3c8b
Fix issue 9882: segfault in ForwardTraversal (#2785) 2020-09-08 20:14:10 +02:00
Paul d5489fd1f0 Fix issue 9883: endless recursion in getLifetimeTokens 2020-09-08 11:33:29 -05:00
Paul 1be67ea008 Merge 2020-09-08 11:00:57 -05:00
Daniel Marjamäki 0c6dc84cbb astyle formatting
[ci skip]
2020-09-07 10:56:02 +02: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
Daniel Marjamäki c7aed8bd0e astyle formatting 2020-09-06 07:47:17 +02:00
Daniel Marjamäki b0b31feadd fix ubsan errors 2020-09-05 21:09:11 +02:00
Daniel Marjamäki a102574e3f astyle formatting 2020-09-05 08:00:51 +02:00
Paul Fultz II cc2bc74084
Track lifetime for lambdas with explicit capture (#2776) 2020-09-05 07:56:01 +02:00
Paul bb37b07def Extend lifetimes to subfunctions 2020-09-04 11:56:34 -05:00
shaneasd 84dd0c961f
False positive dynamic_cast auto variable which has been checked against null (#2769) 2020-09-04 07:06:26 +02: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
Daniel Marjamäki 8e79b0c8bc astyle formatting
[ci skip]
2020-09-01 20:00:04 +02:00