Commit Graph

10115 Commits

Author SHA1 Message Date
Paul 26693df788 Use forward analyzer for container forward 2020-08-08 00:10:03 -05:00
Daniel Marjamäki b263b93f73
Merge pull request #2732 from pfultz2/invalid-container-subobj
Fix issue 9780: FP: invalidContainer calling push_back after getting the address of the vector
2020-08-07 09:52:25 +02: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 5372e93964 Fixed #9825 (redundantAssignment: Do not warn about volatile data) 2020-08-06 22:18:25 +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
Daniel Marjamäki d5b64d9c3a Clarify inconclusive uninitMemberVar warning in copy constructors, it's in general a good idea to copy all the data. 2020-08-05 13:57:40 +02:00
Daniel Marjamäki 7a85b8e452 Do not ask that calculation is clarified when different order would be invalid 2020-08-05 13:20:18 +02:00
Jens Yllman 5ba5916a11 clearer name on the test 2020-08-03 10:30:21 +02:00
Jens Yllman 1cc16deba3 test added to show it works after fix 2020-07-30 22:22:54 +02:00
Daniel Marjamäki fab3a8efc8
Merge pull request #2721 from KenPatrickLehrmann/compound_assign_bitshift
Add missing operators <<= and >>=
2020-07-25 09:39:32 +02:00
Daniel Marjamäki 6a839ad511 Fixed #9814 (False positive: functionConst, trailing return type) 2020-07-24 19:40:42 +02:00
Paul 46e008c3e2 Fixed #9816 (False positive: Condition '!b' is always false in nested do-while loop) 2020-07-24 08:13:14 +02:00
Daniel Marjamäki 53e11ead8f Fix Cppcheck warning: unused variable in test 2020-07-23 19:50:41 +02:00
Ken-Patrick LEHRMANN a923115710 Add missing operators <<= and >>=
This fixes issues (at least false positives) in code using them.
For instance:

```
unsigned compute(unsigned long long a) {
    unsigned num = 0;
    while (a > 0xFFFFFFFF) {
      a >>= 32;
      num += 32;
    }
    if (a > 0xFFFF) {
      a >>= 16;
      num += 16;
    }
    if (a > 0xFF) {
      num += 8;
    }
    return num;
}
```

would give false positive:
```
cppcheck --enable=style  sl3.cpp
Checking sl3.cpp ...
sl3.cpp:11:11: style: Condition 'a>0xFF' is always false [knownConditionTrueFalse]
    if (a > 0xFF) {
          ^
sl3.cpp:3:14: note: Assuming that condition 'a>0xFFFFFFFF' is not redundant
    while (a > 0xFFFFFFFF) {
             ^
sl3.cpp:11:11: note: Condition 'a>0xFF' is always false
    if (a > 0xFF) {
          ^
```
2020-07-23 14:36:34 +02:00
Daniel Marjamäki 682a6d1c02 Fixed #9017 (Simple classes without side effects not reported as unused) 2020-07-23 11:10:08 +02:00
Daniel Marjamäki 25ad22c6af astyle formatting
[ci skip]
2020-07-23 10:09:06 +02:00
Daniel Marjamäki df99d8aa0a
Merge pull request #2719 from pfultz2/fp-unreachable-alias
Fix issue 9807: False positive: ValueFlow in unreachable code, || lhs is true
2020-07-23 09:52:54 +02:00
Daniel Marjamäki 2fd44fa464
Merge pull request #2710 from pfultz2/fp-invalid-container-pointer
Fix issue 9796: False positive: lifetime, pointer item is not deallocated by pop_back
2020-07-22 09:24:54 +02:00
Paul abeea7b32b Merge branch 'main' into fp-invalid-container-pointer 2020-07-21 13:31:13 -05:00
Paul dbb410cdae Merge branch 'main' into condition-in-expr 2020-07-21 13:28:59 -05:00
Rikard Falkeborn 7973fd843c Refactor: Simplify checkSignConversion
The loop only checks astoperand1 and astoperand2. Simplify the condition
to loop over these instead of using a stack. Also, add a testcase for
when astoperand2 is negative.
2020-07-20 11:16:56 +02:00
Paul e2a81a382f Track reading aliases during valueflow forward 2020-07-19 23:25:35 -05:00
Daniel Marjamäki 4a76dbb632 Bug hunting; Avoid bailout uninit FP, stream object 2020-07-19 16:54:44 +02:00
Daniel Marjamäki 7e65b561f0 AST: Fix ast for 'for ((..initexpr..);;)' 2020-07-19 11:10:38 +02:00
Daniel Marjamäki e9281babc4 Bug hunting; avoid false positives for structs/classes with constructors 2020-07-18 18:54:21 +02:00
Georgy Komarov 382f21a5c9
Fixed crash on garbage code: comparisson with an empty second operand
This will fix #9774.
2020-07-18 07:02:12 +03:00
Paul 831690f89b Use parseDecl instead 2020-07-16 14:33:39 -05:00
Daniel Marjamäki 47ff29f1c8
Merge pull request #2708 from pfultz2/multi-mutex-lock
Handle FPs: mutexes being locked at different scopes
2020-07-16 08:35:05 +02: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
Daniel Marjamäki af0db3cc21 Add cppcheck-id for warnings. To start with it's a simple id that changes when file is changed. 2020-07-14 22:30:42 +02:00
Paul 1f74400f13 Merge branch 'revert-mutex-delete' into multi-mutex-lock 2020-07-14 13:05:14 -05:00
Paul 4373404238 Revert "Fixed #9795 (False positive: Local lock is not ineffective, mutex is locked in thread also.)"
This reverts commit 27841d6b81.
2020-07-14 13:04:59 -05:00
Daniel Marjamäki e0be224f4e
Merge pull request #2709 from pfultz2/fp-duplicate-cond-this
Fix FP of duplicateCondition when modifying the this variable
2020-07-13 21:14:58 +02:00
Daniel Marjamäki b2f463dd65
Merge pull request #2707 from Ken-Patrick/fp_pointer_expressions
Fix some false positives when the same expression at different places…
2020-07-13 20:59:22 +02:00
Paul 519f2a537a Format 2020-07-13 13:55:45 -05:00
Daniel Marjamäki 33557012a1
Merge pull request #2706 from rikardfalkeborn/condition-fn-with-sizeof
Fix FN with known condition and sizeof
2020-07-13 20:54:25 +02:00
Daniel Marjamäki cb221e970d Bug hunting: Add test case for CVE-2019-12977. Passing uninitialized struct to function 2020-07-13 20:42:53 +02:00
Daniel Marjamäki 8ba714373f
Merge pull request #2704 from rikardfalkeborn/9635-memleak-with-comma-operator-in-if-statement
Fix #9635 (FP: Memory leak with comma operator in if-statement)
2020-07-13 20:08:57 +02:00
Paul 450bdfedf3 Fix FP of duplicateCondition when modifying the this variable 2020-07-13 12:40:01 -05:00
Daniel Marjamäki 4465d033f6 Bug hunting; When passing uninitialized data to unknown function it is inconclusive if that would be a problem for the function or not 2020-07-13 11:43:11 +02:00
Daniel Marjamäki 0009b4c8af test/bug-hunting/cve.py: Add --slow argument to check slow packages 2020-07-13 11:18:51 +02:00
Paul caabe56f14 Handle FPs: mutexes being locked at different scopes 2020-07-12 21:31:53 -05:00
Ken-Patrick Lehrmann 61ccf888b3 Fix some false positives when the same expression at different places does not have the same value
Typically with
```
int F(int *f);
void F2(int *a, int *b) {
  int c = *a;
  F(a); // modifies *a
  if (b && c != *a) {}
}
```
we would get the following FP:
```
[test.cpp:3] -> [test.cpp:5]: (style) The comparison 'c != *a' is always false because 'c' and '*a' represent the same value.\n
```

I guess it boils down to isSameExpression only checking that the
expression is the same (in the above case, "*a" and "*a" are indeed the
same), but there's not real check on the values.
So the patch here is a bit hackish, and we still have false negatives in
cases with dereferenced pointers.
2020-07-11 14:13:18 +02:00
Rikard Falkeborn d8e7e9176b Fix FN with known condition and sizeof
cppcheck behaved differently if sizeof was to the left or right of the
comparison. In order to fix this, we cannot break the while loop until
all operands have been processed.
2020-07-10 23:39:16 +02: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
Rikard Falkeborn 1e679cc5d1 Fix #9635 (FP: Memory leak with comma operator in if-statement)
When checking for comparisons in if-statements, if there are comma
operators in the if-statement, skip until after the last comma.
2020-07-09 21:31:43 +02:00
Daniel Marjamäki 0c6aabe444
Merge pull request #2703 from rikardfalkeborn/9652-fp-function-call-cast-config
Fix #9652 (fp memleak with function call with cast)
2020-07-08 15:10:41 +02:00
Rikard Falkeborn 4996ec190e Fix #9652 (fp memleak with function call with cast)
When the first argument was (void *)(1), at the start of the second
iteration, arg was pointing to the "1", which caused problems for
nextArgument(), which saw the ")" as the next token and returned
nullptr, signalling that there are no more arguments.

Instead, save the first token in the argument, which makes
nextArgument() do the right thing.
2020-07-08 00:02:39 +02:00
Rikard Falkeborn d5345052ab Fix #9793 (false positive, memleak with lambda)
Skip scopes with lambdas (similar to how checkleakautovar does). In
order to fix this when the lambda is inside a for loop, make
hasInlineOrLambdaFunction() recursive. This should be what all existing
users want.
2020-07-07 21:51:36 +02:00
Daniel Marjamäki 921997c9e9 itc.py; false negative is fixed 2020-07-03 17:50:56 +02:00