Commit Graph

13003 Commits

Author SHA1 Message Date
Paul fec2914700 Add tests for container changes 2020-08-09 22:52:03 -05:00
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 72fa5f2e27 Fixed #9752 (ValueFlow: Uninit after assignment with '&') 2020-08-05 22:57:06 +02: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 10ac0bcf54 changed variable name to match guidelines 2020-07-29 12:13:21 +02:00
Jens Yllman 62f5f248be use simplifyPath() to make sure file name is same as in the checks 2020-07-28 22:19:27 +02:00
Daniel Marjamäki fa32624c93 ValueFlow: Avoid UB in shift when rhs is negative 2020-07-25 14:13:21 +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 b4552dedb0 Fix Cppcheck warning 2020-07-24 19:58:36 +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 a11a0e79e4 Fixed Cppcheck internal warning 2020-07-23 18:54:40 +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 f4a6f8ad07
Merge pull request #2720 from pfultz2/crash-type-scope
Fix crash when typeScope is missing
2020-07-23 09:31:59 +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 0def5d7a9a Reduce variable scope 2020-07-21 19:09:58 -05:00
Paul 3480aba35b Fix crash when typeScope is missing 2020-07-21 14:09:46 -05: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
Paul 5bc5c96c8f Fix cppcheck error 2020-07-21 13:20:39 -05:00
Paul 38e1b57bc9 Use refs 2020-07-21 13:18:45 -05:00
Daniel Marjamäki aad455e1ea Fix compile error 2020-07-21 17:43:12 +02:00
Daniel Marjamäki 453cd93fae update warning hash calculation 2020-07-21 16:00:09 +02:00
Daniel Marjamäki 83be203d44
Merge pull request #2715 from rikardfalkeborn/refactor-use-visitastnodes-more
Refactor use visitastnodes more
2020-07-21 15:26:58 +02:00
Daniel Marjamäki 26c849b732
Merge pull request #2716 from rikardfalkeborn/refactor-use-simple-loop-instead-of-stack-in-checktype
Refactor: Simplify checkSignConversion
2020-07-21 15:26:03 +02:00
Daniel Marjamäki 4ab04db53c Rename 'cppcheckID' to 'hash' 2020-07-21 11:27:03 +02: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
Rikard Falkeborn ed36856451 Refactor: Use visitAstNodes in checkuninitvar 2020-07-20 11:03:52 +02:00
Rikard Falkeborn 9ced26a7a1 Refactor: Use visitAstNodes in checkcondition 2020-07-20 11:03:29 +02:00
Rikard Falkeborn 82fe6193fa Refactor: Use visitAstNodes in checkstring 2020-07-20 10:25:00 +02:00
Rikard Falkeborn 2ace2b006a Refactor: Use visitAstNodes in checkleakautovar 2020-07-20 10:25:00 +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 fe0081496c Bug hunting; Avoid bailout uninit FP, arrays 2020-07-19 16:27:56 +02:00
Daniel Marjamäki 7e65b561f0 AST: Fix ast for 'for ((..initexpr..);;)' 2020-07-19 11:10:38 +02:00
Daniel Marjamäki 3723c708fc ImportProject; Do not fail loading a GUI project that has warning tags 2020-07-19 08:07:10 +02:00
Daniel Marjamäki e9281babc4 Bug hunting; avoid false positives for structs/classes with constructors 2020-07-18 18:54:21 +02:00
Daniel Marjamäki 7cb65b7f67 GUI: Speedup code editor when selecting another warning in the same file 2020-07-18 18:14:55 +02:00
Georgy Komarov 6bc13080ee
Simplify condition 2020-07-18 07:07:20 +03: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
Daniel Marjamäki 58638d7757 Bug hunting; Fix itc.py test 2020-07-17 13:20:31 +02:00
Daniel Marjamäki 7a4e6daecd Fix import GUI project problem 2020-07-17 11:26:03 +02:00
Daniel Marjamäki f2bd603bd3 Bug hunting; Fix TestBughuntingChecks 2020-07-17 11:02:46 +02:00
Daniel Marjamäki 592637af61 Bug hunting; Avoid uninit false positives with simple analysis 2020-07-17 09:05:38 +02:00
Daniel Marjamäki 9af288e1dd Fixed #9724 (GUI: The tags do not work anymore) 2020-07-16 23:03:54 +02:00
Paul 831690f89b Use parseDecl instead 2020-07-16 14:33:39 -05:00
Daniel Marjamäki 0632f86449 Bug hunting; avoid bailout false positives when constructor is called 2020-07-16 16:38:22 +02:00
Daniel Marjamäki 9edbec8594 astyle formatting 2020-07-16 16:36:11 +02:00
Daniel Marjamäki 118e9eb3e2 Better handling of CppcheckID suppressions 2020-07-16 15:27:23 +02: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 6ab4f39f52 GUI: Suppress cppcheck-id 2020-07-15 13:03:07 +02: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 a6d70b9022 Code cleanup, __temp__ files are not needed anymore 2020-07-14 16:54:00 +02:00
Daniel Marjamäki 8d6fd4769b Bug hunting; Terminating analysis 2020-07-14 11:22:42 +02:00
Daniel Marjamäki 176826a1f5 Bug hunting; Avoid false positives 2020-07-14 11:15:26 +02:00
Daniel Marjamäki fe324aea49 Bug hunting; Detect internal error and throw exception 2020-07-14 10:25:00 +02:00
Daniel Marjamäki 6030ab72ab Bug hunting; Avoid some bailout false positives in uninit checker 2020-07-14 08:12:40 +02: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 36b9e545ac Bug hunting; more bailout warnings in uninit check 2020-07-13 20:23:44 +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
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 686a6c7862 Fixed compiler warning 2020-07-03 17:54:55 +02:00
Daniel Marjamäki d2b2bae7bf Fixed #7733 (False positive: scope of the variable can be reduced (variable is used in hidden code)) 2020-07-01 08:24:52 +02:00
Daniel Marjamäki f56a17bf3d Fixed #8858 (FP: identicalConditionAfterEarlyExit when there is #if) 2020-07-01 07:48:32 +02:00
Daniel Marjamäki ddd21a260f Fixed #6978 (False positive: unusedLabel shown for labels that are used in some preprocessor configurations) 2020-06-30 18:26:24 +02:00
Daniel Marjamäki 0583763cc6 Fixed #3088 (False positive: Dont report "struct or union member is never used" for structs with __attribute__((packed)) or #pragma pack(push)) 2020-06-30 11:00:40 +02:00
Daniel Marjamäki 1567ccf97b
Merge pull request #2700 from pfultz2/afterConditionFunction
Extend scope of afterCondition until end of function
2020-06-30 08:28:08 +02:00
Paul c76c03c711 Replace noreturn with macro 2020-06-29 15:54:51 -05:00
Paul 67e06c18a9 Use the already available function scope 2020-06-29 15:36:01 -05:00
Paul a412e3e1f1 Mark syntax error functions as noreturn 2020-06-29 15:33:25 -05:00
Paul 600919f624 Remove redundant conditions 2020-06-29 15:13:06 -05:00
Daniel Marjamäki f34ff9325a Fixed testrunner 2020-06-29 21:53:14 +02:00
Daniel Marjamäki a0770f05e1 Reuse 'extractForLoopValues' in ValueFlow 2020-06-29 21:01:43 +02:00
Paul 07d8cb4f01 Extend scope of afterCondition until end of function 2020-06-29 11:55:59 -05:00
Daniel Marjamäki a49d277e0d Fixed #6471 (FP functionConst - member function modifying member variable after cast (inconclusive)) 2020-06-29 13:09:01 +02:00
Daniel Marjamäki 5164d87a2e Bug hunting; Fixed false positives for containers 2020-06-28 22:49:51 +02:00
Paul d5b6d49d96 Fix issue 9578: false negative: (style) Condition '...' is always false 2020-06-28 15:28:08 -05:00
Daniel Marjamäki b5cd96cbda ExprEngine; Rename variable 2020-06-28 21:36:56 +02:00
Daniel Marjamäki ad5e4fef1f Bug hunting; improved handling of 'malloc' in uninit checker 2020-06-28 21:20:59 +02:00
Daniel Marjamäki 6c588cc3ef Library: Refactoring <alloc> init attribute 2020-06-28 21:01:43 +02:00
Daniel Marjamäki 0e736e0c29 Rename BugHuntingException to ExprEngineException 2020-06-28 17:39:14 +02:00
Daniel Marjamäki d4bd3016da ExprEngine; Improved handling of for loop, loop variable 2020-06-28 17:28:40 +02:00
Daniel Marjamäki c42c751d61 ExprEngine; Fixed testing 2020-06-28 13:41:27 +02:00
Daniel Marjamäki f85cdd3f77 ExprEngine: DataIndex update to get better debug output 2020-06-28 10:52:50 +02:00
Daniel Marjamäki bcaf792e30 Bug hunting; Fix FP for struct with uninitialized members passed to function in C 2020-06-27 22:11:12 +02:00
Daniel Marjamäki c7a8f5217f ExprEngine; Fixed Cppcheck warning 2020-06-27 21:54:38 +02:00
Daniel Marjamäki cd49eb0978 Fix Cppcheck warnings 2020-06-27 20:59:10 +02:00
Daniel Marjamäki d353a4ecba ExprEngine; copy Data => copy arrays 2020-06-27 18:09:43 +02:00
Daniel Marjamäki e6aa96d90f Bug hunting; Improved uninit checking 2020-06-27 14:59:02 +02:00
Daniel Marjamäki 303cadf99f Bug hunting; Improved uninitData warning when unknown function is not configured 2020-06-27 14:29:29 +02:00
Daniel Marjamäki e19ef6ac62 Bug hunting; Improved uninit checking for function calls with constant parameter 2020-06-27 14:15:53 +02:00
Daniel Marjamäki d303510c78 Use value temp.maxTemplateRecursion 2020-06-27 12:57:09 +02:00
Daniel Marjamäki ff5a717fc6 Bug hunting; Avoid false positives for const parameter data 2020-06-27 12:17:11 +02:00
Daniel Marjamäki 57187ef876 ImportProject: Read max template recursion configuration value 2020-06-27 10:34:02 +02:00
Daniel Marjamäki b09bcdc38c Use ValueFlow for compareBoolExpressionWithInt 2020-06-27 08:13:22 +02:00
Daniel Marjamäki 0352a5d32f astyle formatting
[ci skip]
2020-06-27 07:34:48 +02:00
Daniel Marjamäki 1ad70bbeb8
Merge pull request #2697 from pfultz2/unique_lock
Extend mutex checking for more locking patterns
2020-06-27 07:32:26 +02:00
Daniel Marjamäki c3749625f3
Merge pull request #2688 from jpyllman/fix_chklibfunc
not report locally declared functions as missing configuration of --check-library
2020-06-27 06:53:09 +02:00
Daniel Marjamäki 72bdeb9307
Merge pull request #2698 from pfultz2/const-param-casts
Fix issue 9778: False positive: constParameter when returning non-const reference cast
2020-06-27 06:45:30 +02:00
Paul cf475fab51 Fix issue 9778: False positive: constParameter when returning non-const reference cast 2020-06-26 15:47:59 -05:00
Daniel Marjamäki f5ace9ffbe SymbolDatabase; Improved ValueType when container methods items 2020-06-26 22:47:28 +02:00
Paul 82b91869ee Extend mutex checking for more locking patterns 2020-06-26 15:06:20 -05:00
Daniel Marjamäki c5f9e85ee7 GUI: Add configuration for max recursion in template instantiation 2020-06-26 17:12:02 +02:00
Daniel Marjamäki f569bc79f5
Merge pull request #2694 from pfultz2/pch
Add option to disable pch since its broken with ccache
2020-06-26 16:45:38 +02:00
Daniel Marjamäki 98bf0d41aa TemplateSimplifier; Clarify information message when max recursion limit is reached 2020-06-26 12:59:40 +02:00
Daniel Marjamäki 262f44e76a astyle formatting
[ci skip]
2020-06-26 12:56:56 +02:00
Daniel Marjamäki cb8396aaf8
Merge pull request #2696 from pfultz2/getTokenArgumentFunction-ast
Fix issue 9710 and 9767: Use AST to get function from argument
2020-06-26 09:50:18 +02:00
Paul 1bef6ed268 Another check for null 2020-06-25 19:12:01 -05:00
Paul 263a0364cc Avoid null pointer dereference 2020-06-25 17:23:42 -05:00
Paul 720d882b69 Remove known arg 2020-06-25 17:20:20 -05:00
Paul 60c42b17a6 Fix known conditions 2020-06-25 15:46:30 -05:00
Daniel Marjamäki af6e76d623 Fixed #9787 (Better handling of user defined literals) 2020-06-25 22:06:34 +02:00
Paul 1676ad5f45 Fix issue 9710 and 9767: Use AST to get function from argument 2020-06-25 12:54:46 -05:00
Daniel Marjamäki ec8fbb1580
Merge pull request #2682 from pfultz2/check-mutexes
Add new check for incorrect usage of mutexes and lock guards
2020-06-25 16:21:36 +02:00
Paul 18a8b5bc65 Add option to disable pch since its broken with ccache 2020-06-24 18:41:16 -05:00
Paul 3c10a9c659 Update message 2020-06-24 18:09:30 -05:00
Daniel Marjamäki 34468f3c1a Template simplifier; Write information message when recursion limit is reached. 2020-06-24 20:30:03 +02:00
Daniel Marjamäki 693b24d30a Fix testrunner 2020-06-22 14:31:34 +02:00
Daniel Marjamäki ab14d2bc0f exceptRethrowCopy: Fixed FP in Cppcheck 2020-06-22 12:26:41 +02:00
Daniel Marjamäki 9b5986505e AST; Improved ast for variable declaration with assignment 2020-06-22 08:34:31 +02:00
Daniel Marjamäki f792cabc2b ExprEngine; better handling of containers 2020-06-21 21:48:36 +02:00
Daniel Marjamäki 5497e8ed67 ExprEngine; Improved handling of stream read 2020-06-21 20:05:26 +02:00
Daniel Marjamäki 11e2b5ea14 Bug hunting; Timeout 2020-06-21 18:28:07 +02:00
Daniel Marjamäki 65498b5e9a Bug hunting; Fixed hang when there is recursion 2020-06-21 15:16:05 +02:00
Daniel Marjamäki 8ec5605bac
Merge pull request #2689 from Ken-Patrick/9769
9769: Improve value flow for ternary operator
2020-06-21 13:04:43 +02:00
Daniel Marjamäki ff445f9ca2 Bug hunting; Make cve.py happy again 2020-06-21 08:50:27 +02:00
Daniel Marjamäki f270ca1909 ExprEngine; Better handling of function calls 2020-06-20 23:00:39 +02:00
Ken-Patrick Lehrmann 5a3789a23f 9769: Improve value flow for ternary operator
In some cases, the condition of the ternary operator is assigned a known
value after the two possible results, and in such cases, we would not
take the opportunity to assign a value to the ternary operator (and to
the other parents in the ast).
This patch adds this capability.
2020-06-20 10:29:28 +02:00
Ken-Patrick Lehrmann 7065c5598b Try to fix compilation with cppcheck.vcxproj 2020-06-20 09:47:35 +02:00
Daniel Marjamäki af45148e58 ExprEngine; Refactor and improve code. Add tests for increments. 2020-06-19 20:40:20 +02:00
Daniel Marjamäki 06aeac75dc Bug hunting; Fix false negatives 2020-06-19 18:38:02 +02:00
Daniel Marjamäki b4443aa5a0 Suppress exceptRethrowCopy false positive 2020-06-19 18:15:04 +02:00
Daniel Marjamäki 8653c4b3a9 ExprEngine; Fix uninitialized value FP in subfunction when argument is passed by value 2020-06-19 18:05:56 +02:00
Daniel Marjamäki 6ec15b6d7b ExprEngine; Simple handling of increment/decrement 2020-06-19 17:35:35 +02:00
Daniel Marjamäki a5a3738df4 Fixed cve.py 2020-06-19 17:13:35 +02:00
orbitcowboy f60e805798 Running astyle [ci skip] 2020-06-19 16:36:09 +02:00
Daniel Marjamäki c62e345340 Fix Cppcheck warning 2020-06-19 14:11:49 +02:00
Daniel Marjamäki f516bde744 ExprEngine; Fix TODO assertion 2020-06-19 14:05:19 +02:00
Daniel Marjamäki d0ac583b97 Add 'bughuntingchecks' 2020-06-19 13:16:48 +02:00
Daniel Marjamäki cbe038e694 ExprEngine: execute functions in same TU 2020-06-19 10:27:59 +02:00
Jens Yllman 08b0fa21a7 do not report locally declared functions as missing configuration for --check-library 2020-06-18 14:49:19 +02:00
Daniel Marjamäki 542158d0f4 Bug hunting; checking uninitialized struct member 2020-06-18 13:49:11 +02:00
Jens Yllman 9320ac287a only report on functions in --library files 2020-06-18 11:42:07 +02:00
Paul f7029e62ac Check for mor FPs 2020-06-17 17:06:06 -05:00
Daniel Marjamäki 3f8218af1b Removed CheckClass::operatorEq: does not 'belong' 2020-06-17 20:35:43 +02:00
Ken-Patrick Lehrmann c297ed8204 Better handle noreturn or throwing functions in valueflow
Teaching cppcheck about `BOOST_THROW_EXCEPTION` and
`boost::throw_exception`, and using noreturn information from libraries
in value flow.

This fixes false positive nullPointerRedundantCheck with the following
code:
```
void throwexception(int * buf)
{
    if (!buf)
        boost::throw_exception(std::bad_alloc());
    *buf = 0;
}
```
2020-06-17 19:06:14 +02:00
Paul 21f76d62a1 Merge branch 'main' into check-mutexes 2020-06-17 10:45:43 -05:00
Daniel Marjamäki 51a6af299f
Merge pull request #2683 from Ken-Patrick/cast_expandTemplate
Fix handling of c++ casts in template expansion
2020-06-17 09:21:01 +02:00
Daniel Marjamäki 94f92f00fe
Merge pull request #2684 from firewave/precompiled
use precompiled headers if CMake supports it
2020-06-17 07:53:51 +02:00
Daniel Marjamäki d26593321d Fixed Visual Studio compile error 2020-06-16 22:56:01 +02:00
Daniel Marjamäki 4947a3b7ab Bug hunting; review and improve handling of multi dimensional arrays 2020-06-16 22:50:45 +02:00
firewave a49d60f0b3 use precompiled headers if CMake supports it 2020-06-16 19:56:53 +02:00
Ken-Patrick Lehrmann 5c1a2db434 Fix handling of c++ casts in template expansion
Cast were not expanded properly: the `<` was not taken into account in
typeindentlevel, so we would then miss a `>`, resulting in syntaxError.
2020-06-16 19:36:04 +02:00
Paul 18225ee27e Update text and change to warnings 2020-06-16 10:32:39 -05:00
Paul 7c9144ea47 Add to classInfo 2020-06-15 19:43:33 -05:00
Paul 172537807b Add check for incorrect usage of mutexes and lock guards 2020-06-15 19:40:54 -05:00
Daniel Marjamäki 6faad9cd90 Bug hunting; better handling when assigning multidimensional array in for loop 2020-06-15 22:42:45 +02:00
Daniel Marjamäki b36c85d8fd Rename VerifyException to BugHuntingException 2020-06-15 22:07:32 +02:00
Daniel Marjamäki f5fe5ca2dd
9768: Fix ast with throw in the middle of return (#2678)
* 9768: Fix ast with throw in the middle of return

```
int f(bool x)
{
    return x ? 0 : throw 0;
}
```

The `throw` part was not included in the ast, leading to an invalid
ternary operator.

* 8526: Fix ast construction for ternary operator

This tries to decide a bit more properly when ':' can be part of a
ternary operator. More precisely, there are some times when we want to
delay the construction of the ast for ':', so that it is place
accordingly to the matching '?'.

Typically, this fixes an issue with
`return val < 0 ? throw 1 : val;`,
where the ast for ':' would be constructed during as part of the
`throw`, and the ast for `?` would be invalid.

This patch is a bit of a hardcode, stating that we don't expect ':'
inside a throw, unless there is a complete ternary operator in there
(there can't be a range based for loop, a case in a switch). When we
reach ':', we know we are and the end of the `throw`.
2020-06-15 10:36:02 +02:00
Daniel Marjamäki 2b0e4926bc valueFlowAfterAssign: variable initialization 2020-06-14 21:14:05 +02:00
Ken-Patrick Lehrmann 7ddb7aef7d 8526: Fix ast construction for ternary operator
This tries to decide a bit more properly when ':' can be part of a
ternary operator. More precisely, there are some times when we want to
delay the construction of the ast for ':', so that it is place
accordingly to the matching '?'.

Typically, this fixes an issue with
`return val < 0 ? throw 1 : val;`,
where the ast for ':' would be constructed during as part of the
`throw`, and the ast for `?` would be invalid.

This patch is a bit of a hardcode, stating that we don't expect ':'
inside a throw, unless there is a complete ternary operator in there
(there can't be a range based for loop, a case in a switch). When we
reach ':', we know we are and the end of the `throw`.
2020-06-14 18:57:18 +02:00
Ken-Patrick Lehrmann 4023a487ff 9768: Fix ast with throw in the middle of return
```
int f(bool x)
{
    return x ? 0 : throw 0;
}
```

The `throw` part was not included in the ast, leading to an invalid
ternary operator.
2020-06-14 14:49:10 +02:00
orbitcowboy f69ce02c90 Running astyle [ci skip] 2020-06-14 10:06:54 +02:00
Daniel Marjamäki 97fd51edd1 Set version to 2.1.99 / 2.2 dev 2020-06-14 07:16:14 +02:00
Daniel Marjamäki 026bbac975 2.1: Set version 2020-06-13 17:04:26 +02:00
Daniel Marjamäki 37245a8179 Update copyright year 2020-06-13 16:37:12 +02:00
Paul Fultz II 06ed088bd0
Fix issue 9751: Wrong lifetime caused by std::function (#2676) 2020-06-13 10:26:54 +02:00
Paul Fultz II 03b41ac987
Fix issue 9718: False positive: Parameter can be declared const when written to via stream extraction operator (#2677) 2020-06-13 09:20:40 +02:00
Daniel Marjamäki 6600453b44 Try to make Travis happy 2020-06-13 07:45:31 +02:00
orbitcowboy 258d0a6ade Running astyle [ci skip]. 2020-06-12 16:08:40 +02:00
orbitcowboy 9f445fc735 Library: simplified code and added test cases for validating <valid>-tag expressions 2020-06-12 16:06:43 +02:00
orbitcowboy a3d58a9302 std.cfg: Allow scientific floating point notation for '<valid>'-tags 2020-06-12 08:51:33 +02:00
Daniel Marjamäki 3f1f62e078 Fixed #9746 (SymbolDatabase: Wrong valueType for return) 2020-06-10 21:13:53 +02:00
Daniel Marjamäki d31d778bf4 Fixed #9533 (Syntax Error: AST broken, 'for' doesn't have two operands incrementing pointer in initializer) 2020-06-09 20:57:00 +02:00
Paul Fultz II 0c659a1499
Fix incorrect logic for condition (#2675) 2020-06-09 08:16:53 +02:00
Daniel Marjamäki 6d796b434e Fixed #9731 (ValueFlow: does not handle many assignments well) 2020-06-08 21:17:12 +02:00
Daniel Marjamäki 43b30d974f astyle formatting
[ci skip]
2020-06-08 00:50:45 +02:00
Daniel Marjamäki ca8b5f49f3 library: fixed handling of indirect attribute 2020-06-07 20:18:54 +02:00
Simon Martin 1705d096f7
Simplify empty anonymous namespaces. (#2673) 2020-06-07 13:49:04 +02:00
Ken-Patrick Lehrmann a45c7752a5
9185: Don't syntax error on nested lambdas (#2672) 2020-06-07 08:58:12 +02: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
Ken-Patrick Lehrmann 99ff04f617
9757: skip template parameters when computing scope (#2670)
The template parameter is confusing simplifyUsing: it does not compute
properly the scope, and we end up replace "type" in "to_string" with
"void", then later "void" is removed and we have an internal error.
2020-06-06 17:51:15 +02:00
Daniel Marjamäki 44ff22f879 Fixed #9276 (FP literalWithCharPtrCompare) 2020-06-06 17:47:30 +02:00
Daniel Marjamäki 120c572252 Fixed #9750 (Chained stream operation gives uninitvar error) 2020-06-06 15:24:01 +02:00
Ken-Patrick Lehrmann 8c2c81dbcd
Fix some false positive in loop forward analysis (#2669)
* Fix some false positive in loop forward analysis

In cases like:
```
bool b();
void f()
{
    int val[50];
    int i, sum=0;
    for (i = 1; b() && i < 50; i++)
        sum += val[i];
    for (; i < 50; i++)
        sum -= val[i];
}
```
The forward analysis assumed the second loop was entered, and we ended
up with false positive in it:
 `Array 'val[50]' accessed at index 50, which is out of bounds`

* Fix style
2020-06-05 18:06:03 +02:00
Daniel Marjamäki eeda0442fa astyle formatting
[ci skip]
2020-06-01 08:59:34 +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
Daniel Marjamäki 9772770226 Import project: Fix standard 2020-05-31 21:37:02 +02:00
Paul Fultz II eb4754b7d9
Fix issue 9587: False positive: parameter can be declared with const (#2667) 2020-05-31 10:10:10 +02:00
Paul Fultz II eed2e829a7
Revert "Cleanup: Removed Tokenizer::simplifyTokenList2. As a side-effect, rules for "simple" token list are now executed on normal token list." (#2666)
This reverts commit 187cde183d.
2020-05-30 11:23:22 +02:00
PKEuS 187cde183d Cleanup: Removed Tokenizer::simplifyTokenList2. As a side-effect, rules for "simple" token list are now executed on normal token list. 2020-05-29 21:21:07 +02:00
Daniel Marjamäki eb9576cdf8 CLI: 'simple' rules are deprecated, support will be removed in Cppcheck-2.5 2020-05-29 14:20:46 +02:00
PKEuS bf69541369 Visual Studio: Use new files precompiled.h with several common includes for core and testrunner.
- CLI+Core: Reduces build time by 55% from 3:53 to 1:47
- Testrunner: Reduces build time by 27% from 1:40 to 1:13
2020-05-29 12:16:04 +02:00
Daniel Marjamäki 67115491ea Fixed #9739 (Tokenizer: simplifyTypedef: wrong simplification in using) 2020-05-29 11:16:49 +02:00
Daniel Marjamäki 7ff692341e Fixed #9730 (Regression: TEXT macro not handled in windows code) 2020-05-28 22:03:16 +02:00
miltolstoy 79c3af56e4
fix 9296: false negative uninit variable (#2663) 2020-05-28 21:28:18 +02:00
Daniel Marjamäki d64631219b Fixed #9741 (Wrong value for sizeof) 2020-05-28 21:24:48 +02:00
Paul Fultz II c9798590ba
Fix issue 9701: False positive. 3rd expression in for uses comma operator. (#2664) 2020-05-28 07:41:47 +02:00
Daniel Marjamäki 27fc5f1a2f Fix Cppcheck warning 2020-05-27 21:31:40 +02:00
Daniel Marjamäki 208e2c7fdf Clang parser; only set cpp std if path is c++ 2020-05-27 21:06:27 +02:00
Daniel Marjamäki f482eb49cd ExprEngine; Fixed bug. Constraint expressions must be boolean 2020-05-27 19:37:07 +02:00
Oliver Stöneberg 3a90341961
some CMake cleanups and additions (#2639) 2020-05-27 05:15:46 +02:00
Daniel Marjamäki 6a7eada417 Reverted and fixed changes in version.h 2020-05-26 23:29:12 +02:00
Daniel Marjamäki 4d5fe6ec5e astyle formatting
[ci skip]
2020-05-26 23:28:19 +02:00
Daniel Marjamäki 72f9fcefbb Update version '2.0 dev' 2020-05-26 21:25:45 +02:00
Daniel Marjamäki 60c7b66636 Clang import; do not use FileSettings::cppcheckDefines() when Clang parser is used 2020-05-26 20:46:41 +02:00
Oliver Stöneberg 4f68d85633
optimized non-matchcompiled Token::simpleMatch() a bit (#2640) 2020-05-26 20:13:56 +02:00
Daniel Marjamäki dc0b68d505 handle clang type 'x < y::z >' better 2020-05-26 17:37:33 +02:00
Daniel Marjamäki 39fec386a1 Import project: Add stdcpp20 and stdcpplatest 2020-05-26 08:53:37 +02:00
Daniel Marjamäki d70911c801 ImportProject: Read --std settings from vcxproj file 2020-05-25 21:43:24 +02:00
Daniel Marjamäki f7f26ffe90 Tokenizer: Better handling of c alternative tokens in const method 2020-05-25 15:07:23 +02:00
Daniel Marjamäki f7bff1a272 Import project: Avoid NULL pointer dereference 2020-05-24 21:39:18 +02:00
Daniel Marjamäki e448cc68b5 Import project: Speed up if --file-filter has been provided 2020-05-24 21:23:49 +02:00
Daniel Marjamäki ff17cc2e8f astyle formatting
[ci skip]
2020-05-24 10:52:58 +02:00
Daniel Marjamäki 31324573fa Clang import; Update ast dump flags. Use -Xclang. 2020-05-24 10:52:43 +02: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
Ken-Patrick Lehrmann 084529575f
Skip ast validation inside template (#2661) 2020-05-23 21:11:08 +02:00
Daniel Marjamäki 5a4b309e6f Bug hunting: Add 'buffer overflow' check. Detect CVE-2019-19334 2020-05-23 17:50:24 +02:00
Oliver Stöneberg c1f762b861
disabled some Visual Studio warnings (#2635) 2020-05-23 17:42:56 +02:00
Daniel Marjamäki 820a9c29c1 ExprEngine: Return instead of Throw to continue analysis more 2020-05-23 11:43:30 +02:00
Daniel Marjamäki e5a3dc1a0c ExprEngine; Slow processing 2020-05-23 11:31:12 +02:00
Daniel Marjamäki 4e2f8d5d48 astyle formatting
[ci skip]
2020-05-23 07:30:22 +02:00
Daniel Marjamäki 5c3474ec5c Renamed hasReturnFunction to hasNoreturFunction 2020-05-23 07:30:05 +02:00
Oliver Stöneberg 37bc0483a4
made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
Paul Fultz II 0832830a95
Fix issue 9721: ValueFlow: Comparison is always false, but ValueFlow says it is always true (#2658) 2020-05-23 07:15:13 +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
Paul Fultz II 526abd4b52
Fix issue 9738: ValueFlow: handle std::tie better (#2657) 2020-05-22 22:57:20 +02:00
Daniel Marjamäki c86cfdaa50 Fixed #9736 (False positive: knownArgument in assert calls) 2020-05-22 11:49:28 +02:00
Daniel Marjamäki 43b58dbc9e Fixed #9729 (AST: lambda with noexcept) 2020-05-22 11:29:10 +02:00
Daniel Marjamäki ac1ceb85b6 AST: improved AST when expression starts with %char% or %str% 2020-05-22 09:35:55 +02:00
Daniel Marjamäki 4c5310433c astyle formatting
[ci skip]
2020-05-22 08:48:28 +02:00
Daniel Marjamäki ffdf13fcdb AST: A little code cleanup 2020-05-22 08:48:06 +02:00
Paul Fultz II 8301fa8244
Fix issue 8144: valueFlowBeforeCondition: struct (#2645) 2020-05-21 08:47:48 +02:00
miltolstoy a9d8b3495d
feat: add modulo of one check (#9528) (#2650) 2020-05-20 23:01:32 +02:00
PKEuS 662745b504 Fixed several coverity messages 2020-05-20 18:54:16 +02:00
Ken-Patrick Lehrmann a96a879b6d
Fix crash in addons/test/test-misra.py (#2652) 2020-05-20 16:02:13 +02:00
Ken-Patrick Lehrmann 79d3f488da
Pass defines flags when calling clang (#2651) 2020-05-20 14:56:55 +02:00
Daniel Marjamäki 299e11c991 Fixed Cppcheck warnings 2020-05-19 21:55:28 +02:00
PKEuS dc701276de Optimizations to ValueFlow and ForwardAnalyzer:
- Remove errorPath of a value on assignment (this fixes enormous memory consumption for code with many subsequent assignments)
- De-virtualized a simple get function that was virtual for no reason
- Cloned function isAliasOf() for single values to avoid instantiating unnecessary std::list objects (
- Replaced a couple of trivial Token::Match/simpleMatch expressions by direct comparison
- Treat enumerators as literal values
2020-05-19 21:07:04 +02:00
Daniel Marjamäki 64291c6b61 fix Clang execution 2020-05-19 19:17:23 +02:00
Daniel Marjamäki 32e569704b executeCommand in CppCheckExecutor or QCheckThread 2020-05-19 16:04:40 +02:00
PKEuS baca1fbe04 Fixed compilation: Added missing include 2020-05-19 14:32:50 +02:00
PKEuS 22884888fb Optimization: Improved performance of ForwardAnalyzer by adding some pre-checks and combining conditions 2020-05-19 13:48:15 +02:00
PKEuS c155062cf2 Optimization: Speed up SymbolDatabase creation and Tokenizer::findGarbageCode() by using Token::isKeyword() for pre-checks 2020-05-19 13:48:15 +02:00
PKEuS f6788c0472 Fixed Token::isKeyword: Actually set this flag to a reasonable value in all code paths 2020-05-19 13:47:25 +02:00
PKEuS c9d8f607df Optimization: Reduced peak memory usage (30% in my test case) by immediately deleting simplecpp::TokenList while creating the cppcheck TokenList. 2020-05-19 12:08:17 +02:00
amai2012 d78ff975a0 Run dmake 2020-05-19 10:11:56 +02:00
Daniel Marjamäki 37646c9ffb revert accidental mode changes 2020-05-19 10:05:14 +02:00
PKEuS 09a30bd6b5 Optimization: Speed up Tokenizer::findGarbageCode() (by 15% in my test case) by avoiding iterating through token list multiple times 2020-05-19 08:54:47 +02:00
PKEuS a9cea9ad7c Fixed compilation (next attempt): Added more missing includes 2020-05-19 08:53:38 +02:00
PKEuS f0ac0c8675 Optimization: Remove simplecpp::TokenList as soon as cppecheck TokenList was created. This saves memory while checks are running (20% in my test case), although not peak memory 2020-05-19 08:41:05 +02:00
PKEuS ade253a730 Optimization: Reduced memory consumption of token list
- allocate memory for mTemplateSimplifierPointers only if necessary
- reordered member variables in TokenImpl
2020-05-19 08:40:24 +02:00
PKEuS c409daf918 Fixed compilation: Added missing include 2020-05-19 08:38:51 +02:00
PKEuS 4948f85460 Visual Studio: Updated solution
- Enable several compiler warnings again
- Let __cplusplus have a reasonable value
2020-05-19 08:35:13 +02:00
PKEuS d6390dbd14 Optimization: Improved performance of simplifyTypedef for code with lots of typedefs
20% performance gain when checking ExtremeTuxRacer sourcecode (with glext.h available)
2020-05-19 08:35:13 +02:00
Philipp Kloke 32923b7ac5 Refactorization: Fixed a couple of compiler warnings about reusing variable names 2020-05-19 08:35:12 +02:00
PKEuS 793ed68029 Refactorization: Moved code from header to source
- from utils.h to new utils.cpp
- from token.h to token.cpp
- from valueflow.h to valueflow.cpp
- from errorlogger.h to errorlogger.cpp
2020-05-19 08:35:12 +02:00
Daniel Marjamäki 65e9f6210c CLI: Tweak execution of python addons 2020-05-19 08:14:56 +02:00
Daniel Marjamäki 259724d6e3 astyle formatting
[ci skip]
2020-05-18 19:53:35 +02:00
shaneasd 7bfd686f04
Fix #9700 duplicateBranch false positive from missing scope operator :: in ast (#2646) 2020-05-18 19:31:13 +02:00
Daniel Marjamäki f6f489ea49 Try to make AppVeyor happy 2020-05-18 09:51:47 +02:00
Daniel Marjamäki aa7a4b8372 Try to make AppVeyor happy 2020-05-18 08:24:17 +02:00
Daniel Marjamäki a0f2fda53a Addons: If normal python fails, try 'python' 2020-05-18 07:44:46 +02:00
Daniel Marjamäki 2ef538c171 Tweak paths when executing addons in Cppcheck 2020-05-17 21:45:37 +02:00
Daniel Marjamäki 9eda399323 Less strict unknownMacro 2020-05-17 19:12:16 +02:00
Daniel Marjamäki 547d1b158e Fixed #9723 (GUI: inline suppressions does not work for addons) 2020-05-17 16:50:13 +02:00
Daniel Marjamäki 871cf379d5 ExprData: Better handling of ternary operator 2020-05-15 21:34:52 +02:00
Daniel Marjamäki 76f4fae806 Bug hunting; Started to activate some itc tests for uninitialized variables 2020-05-15 20:58:33 +02:00
Daniel Marjamäki 57e9036186 Cppcheck --addon command should use python3 by default. It can be overridden if needed. 2020-05-15 14:33:35 +02:00
Daniel Marjamäki e508950f4f ExprEngine; Activate bug hunting analysis for uninitialized variables/data. This analysis is pretty experimental right now. 2020-05-15 11:25:56 +02:00
Daniel Marjamäki 275c8e84d2 Set development version 2.0.99 2020-05-15 11:15:34 +02:00
versat 2fd2edd3f9 astyle formatting
[ci skip]
2020-05-14 18:18:14 +02:00
Oliver Stöneberg a0317477c9
utils.h: avoid unnecessary string creation in isStringCharLiteral() (#2638)
* utils.h: avoid unnecessary string creation in isStringCharLiteral()

reduces Ir from 541 to 63 in a test

* dmake
2020-05-14 14:45:35 +02:00
Paul Fultz II d123279fc1
Fix issue 9709: ValueFlow: variable value is not known (#2643) 2020-05-14 14:10:32 +02:00
Daniel Marjamäki 0799d74071 Tweak Z3 version checks 2020-05-12 17:01:16 +02:00
Daniel Marjamäki 3e650c311b Remove NEW_Z3 macro 2020-05-12 16:57:07 +02:00
Daniel Marjamäki 046f8eb6c6 ExprEngine: improved handling when lhs/rhs for && has unknown value 2020-05-10 22:50:23 +02:00
Oliver Stöneberg e0e50139cb
cleaned up includes based on include-what-you-use (#2632)
* cleaned up includes based on include-what-you-use

* token.cpp: fixed -Wextra-semi-stmt warning
2020-05-10 16:45:45 +02:00
Daniel Marjamäki dc32f428ff Set Cppcheck version 2020-05-10 11:28:31 +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
Daniel Marjamäki 137f262300 Fix Token::isImpossibleIntValue 2020-05-09 10:30:19 +02:00
Daniel Marjamäki d4169f04d5 Bug hunting; Avoid false warnings for impossible values 2020-05-08 17:42:56 +02:00
Daniel Marjamäki ab8bf81f03 ValueFlow: Try to clarify debug output for impossible values 2020-05-08 16:13:55 +02:00
Daniel Marjamäki 02d88cb191 Travis: Run TestExprEngine tests 2020-05-08 12:21:22 +02:00
Daniel Marjamäki 4779cb124e Fixed #9649 (False positive: uninitialized struct member) 2020-05-07 22:27:18 +02:00
Daniel Marjamäki 00d1091506 Tokenizer: operator handling, fix tests 2020-05-04 23:00:51 +02:00
Daniel Marjamäki 06cb0e99d1 Tokenizer: Fix syntax error when operator* is called 2020-05-04 21:33:30 +02:00
Daniel Marjamäki 8c57055a0b Try to make Travis happy 2020-05-03 20:46:29 +02:00
Daniel Marjamäki b5094f298a Bug hunting; Add new 'incomplete' flag for error messages. Used when analysis is incomplete. 2020-05-03 17:20:38 +02:00
Daniel Marjamäki 4c63940902 Add bug hunting test case for CVE-2019-7156 2020-05-02 22:22:31 +02:00
Daniel Marjamäki 5eeeba97eb SymbolDatabase: Better handling of function pointer function argument 2020-05-02 17:04:54 +02:00
Daniel Marjamäki 56abbc1d42 Fixed segmentation faults 2020-05-01 18:10:18 +02:00
Daniel Marjamäki 34572a40ab Bug hunting: Fixed handling of switch 'case %char%' 2020-05-01 15:15:24 +02:00
Daniel Marjamäki 999ef06156 ExprEngine: Try to handle function with unknown type better 2020-04-30 22:10:30 +02:00
Daniel Marjamäki b27fabaacb Refactoring ExprEngine 2020-04-30 21:49:27 +02:00
Daniel Marjamäki b97250e0fa ExprEngine; Try to handle assignments better 2020-04-30 21:05:34 +02:00
Daniel Marjamäki 5a9e81897a ExprEngine: Document how it works 2020-04-30 12:18:49 +02:00
Daniel Marjamäki e30eabc896 ExprEngine: Fail to execute contract => write error message 2020-04-29 18:30:12 +02:00
Daniel Marjamäki daea5e2d6c Bug hunting: Do not warn about 'Division by zero' when variable is uninitialized 2020-04-29 11:00:33 +02:00
Daniel Marjamäki 5d67fd0e56 Bug hunting: Set 'inconclusive' flag for bailout values 2020-04-29 10:58:01 +02:00
Daniel Marjamäki 3eb19a64cb Removed inline suppression, it was not a FP, use #ifdef differently 2020-04-28 22:29:16 +02:00
Daniel Marjamäki 13e79fdeb6 Temporary inline suppression to hide false positive 2020-04-28 22:21:07 +02:00
Daniel Marjamäki 249a101ec2 Travis: Fix naming 2020-04-28 22:18:02 +02:00
Daniel Marjamäki 12dfd8a5ca GUI: Show missing/added contracts in tab 2020-04-28 22:09:01 +02:00
Daniel Marjamäki dab8b9fd31 ExprEngine: Improved checking of contracts in function calls 2020-04-28 17:16:13 +02:00
Daniel Marjamäki c19a9c2ad9 GUI: Only edit contract for non-bailout warnings 2020-04-27 19:43:38 +02:00
Daniel Marjamäki 2e369cc842 astyle formatting
[ci skip]
2020-04-27 17:35:52 +02:00
Lionel Gimbert ad6be7b122
Enforcing CppCoreGuideline C.35 on virtual class destructor (#2572)
* Enforcing CppCoreGuideline C.35
A base class destructor should be either public and virtual, or protected and non-virtual

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rc-dtor-virtual

* Protected destructor of ciurtual class can be virtual
2020-04-27 09:22:42 +02:00
Daniel Marjamäki f7096a2232 Bug hunting: basic handling of contracts through GUI 2020-04-27 09:08:50 +02:00
Daniel Marjamäki 72e0a4be29 Fixed initializerList warning 2020-04-26 15:24:25 +02:00
Daniel Marjamäki 6d7dd7400d Refactoring; Sort options alphabetically. Removed unused --check-diff functionality. 2020-04-26 10:22:12 +02:00
Daniel Marjamäki 47c998e52d Fixed #9689 (setVarId: wrong varid when 'not' is used) 2020-04-25 14:42:45 +02:00
Daniel Marjamäki 39710f106c Fixed #9693 (Bug hunting: Segmentation fault with --bug-hunting and clangimport.cpp) 2020-04-25 10:13:18 +02:00
Oliver Stöneberg 04bd2bdb74
some sanitizer build fixes and cleanups (#2621)
* cleaned up sanitizer build flags

* exprengine.cpp: work around linker error with Clang and UBSAN
2020-04-24 21:17:06 +02:00
Daniel Marjamäki 3042bbdc3d Bug hunting: Handle early returns faster 2020-04-24 18:51:54 +02:00
Paul Fultz II 2a09465a07
Fix issue 9686: Regression: ValueFlow should handle try/catch better (#2618) 2020-04-22 19:20:03 +02:00
Oliver Stöneberg 1388e9385b
cleaned up setting of compiler options and a few more things in CMake (#2599)
* cleaned up compiler options related code in CMake

* moved cmake_minimum_required() and raised to latest 2.8.x version

* use proper compiler version check / print compiler version

* fixed linking of sanitized builds

* added proper version checks to newer Clang warnings and enabled them / moved tinyxml_objs flags to proper compiler

* disabled -Wdeprecated-declarations for Clang

* compileroptions.cmake: removed unnecessary check for clang++ existence - CMAKE_CXX_COMPILER_ID is determined by CMake

* printInfo.cmake: removed unnecessary message for ANALYZE_ADDRESS - LSAN is part of ASAN and enabled by default

* cleaned up if() comparisons in CMake

* added/adjusted TODOs
2020-04-22 11:04:19 +02:00
Daniel Marjamäki 387f0a268b Clang import: Better bailout for syntax errors when build dir is not used 2020-04-22 10:27:44 +02:00
Paul Fultz II d88557bc18
Rename constArgument to knownArgument (#2616) 2020-04-22 09:13:35 +02:00
Daniel Marjamäki 05dcb9a435 Clang import; Allow Clang import without a Cppcheck build dir 2020-04-21 22:26:34 +02:00
Oliver Stöneberg 1af959af2c
fixed -Wextra-semi-stmt Clang warnings (#2553)
* fixed -Wextra-semi-stmt Clang warnings

* adjusted REDIRECT macro to require a semicolon

* testmathlib.cpp: rolled back accidental change
2020-04-21 17:27:51 +02:00
Daniel Marjamäki bda73600e0 Tokenizer: Improved removal of unused template (#9588) 2020-04-20 20:48:22 +02:00
Daniel Marjamäki da6e0308c5 Fixed #9195 (False positive: shadowFunction when constructor is shadowed) 2020-04-20 18:02:10 +02:00
Zorgovskiy 08fc956990
Fixes issue #9664 (#2614) 2020-04-20 08:59:35 +02:00
Daniel Marjamäki 219180b00a Fixed #9038 (Auto type with explicit pointer symbol detected as integer) 2020-04-19 20:08:47 +02:00
Lukas Grützmacher 095fd2bc62
add command line option to select single project configuration of loaded solution (#2523)
* add command line option to select single project configuration of loaded solution

* Update cmdlineparser.cpp

* Update manual.md

* fix initialization
2020-04-19 18:19:28 +02:00
Daniel Marjamäki e8bbfdbfee Fixed #9559 (Multiple checks to std::atomic are not redundant) 2020-04-19 17:29:40 +02:00
Daniel Marjamäki 3c56ccc33f Fixed #9531 (Syntax Error: AST broken, 'for' doesn't have two operands.) 2020-04-19 17:00:22 +02:00
Paul Fultz II e2efb338b6
Fix issue 9678: False positive: generic valueflow forward analysis (#2611) 2020-04-19 08:28:07 +02:00
Daniel Marjamäki 54978847c5 Fixed #8916 (FP: followVar does not seem to handle non-const method call properly) 2020-04-18 19:54:55 +02:00
Daniel Marjamäki de53f63f76 Fixed #9665 (Tokenizer::setVarId: for loop variables) 2020-04-18 12:08:53 +02:00
Carl Michael Grüner Monzón 7c93f51885
Consider pre{inc,dec}rements on assert checks (#2605)
* Consider pre{inc,dec}rements on assert checks

* Simplify code by using new AST APIs

* Fix assert test with invalid syntax
2020-04-18 09:26:24 +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
Daniel Marjamäki aa1bbf2e62 Fixed #9679 (False positive: use this after free (lambda not executed directly)) 2020-04-17 20:20:45 +02:00
Daniel Marjamäki e4bea02cad Fixed #7578 (varid not set for 'pointer to array' member variable in method) 2020-04-15 20:56:21 +02:00
Daniel Marjamäki 266c8d2c09 Remove temporary daca bailouts 2020-04-15 19:54:56 +02:00
Daniel Marjamäki 98be091d80 Fixed typedef simplification for array of function pointers 2020-04-13 16:28:01 +02:00
Daniel Marjamäki 9ccf068393 astyle formatting
[ci skip]
2020-04-13 13:48:05 +02:00
Oliver Stöneberg 2c1e36e63e
cleaned up includes based on include-what-you-use (#2600)
* cleaned up includes based on include-what-you-use

* check.h: trying to work around Visual Studio 2012 bug

* fixed Visual Studio compilation
2020-04-13 13:44:48 +02:00
Daniel Marjamäki 0747bc7ba3 Clang import; Ensure Function::arg is set 2020-04-13 13:37:34 +02:00
Daniel Marjamäki e1543587e0 Clang import; Bailout if clang reports error message 2020-04-13 12:52:24 +02:00
Daniel Marjamäki 2f5e585e59 astyle formatting
[ci skip]
2020-04-13 12:52:00 +02:00
Daniel Marjamäki adb3588b24 Clang import; Set Variable::typeStartToken and Variable::typeEndToken 2020-04-13 10:45:31 +02:00
Daniel Marjamäki c99867421d Clang import; Fixed dead pointer 2020-04-12 22:41:45 +02:00
shaneasd 82c09f243b
Maybeunusedsupport (#2570)
* Add rudimentary support for [[maybe_unused]]

* Add more test cases. use the symboldatabase rather than reparsing. Fix travis error.

* test review actions

* change var to usage._var
2020-04-12 20:35:54 +02:00
Daniel Marjamäki 97f5c5767e Clang import; Ensure function pointer is created 2020-04-12 20:34:05 +02:00
Daniel Marjamäki 6b579293b6 Clang import; Destructor 2020-04-12 17:27:49 +02:00
Daniel Marjamäki 4dfb793cd2 Clang import; Improved handling of constructor 2020-04-12 17:27:49 +02:00
Daniel Marjamäki 97b04ba9a7 Syntax check: Using keyword in global scope 2020-04-11 17:36:22 +02:00
Paul Fultz II 8b27f1c216
Fix issue 9667: crash: crash in valueflow for weird code where label address is returned (#2602) 2020-04-11 13:56:53 +02:00
Daniel Marjamäki e8e3c2660d Detect syntax error 'x ==> y' 2020-04-11 11:05:27 +02:00
Daniel Marjamäki 32bf53eeda Fixed #9221 (False positive when using an array of lists) 2020-04-10 14:01:15 +02:00
Daniel Marjamäki eff225a09c Use 'static' instead of unnamed namespace for variables 2020-04-10 13:48:38 +02:00
Daniel Marjamäki b67a043e5b Remove unused variable 2020-04-10 13:16:15 +02:00
Daniel Marjamäki 05769e8dcc Code cleanup 2020-04-10 13:14:38 +02:00
Daniel Marjamäki c029d5150c Fixed #9123 (False positive: uninitialized variable) 2020-04-10 12:33:15 +02:00
Daniel Marjamäki 0725c2290c Tokenizer: Do not simplify function pointers to normal pointers as we loose important information 2020-04-10 11:53:32 +02:00
Daniel Marjamäki e0c8118c02 Fixed crash in AST 2020-04-09 17:42:51 +02:00
Daniel Marjamäki d7af52865d ValueFlow: avoid crash when && is used in r-value variable declaration 2020-04-09 14:38:10 +02:00
Daniel Marjamäki e7ddd9cc15 ForwardAnalyzer: Add recursion limit 10000 2020-04-09 12:11:33 +02:00
Oliver Stöneberg aaffd1f761
some cleanups (#2601)
* exclude the *_sanitized fuzz-client dependencies from all as well

* .gitignore: added CMake output folders and removed a duplicated entry
2020-04-09 09:23:31 +02:00
Daniel Marjamäki 8e9d7290b2 Tokenizer::simplifyTypedef: Better handling of r-value references 2020-04-08 22:40:45 +02:00
Achouv 7719e4309d
avoid false positive unused static const struct member (#2598) 2020-04-08 18:09:20 +02:00
Oliver Stöneberg e3b644d877
aligned GCC warnings (#2592)
* excluded oss-fuzz related CMake targets from all

* checkstl.cpp: fixed -Wmissing-declarations warning

* suppress -Wsuggest-attribute=format GCC warnings for tinyxml in CMake for now

* aligned GCC warnings in dmake, CMake and Travis / removed now useless WARNINGS_ANSI_ISO
2020-04-08 14:56:12 +02:00
Paul Fultz II 3773d0e875
Find more redundant conditions (#2597) 2020-04-07 07:15:15 +02:00
Daniel Marjamäki 66ee3a0afc Clang import: Better handling of methods that are defined after declaration 2020-04-06 17:18:52 +02:00
Daniel Marjamäki 8dd0a9241c TemplateSimplifier: Simplification of const types 2020-04-05 13:51:58 +02:00
Daniel Marjamäki 189cf29597 astyle formatting
[ci skip]
2020-04-05 10:57:51 +02:00
Sam Lane 60f9fefcd4
Add Support For Configuring Addon Python Interpreter Version (#2591) 2020-04-05 10:57:28 +02:00
Daniel Marjamäki f01783238e Fixed #9596 (False positive: Returning an integer in a function with a pointer return type auto handling) 2020-04-04 20:03:48 +02:00
orbitcowboy 048b08f5be Running astyle. There are no functional changes [ci skip] 2020-04-04 14:49:08 +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
Oliver Stöneberg 1dd8d4afaf
fixes for Clang and clang-tidy 10 (#2588)
* clang_tidy.cmake: added clang-tidy-10 to program list

* fixed -Wrange-loop-construct Clang warnings

* fixed readability-qualified-auto clang-tidy warnings

* .clang-tidy: actually disable clang-analyzer-* warnings

* .clang-tidy: disabled some new warnings introduced with clang-tidy-10
2020-04-04 11:44:59 +02:00
Daniel Marjamäki ac45bf7af2 Small refactoring 2020-04-04 11:19:39 +02:00
Paul Fultz II 40e1e82a65
Fix issue 9644: Token::astOperand1() cyclic dependency on valid C++ code (#2590)
* Remove check for lambda

* Add test case
2020-04-04 10:55:31 +02:00
Daniel Marjamäki e0acd1abf8 Tokenizer: Report unknown macro that contains '.x=..' argument 2020-04-04 10:32:56 +02:00
Daniel Marjamäki efb583e3d1 astyle formatting
[ci skip]
2020-04-04 10:31:38 +02:00
Paul Fultz II a22a77c1fc
Use library config for unstable containers instead of hardcoded values (#2585)
* Use library config for unstable containers instead of hardcoded values

* Fix xml validation
2020-04-03 13:16:57 +02:00
Paul Fultz II 58e3f19ed8
Fix issue 9662: AST broken, ternary operator missing operand(s) on valid C++ code (#2589)
* Fix issue 9662: AST broken, ternary operator missing operand(s) on valid C++ code

* Add test for issue 9537
2020-04-03 10:04:10 +02:00
Oliver Stöneberg 8968edeabd
avoid unnecessary creation of lists in SingleValueFlowForwardAnalyzer.isAlias() and MultiValueFlowForwardAnalyzer.isAlias() (#2586)
Comparing before and after (Ir per call) when scanning the Cppcheck source:
SingleValueFlowForwardAnalyzer.isAlias()
1246 -> 1101
MultiValueFlowForwardAnalyzer.isAlias()
4202 -> 1617
2020-04-03 09:25:21 +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 6cc58e1086
Set a max for the combination of arguments that can be passsed through valueFlowSubFunction (#2579)
* Set a max for the combination of arguments that can be passsed

* Skip mismatch path ids when computing the cross product
2020-04-01 22:33:09 +02:00
Armin Müller 3ff171e157
Typos found by running "codespell" (#2584) 2020-04-01 14:37:43 +02:00
Daniel Marjamäki 7577bdb1df DACA: Try to avoid some crashes/hangs for the most crazy code so we can focus on most serious bugs first 2020-03-31 11:33:38 +02:00
Oliver Stöneberg 28cd5d7ea2
fixed OSS-Fuzz builds and added CMake targets (#2577)
* fixed compilation of OSS-Fuzz clients

* added preliminary CMake target for fuzz-client - also added *_sanitized targets of dependencies (only available with Clang)

* added oss-fuzz build to Travis CI
2020-03-31 09:33:58 +02:00
orbitcowboy acdc62f8f0 Formatted the code. There are no functional changes [ci skip] 2020-03-26 17:03:21 +01: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 b68d6f9471
Fix crash in valueflow when using local classes (#2575) 2020-03-22 10:12:53 +01:00
Paul Fultz II 7fd3580f21
Dont traverse conditions multiple times (#2574) 2020-03-20 10:37:16 +01:00
Paul Fultz II f2527f5340
Fix crash in valueFlowForLoopSimplifyAfter (#2573) 2020-03-20 07:16:05 +01:00
Dmitry-Me dd5b9f3b82 Resolve sign mismatch warnings 2020-03-19 18:22:55 +03:00
orbitcowboy 637c4e2bc0 wxwidgets.cfg: Added support for more interfaces. 2020-03-15 19:39:23 +01:00
Dmitry-Me ab5835d359
Avoid giant C4267 warning in 64-bit Visual C++ build (#2569) 2020-03-14 14:41:45 +01:00
Daniel Marjamäki 1173186876 Fixed daca@home crash by stopping for unknown macro 'MACRO(a();b();)' 2020-03-12 13:28:09 +01:00
Daniel Marjamäki 900b99fbd8 Tokenizer; Report unknown macro used in function declaration 2020-03-10 20:22:46 +01:00
Daniel Marjamäki 51732e9d75 ForwardAnalyzer: Fixed crash 2020-03-10 10:36:05 +01:00
Daniel Marjamäki f093d23a36 SymbolDatabase: Fixed addArguments 2020-03-09 15:13:50 +01:00
Daniel Marjamäki 1008868506 AST: Better handling of '(type){..}' 2020-03-08 16:46:06 +01:00
Daniel Marjamäki cdee62c032 AST: Fixed AST for struct cast '(struct T){...}' 2020-03-08 16:21:22 +01:00
Daniel Marjamäki f7612fd1a9 ForwardAnalyser; Tweak fix for crash 2020-03-08 12:02:45 +01:00
Daniel Marjamäki 2600dee36c ForwardAnalyzer: Fix crash in cast '(T* &&)', the && does not have operands 2020-03-08 11:49:14 +01:00
Daniel Marjamäki 5376ba1701 AST: Throw validation exception if ternary operator is missing operands 2020-03-07 21:46:38 +01:00
orbitcowboy 85a26802e3 Running astyle [ci skip] 2020-03-01 20:39:00 +01:00
Paul Fultz II 6ea4f60600
Enable valueFlowSubfunction for multiple parameters (#2550) 2020-03-01 16:46:20 +01:00
Daniel Marjamäki 5df6d5bc7c Tokenizer; Warn about unknown macro used in string concatenation 2020-02-28 21:52:01 +01:00
Daniel Marjamäki baa4cee70c Travis: Fixed Cppcheck warning 2020-02-27 10:51:34 +01:00
Daniel Marjamäki 38b570138f AST: Try to handle c++17 for properly 'for (auto [a,b]:c)' 2020-02-27 09:58:53 +01:00
Daniel Marjamäki 84995485ea VarId: fixed varids for 'for (auto [x,y]: xy)' 2020-02-27 07:18:07 +01:00
Oliver Stöneberg 1863ccb0a7
fixed Clang warnings about unused variables (#2554) 2020-02-26 14:52:43 +01:00
Daniel Marjamäki e4937ed621 AST: Fixed wrong AST for cast '(std::vector<int>&&)s->second' 2020-02-25 21:05:49 +01:00
Rikard Falkeborn 9896dce7f2
checkuninitvar: Fix FN with c++ casts (#2549) 2020-02-23 19:53:17 +01:00
Daniel Marjamäki 4f9a0b8420 Refactoring suppressions 2020-02-23 19:49:53 +01:00
Daniel Marjamäki bba340da3d Preprocessor: Tweak parseCommentToken 2020-02-23 18:29:56 +01:00
Daniel Marjamäki 5ed5bf935f astyle formatting
[ci skip]
2020-02-23 18:04:47 +01:00
ghking 5479c7340b
a new method to declare inline suppress which is more readable and more convenient. (#2533) 2020-02-23 18:04:24 +01:00
Daniel Marjamäki ef26b55737 AST: Fix wrong handling for '{scope} (expr)' 2020-02-23 15:01:06 +01:00
Daniel Marjamäki f07a71e3e1 Report unknown macros for pattern '%name% %num%' 2020-02-22 11:57:36 +01:00
Daniel Marjamäki cf10b1a220 fix ast for expression that starts with number 2020-02-21 21:11:32 +01:00
Daniel Marjamäki ec8c733afb Improved Qt simplification 2020-02-21 19:04:21 +01:00
Daniel Marjamäki 388b5118df Fixed bad ast (wrong result from iscast()) 2020-02-21 17:15:33 +01:00
Daniel Marjamäki c514818b65 astyle formatting
[ci skip]
2020-02-21 16:18:41 +01:00
Daniel Marjamäki 26a11e20d0 Revert "Fix crash with garbage code (#2547)"
This reverts commit b25709a492.

The real problem was wrong AST for valid code, I want to fix that instead.
2020-02-21 09:35:01 +01:00
Paul Fultz II b25709a492
Fix crash with garbage code (#2547) 2020-02-21 06:53:28 +01:00
Daniel Marjamäki 6f6f9dd5bc Tokenizer: Throw unknownMacro in non-executable scope 2020-02-19 21:12:58 +01:00
Paul Fultz II 392060aefe
Fix issue 7804: ValueFlow: possible value in second if body (#2543) 2020-02-19 07:55:04 +01:00
Rikard Falkeborn f6e7fb4bd9
Bugfix valuetype for some integer constants (#2545) 2020-02-19 07:51:39 +01:00
Daniel Marjamäki 95ac456e13 Fixed #9582 (false positive "error: Out of bounds access" with std::array and constant) 2020-02-19 07:36:02 +01: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
Daniel Marjamäki afb5590741 New check: delete 'self pointer' that might be used as 'this' and then use some member/method 2020-02-18 18:24:18 +01:00
Dmitry-Me 2168305f4e Better variable name 2020-02-18 18:38:59 +03:00
Daniel Marjamäki 244e291605 Fixed #9640 (clang import: reference parameter) 2020-02-17 18:56:25 +01:00
Armin Müller 75b1ade316
Typos found by running "codespell" (#2542) 2020-02-17 18:28:58 +01:00
Dmitry-Me f6da17eda5 Return early to avoid unneeded computations 2020-02-17 18:56:27 +03:00
Paul Fultz II 3b20684aca
Fix issue 9360: False positive: arrayIndexOutOfBounds when function is called with different array sizes (#2541) 2020-02-17 10:31:08 +01:00
Ken-Patrick Lehrmann 7044c17599
9575: false positive in fclose (#2540)
Fix false positive introduced by
0b7649ca9b

Only return the function token from checkTokenInsideExpression when it
might be one the argument (hence keeping a pointer to one of them).
Otherwise, we can directly skip to the token after the function call.
2020-02-17 10:25:30 +01:00
Daniel Marjamäki 89cb0187d0 Travis: Use simpleMatch for simple pattern 2020-02-16 21:47:46 +01:00
amai2012 efeb7deb7a Run dmake and astyle 2020-02-16 19:58:09 +01:00
Daniel Marjamäki ae0a73a538 Fixed #9618 (isCast flag not set for c++ casts) 2020-02-16 16:46:40 +01:00
Paul Fultz II 921887a281
Use valueFlowGeneric for valueFlowForwardExpression (#2537) 2020-02-16 16:02:22 +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
Daniel Marjamäki a350ed9bc2 Fixed #9023 (AST: wrong lhs for a = b + foo(A::Hash{}(""))) 2020-02-16 13:58:43 +01:00
Daniel Marjamäki 320cb9008f minor tweaks of knownConditionTrueFalse 2020-02-15 20:21:13 +01:00
Daniel Marjamäki 67b495fc50 Fixed #9280 (False positive: unreadVariable on assignment to fixed address volatile struct member) 2020-02-15 17:31:47 +01:00
Daniel Marjamäki 8c0ad6a1b9 Fixed #9555 (False positive (unreadVariable): struct is assigned a value that is never used) 2020-02-15 16:43:06 +01:00
Daniel Marjamäki 569b2a4171 Fixed #9600 (false positive: compareBoolExpressionWithInt with --clang) 2020-02-15 14:45:12 +01:00
Daniel Marjamäki df21da35bf Refactoring; Use std::function instead of template type 2020-02-15 09:20:49 +01:00
Daniel Marjamäki 365da62624 Refactoring; Use std::function instead of template type 2020-02-15 09:14:14 +01:00
Daniel Marjamäki 697ca12d97 Refactoring; Convert templates to normal functions 2020-02-15 08:08:55 +01:00
Paul Fultz II 61d847cac2
Fix issue 9637: false positive: Condition 'i<2U' is always true (#2536) 2020-02-15 07:57:43 +01:00
Daniel Marjamäki e04b9fe4a4 Remove unused functions 2020-02-14 20:37:33 +01:00
Daniel Marjamäki 332279326f checkVirtualFunctionCallInConstructor; Check should be 'style' since there is no UB. Disabled the check temporarily, it should use CTU to determine if the class is a base class 2020-02-14 17:10:12 +01:00
Daniel Marjamäki e31b2f8b73 SymbolDatabase; Set smart pointer type in Variable valueType 2020-02-14 09:40:27 +01:00
Daniel Marjamäki 5f4a900f88 astyle formatting
[ci skip]
2020-02-13 17:04:05 +01:00
Paul Fultz II 7368a54629
Add generic valueflow forward analysis (#2511) 2020-02-13 16:27:06 +01:00
Daniel Marjamäki 1b66820cdb Revert "remove BUG_HUNTING_UNINIT conditionals"
This reverts commit 07a251d783.
2020-02-12 18:54:07 +01:00
Daniel Marjamäki 3ec03b8915 Fixed #9571 (False positive: containerSize) 2020-02-12 18:53:36 +01:00
Daniel Marjamäki 3675f49a53 astyle formatting
[ci skip]
2020-02-12 18:52:50 +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
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
Daniel Marjamäki 07a251d783 remove BUG_HUNTING_UNINIT conditionals 2020-02-10 21:43:06 +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
Daniel Marjamäki bb701fd8be GUI: Tweak ProjectFileDialog: Bug hunting, safe class checking 2020-02-09 21:02:28 +01:00
IOBYTE 4d58d9fc87
fix daca chromium crash (#2527) 2020-02-09 11:19:36 +01:00
Rikard Falkeborn b1c6f2946a
Fix redundant FP assignment with unsigned zero (#2521)
* Refactor isNullOperand out of FwdAnalysis

* Improve isNullOperand

* Fix redundantAssignment FP with unsigned zero

* isNullValue check number

* Enhance isNullOperand to handle c++ casts

Also handle cast of NULL.
2020-02-09 11:16:08 +01:00
Dmitry-Me e9b7e7811b Remove unreachable code and repeated computation 2020-02-05 18:20:43 +03:00
Daniel Marjamäki 25b5304efc GUI: Simple first hack to allow bughunting in the GUI 2020-02-04 21:20:43 +01:00
Daniel Marjamäki ca3095746c Fixed #9594 (False positive: Using argument that points at uninitialized variable when write only) 2020-02-04 18:56:18 +01:00
Dmitry-Me c8df734c07 Merge overlapping patterns 2020-02-04 18:35:30 +03:00
Rikard Falkeborn 488bc9997c
Improve isSameExpression for same valued literals with followvar (#2519)
It allows (for example) cppcheck to detect that the lhs and the rhs are
the same in the following example:

	double g()
	{
        	double a = 1e1
	        return a & 10.0;
	}
2020-02-03 09:35:24 +01:00
Rikard Falkeborn bbfd10a69f
Bugfix Mathlib::isNullValue for hexadecimal numbers (#2517) 2020-02-02 16:40:36 +01:00
Daniel Marjamäki a9f55f4985 CLI: add -isystem include paths when running Clang 2020-02-02 16:35:42 +01:00
Daniel Marjamäki 894497e704 CLI: Checking imported project with clang 2020-02-02 14:36:33 +01:00
Daniel Marjamäki 216698c164 Fix cppcheck project import for Clang parser setting 2020-02-02 12:15:23 +01:00
Daniel Marjamäki 6a2312087c Clang import; Fix crash 2020-02-02 12:13:19 +01:00
Daniel Marjamäki d2dd3930ae GUI: Generate Clang files 2020-02-02 11:05:30 +01:00
Daniel Marjamäki 632dc0f141 GUI: Select parser; Cppcheck or Clang 2020-02-02 10:45:42 +01:00
Daniel Marjamäki 103ecb0257 Refactoring; Avoid templates 2020-02-01 08:52:34 +01:00
Daniel Marjamäki 0e0d88f65e Refactoring; Avoid template<> 2020-02-01 08:39:58 +01:00
Daniel Marjamäki e515f4ab3e Refactoring; Remove unused function 2020-02-01 08:34:36 +01:00
Daniel Marjamäki 0de19acd43 Refactoring; Avoid template<> 2020-02-01 08:32:14 +01:00
Daniel Marjamäki 2b336ac147 Refactoring; stricter lambda capture 2020-02-01 08:28:18 +01:00
Daniel Marjamäki 6c1cc54671 Refactoring; Avoid template<> 2020-02-01 08:24:31 +01:00
Daniel Marjamäki 9eb6925976 Refactoring; Avoid template<> 2020-02-01 08:20:20 +01:00
Rikard Falkeborn ff9c04dc28
Improve isSameExpression for literals (#2514)
Improve isSameExpression() for literals with same value but different
representation, for example  the following different ways of
representing 9 as double: 9.0, 0.9e1 and 0x1.2p3.

With this change, cppcheck can (for example) correctly detect that the
else if statements are always false in the following example:

	void f(double x) {
		if (x < 9.0) {}
		else if (x < 0x1.2p3) {}
		else if (x < 0.9e1) {}
	}
2020-02-01 07:22:41 +01:00
Daniel Marjamäki fb38e87bf4 astyle formatting
[ci skip]
2020-01-31 14:13:52 +01:00
fuzzelhjb b0ce3e4c0c
Support clang tidy (#2512) 2020-01-31 14:10:27 +01:00
fuzzelhjb 074d08e39e
Check specific Visual Studio configurations (#2503) 2020-01-31 07:08:38 +01:00
fuzzelhjb d82da987e5
Support clang tidy (#2486) 2020-01-30 07:14:17 +01:00
Daniel Marjamäki dcee189146 Tokenizer::setVarId: better handling of decltype() 2020-01-29 17:40:22 +01:00
Daniel Marjamäki 18124fe248 Fixed #9591 (SymbolDatabase: decltype) 2020-01-29 17:29:40 +01:00
Daniel Marjamäki 37f4ec5bbe Clang import; Write error message when Clang is not in path 2020-01-27 18:26:17 +01:00
Daniel Marjamäki b1abcc06df Clang import; distinguish static variable 2020-01-27 13:00:52 +01:00
Daniel Marjamäki 830f901206 Fixed #9586 (Valuetype: Wrong type for 'true << 1') 2020-01-27 11:46:59 +01:00
Rikard Falkeborn 8819e19dae Fix #8489 (Fix FN printf argument with parenthesis) (#2508) 2020-01-27 06:55:01 +01:00
Daniel Marjamäki 211d2e336d Clang import; Handle EnumDecl without children 2020-01-26 14:35:08 +01:00
Daniel Marjamäki 66dd985c9d Clang import; Better handling of enums 2020-01-26 07:32:14 +01:00
Daniel Marjamäki 625da9af5c SymbolDatabase: Use range for loop 2020-01-26 07:31:04 +01:00
Daniel Marjamäki a5a294cf13 Code cleanup 2020-01-25 18:11:54 +01:00
Daniel Marjamäki 6f8799023f Clang import; Clang 9 fix 2020-01-25 17:22:22 +01:00
Daniel Marjamäki b6833b525f Clang import 2020-01-25 17:01:17 +01:00
Daniel Marjamäki 6beadd9eb9 Restore cppcheck.cpp 2020-01-25 16:14:56 +01:00
Daniel Marjamäki f911495db3 Clang import; Handle clang-9 while loop better 2020-01-25 16:10:13 +01:00
Daniel Marjamäki 0bab9ba6e3 Clang import; Handle clang-9 range for loop 2020-01-25 14:47:51 +01:00
Daniel Marjamäki afad8b1f5c Clang import; Set Scope::check 2020-01-25 11:59:01 +01:00
Simon Martin 2840173a72 Ticket #9569: Do not substitute type aliases within enum definitions. (#2504) 2020-01-25 10:18:37 +01:00
Simon Martin 224a41361d Ticket #9572: Properly detect designated initializers. (#2496) 2020-01-25 10:14:16 +01:00
Daniel Marjamäki 569523bbef Clang import; Better handling of enums 2020-01-25 09:31:47 +01:00
Daniel Marjamäki b3e192a4e1 astyle formatting
[ci skip]
2020-01-24 21:34:47 +01:00
Daniel Marjamäki 1cabba8755 Clang import; Improved enum handling 2020-01-24 21:34:29 +01:00
Daniel Marjamäki 0929c3cced Cleanup code, CppCheck::checkNormalTokens executes the bug hunting code 2020-01-24 20:37:24 +01:00
Daniel Marjamäki 7db54bde6f Run normal checks on --clang output 2020-01-24 18:04:39 +01:00
Aleksandr Serbin 11993ed999 Ticket 5607: Allow to exclude folders with glob pattern (#2498) 2020-01-24 07:06:09 +01:00
Daniel Marjamäki fc813cef2a Clang import: IfStmt 2020-01-23 16:18:39 +01:00
Daniel Marjamäki ce77db2b1b Clang import; EnumDecl 2020-01-23 16:06:25 +01:00
Daniel Marjamäki fcd6c62a0d Clang import; Always set Scope::classDef token 2020-01-23 10:33:29 +01:00
Daniel Marjamäki 6a07c2f71a ExprEngine; Check struct member assignment 2020-01-21 20:29:13 +01:00
Daniel Marjamäki 263f80deb8 ExprEngine: Add variable value checker 2020-01-21 20:19:51 +01:00
Daniel Marjamäki 4235a29501 ExprEngine: Handle variable annotations better 2020-01-21 18:55:07 +01:00
Daniel Marjamäki b6db5116c3 Clang import; CXXStdInitializerListExpr 2020-01-21 18:29:04 +01:00
Daniel Marjamäki a20b3a9e2e Clang import; better handling of string literals 2020-01-21 17:47:57 +01:00
Daniel Marjamäki 6386f0e633 Clang import; CXXDeleteExpr 2020-01-21 17:47:57 +01:00
Daniel Marjamäki 9f26e8a356 Clang import; CXXNewExpr 2020-01-21 12:16:39 +01:00
Daniel Marjamäki 7fecc17707 Clang import; CXXThrowExpr 2020-01-21 11:16:22 +01:00
Daniel Marjamäki 549df6a80e Clang import; Fixed wrong AST 2020-01-21 11:07:47 +01:00
Daniel Marjamäki 459e906ae1 Clang import; ConditionalExpr 2020-01-21 07:00:03 +01:00
Daniel Marjamäki e5662ceef2 Clang import; CXXDefaultArgExpr 2020-01-21 06:52:45 +01:00
Daniel Marjamäki f048b4ca57 Clang import; CXXBindTemporaryExpr and CXXTemporaryObjectExpr 2020-01-20 21:43:25 +01:00
Daniel Marjamäki bdc621b7a3 Clang import; MaterializeTemporaryExpr 2020-01-20 21:27:49 +01:00
Daniel Marjamäki 78fcf93342 Clang import; DoStmt 2020-01-20 20:46:33 +01:00
Daniel Marjamäki cd3ad89777 Clang import; GotoStmt, LabelStmt 2020-01-20 19:07:10 +01:00
Daniel Marjamäki 6722ee9d3f test/bug-hunting: add --clang option to the juliet testing 2020-01-20 18:53:40 +01:00
Daniel Marjamäki 3ccd369cf5 Clang import; CaseStmt 2020-01-20 17:38:54 +01:00
Daniel Marjamäki d635ea4b7f Clang import; SwitchStmt 2020-01-20 14:24:03 +01:00
Daniel Marjamäki dea6cc3b76 Clang import; FloatingLiteral 2020-01-20 14:10:43 +01:00
versat 0cf82d6d45 cppcheck.cpp: Fix reserved name "stderr"
Using "stderr" as variable name results in build errors on Windows.
2020-01-20 11:12:23 +01:00
Daniel Marjamäki 9bc43fca1d Fixed crash when printing out ValueFlow debug output 2020-01-20 08:11:57 +01:00
Daniel Marjamäki 8ac2cdd9ff Clang import; If there are syntax errors then abort analysis 2020-01-19 17:30:57 +01:00
Daniel Marjamäki 0eccffe8e3 --clang; require that --cppcheck-build-dir. output files are needed. 2020-01-19 12:33:17 +01:00
Daniel Marjamäki 7d4bd57cc5 Clang import; Fix crash 2020-01-19 09:45:47 +01:00
Daniel Marjamäki 84bb024662 Refactoring; Reuse variable typeSize 2020-01-19 09:17:38 +01:00
Daniel Marjamäki a6ab986217 ExprEngine; In divbyzero report rhs token because that has better location 2020-01-19 09:16:02 +01:00
Daniel Marjamäki 16981f0813 ExprEngine; Fix FP for BailoutValue 2020-01-19 09:10:50 +01:00
Daniel Marjamäki 3d1cb87a11 Clang import; range for 2020-01-18 19:23:37 +01:00
Daniel Marjamäki 36a67c7022 Clang import; fixed ValueType::typeSize calls 2020-01-18 17:32:59 +01:00
Daniel Marjamäki cefd7fb33f Fix testrunner 2020-01-18 12:29:03 +01:00
Daniel Marjamäki 269d21e972 Clang import; Better array handling in sizeof() 2020-01-18 11:55:50 +01:00
Daniel Marjamäki b905547c76 Clang import; Better sizeof/type handling 2020-01-18 11:07:36 +01:00
Daniel Marjamäki f7a30fc99f Rename Verification => Bughunting 2020-01-18 07:25:57 +01:00
Rikard Falkeborn 0bb98aeef9 Fix 9577 (endless recursion in Valueflow::bifurcate()) (#2492)
Ensure bifurcate() does not recurse endlessly where a variable is
initialized recursively, or a variable is initialized as x(0) or x{0}
followed by a recursive assignment (for example int x(0); x = x / 1;).

The first case is solved by bailing out if there initialization is done
using x(0) or x{0}, the second by adding a missing depth argument to a
recursive call.
2020-01-17 03:17:26 +01:00
Daniel Marjamäki bc39cd73f0 Clang import; fix wrong 'sizeof' import 2020-01-17 03:15:08 +01:00
Daniel Marjamäki 272fbfeb74 ExprEngine; Fix Z3 usage for floats 2020-01-16 19:35:05 +01:00
Daniel Marjamäki bc737be0b5 ExprEngine; OLD_Z3 => NEW_Z3 2020-01-16 18:59:47 +01:00
Dmitry-Me 01e0a61ebe Break loops earlier 2020-01-16 18:37:10 +03:00
Daniel Marjamäki 76a048a2c1 Bug hunting; 'hide' the uninitialized variables checking, I need to focus on division by zero and clang import 2020-01-15 21:06:00 +01:00
Daniel Marjamäki 9507fccfc1 ExprEngine: Quick hacks for old Z3 compatibility 2020-01-15 19:46:00 +01:00
Daniel Marjamäki 52d72b6ffc ExprEngine; Fix crash 2020-01-15 18:35:55 +01:00
Daniel Marjamäki 446e7c3c0e ExprEngine; Fix fp in edgevalue 2020-01-15 17:51:34 +01:00
Daniel Marjamäki c79ec9e956 ExprEngine: sizeof() 2020-01-15 15:24:36 +01:00
Daniel Marjamäki 5ac0eb100c Bug hunting; avoid crash when argument is NULL 2020-01-15 07:15:47 +01:00
Daniel Marjamäki 7820b5dbcc Rename 'Verification' to 'Bug hunting' 2020-01-14 21:17:07 +01:00
Daniel Marjamäki dfbf347912 Clang import; Better type 2020-01-13 17:56:30 +01:00
Daniel Marjamäki a17ded3862 Clang import; handle {} that is not a scope better 2020-01-13 13:16:02 +01:00
Daniel Marjamäki 066e43cce3 Clang import; InitListExpr 2020-01-13 12:44:35 +01:00
Daniel Marjamäki bd41b3d713 Clang import; Fixed function arguments in SymbolDatabase 2020-01-13 05:52:46 +01:00
Daniel Marjamäki 9f3df5d630 Clang import; CompoundAssignOperator 2020-01-12 18:41:46 +01:00
Daniel Marjamäki ae7ff940e6 Clang import; minor tweaks 2020-01-12 18:05:45 +01:00
Daniel Marjamäki 1e207e42c5 CppCheck: Try to handle '"' properly in split() 2020-01-12 17:13:26 +01:00
Daniel Marjamäki f4f4377fbf Clang import; Constructor arguments, ExprWithCleanups 2020-01-12 16:49:02 +01:00
Daniel Marjamäki 47e186864b Clang import; Set function pointer properly 2020-01-12 15:15:21 +01:00
Daniel Marjamäki fd1809590c Token: Write function() in ast debug output 2020-01-12 15:04:25 +01:00
Daniel Marjamäki 0e75f16510 verificationUninit: ignore bailout values until it's less noisy 2020-01-12 14:52:15 +01:00
Daniel Marjamäki 1bad69923c astyle formatting
[ci skip]
2020-01-12 13:35:39 +01:00
Daniel Marjamäki 166402b5cf verificationUninit: Avoid some false positives for 'bailout' values 2020-01-12 13:35:09 +01:00
Daniel Marjamäki 88429382b7 Verification; Avoid obvious verificationUninit false positives during bailout 2020-01-12 11:53:49 +01:00
Daniel Marjamäki 55ea06354b ExprEngine: BailoutValue is uninitialized 2020-01-12 10:42:20 +01:00
Daniel Marjamäki e78438e990 astyle formatting
[ci skip]
2020-01-12 10:32:47 +01:00
Daniel Marjamäki 7704f6578f Verification; Fix struct member false negative 2020-01-12 10:29:03 +01:00
Rikard Falkeborn c6e74f4c10 Mathlib: Fix value of suffixed binary integer literal (#2487) 2020-01-12 08:11:12 +01:00
Daniel Marjamäki 668212ac2f SymbolDatabase: Type lookup for clang type strings 2020-01-11 21:24:15 +01:00
Daniel Marjamäki cde757bcd3 Clang import; Type fixes 2020-01-11 18:39:59 +01:00
Daniel Marjamäki abc51afcf1 Clang import; parse clang ast type with ValueType::parseDecl 2020-01-11 18:07:57 +01:00
Daniel Marjamäki ba244be2d6 Clang import; getType() 2020-01-11 16:49:30 +01:00
Daniel Marjamäki aa090a8b45 Clang import; addTypeTokens for function return type 2020-01-11 16:40:22 +01:00
Daniel Marjamäki f7f5f10de4 Clang import; Tweaked IfStmt (Clang 3.8 compatibility) 2020-01-11 16:15:18 +01:00
Daniel Marjamäki 05a34142aa Clang import; forward class declaration 2020-01-11 16:02:25 +01:00
Daniel Marjamäki 380cc78077 Clang; Run ValueFlow 2020-01-11 14:00:41 +01:00
Daniel Marjamäki 6b983a9587 Revert ValueFlow changes, there was unexpected problems in testrunner 2020-01-11 13:11:19 +01:00
Daniel Marjamäki 052eaba632 Clang; run ValueFlow analysis 2020-01-11 13:04:51 +01:00
Daniel Marjamäki 9c38a659a1 Clang import; Fixed CXXConstructExpr without child 2020-01-11 12:16:48 +01:00
Daniel Marjamäki 96ff57e275 ValueFlow; Refactoring 2020-01-11 09:17:32 +01:00
Daniel Marjamäki 30bc67c691 Clang import; CXXNullPtrLiteralExpr 2020-01-10 19:01:33 +01:00
Daniel Marjamäki 7a3bedb583 Clang import; CXXConstructExpr 2020-01-10 18:54:28 +01:00
Daniel Marjamäki c23d33fc0a Clang import; Fixed getSpelling() and getType() 2020-01-10 18:13:47 +01:00
Daniel Marjamäki f667abacf6 Clang import; character literal '\' 2020-01-10 17:37:36 +01:00
Daniel Marjamäki 4c778e0999 Clang import; Rename files/namespace 2020-01-10 16:29:06 +01:00
Daniel Marjamäki 8f1a50ffc0 Clang import; CStyleCastExpr 2020-01-10 16:19:01 +01:00
Daniel Marjamäki 75fd4809e6 Fix compiler warning 2020-01-10 15:08:53 +01:00
Daniel Marjamäki 797ed88147 Fix Cppcheck warning 2020-01-10 15:04:07 +01:00
Daniel Marjamäki 729fca8728 Clang import; handle locations better, only expand function bodies in source file 2020-01-10 14:59:34 +01:00
Daniel Marjamäki e7e80a574d Clang import; types 2020-01-10 12:13:50 +01:00
Daniel Marjamäki d0c1674fe6 Clang import; Fix in splitString 2020-01-10 11:40:28 +01:00
Daniel Marjamäki 4ed7178d4d Clang import; bug fixing in addTypeTokens 2020-01-10 11:32:54 +01:00
Daniel Marjamäki a0a2eae1d2 Clang import; cxxStaticCastExpr2 2020-01-10 11:04:51 +01:00
fuzzelhjb fcd5cda97f Check selected files from project (#2378) 2020-01-10 08:57:37 +01:00
Daniel Marjamäki 3db6502fba Verification; Dangerous casting of void pointer 2020-01-09 21:25:23 +01:00
Daniel Marjamäki b8aa71bc87 Clang import; CXXStaticCast 2020-01-09 20:53:06 +01:00
Daniel Marjamäki bf62138237 Verification; Remove VERIFY_UNINIT define, the checking is always compiled from now on 2020-01-09 20:25:52 +01:00
Daniel Marjamäki 35a8cd8418 Verification; fix division by zero false negative when value might be uninitialized 2020-01-09 19:40:15 +01:00
Daniel Marjamäki 34a26c7dd7 Clang import; Pass include paths to clang 2020-01-09 19:15:01 +01:00
Daniel Marjamäki ae5dbe0575 Clang import; UnaryOperator 2020-01-09 19:07:14 +01:00
Daniel Marjamäki 84b4f0f6ab Verification; Fixed false negative when global variable is changed by function call 2020-01-09 18:50:29 +01:00
Daniel Marjamäki 2137f1ead9 Clang import; reference before declaration 2020-01-09 18:03:24 +01:00
Daniel Marjamäki d842f00aef Clang import; UnaryExprOrTypeTraitExpr 2020-01-09 17:31:46 +01:00
Daniel Marjamäki 7daa1bc11d Clang import: CharacterLiteral 2020-01-09 16:54:45 +01:00
Daniel Marjamäki fea981211e Clang import; CXXBoolLiteralExpr 2020-01-09 16:19:38 +01:00
Daniel Marjamäki e6b873b7b9 Clang import; CXXOperatorCallExpr 2020-01-09 15:59:22 +01:00
Daniel Marjamäki 98e700e30d Clang import; Tweaks 2020-01-09 14:13:39 +01:00
Daniel Marjamäki 90e7a94ff4 Clang importer; Allow throw 2020-01-09 13:58:14 +01:00
Daniel Marjamäki a9dbf129f0 Clang import; some small tweaks 2020-01-09 13:52:17 +01:00
Daniel Marjamäki 64612bf93e Clang import; robustness 2020-01-09 13:40:38 +01:00
Daniel Marjamäki 060c695f80 Clang import; CXXConstructorDecl, CXXThisExpr 2020-01-09 13:19:14 +01:00
Daniel Marjamäki 1589ac5352 Clang import; Set links properly 2020-01-09 12:42:29 +01:00
Daniel Marjamäki 1be41cb8fb Clang import; in AstNode::dumpAst print <<<<NULL>>>> 2020-01-09 11:04:30 +01:00
Daniel Marjamäki 3d2d4c5cbd Clang import; Tweaks 2020-01-09 10:49:47 +01:00
Ken-Patrick Lehrmann 0b7649ca9b Fix 9298 (#2476)
* Fix 9298

Tell cppcheck that strcpy returns its first argument, and use that
knowledge in checkTokenInsideExpression.

* Add missing unit tests in cmake
2020-01-09 08:47:36 +01:00
Maksim Derbasov 872d531568 Removing check hidingInheritedPublic (#2482) 2020-01-09 06:53:08 +01:00
Daniel Marjamäki 4e8a922e18 Clang import; CXXMemberCall 2020-01-08 21:49:23 +01:00
Daniel Marjamäki 3387ee3512 Clang import; ClassTemplateDecl 2020-01-08 21:31:06 +01:00
Daniel Marjamäki eb3270959e Clang import; FunctionTemplateDecl 2020-01-08 20:47:52 +01:00
Daniel Marjamäki 27be51cb49 Clang importer; FieldDecl in CXXRecordDecl 2020-01-08 19:43:01 +01:00
Daniel Marjamäki 64953f36b3 Clang import: CXXRecordDecl, CXXMethodDecl 2020-01-08 19:32:04 +01:00
Daniel Marjamäki 5ffd6d744c Clang import; fix Cppcheck warnings about unused variables 2020-01-08 18:55:28 +01:00
Daniel Marjamäki 54a9b61329 Clang import; NamespaceDecl, varDecl4, varDecl5 2020-01-08 18:23:40 +01:00
Daniel Marjamäki b8ae957365 Clang import; fwrite FunctionDecl 2020-01-08 16:42:21 +01:00
Daniel Marjamäki c4c929a6a7 Clang import: StringLiteral, funcdecl3, determine includes with clang -v 2020-01-08 16:36:51 +01:00
Daniel Marjamäki f51048e03b Clang Import; TypedefDecl 2020-01-08 14:25:09 +01:00
Daniel Marjamäki e6ee29fd11 Clang import; BreakStmt, ContinueStmt 2020-01-08 12:29:54 +01:00
Daniel Marjamäki ea414e46e1 Clang import; WhileStmt 2020-01-08 12:19:48 +01:00
Daniel Marjamäki 61039023b2 Clang import; ForStmt 2020-01-08 10:35:44 +01:00
Daniel Marjamäki 4b7e6c68b0 Clang import; MemberExpr 2020-01-08 09:51:35 +01:00
Daniel Marjamäki d75d9c1866 Clang import; Refactoring 2020-01-07 19:51:44 +01:00
Daniel Marjamäki e5b99d3299 Clang import; Refactoring 2020-01-07 19:47:06 +01:00
Daniel Marjamäki a3abc75ca1 Clang import; RecordDecl 2020-01-07 18:33:24 +01:00
Daniel Marjamäki c4131bbc5b Clang import; else 2020-01-07 12:38:37 +01:00
Daniel Marjamäki b829c4cebb Clang import; Arrays 2020-01-07 12:19:06 +01:00
Daniel Marjamäki 2760d4400b SymbolDatabase: Ensure parameter name is same 2020-01-06 18:56:01 +01:00
Daniel Marjamäki 6a4a59b783 Clang Import; Added test 2020-01-06 16:45:18 +01:00
Daniel Marjamäki 28688dcc09 Clang Import; set Token::function() 2020-01-06 15:26:21 +01:00
Daniel Marjamäki 8ea22edb4e Clang Import; VarDecl 2020-01-06 13:47:19 +01:00
Daniel Marjamäki 00c05ce626 Clang import; CallExpr, setLocation 2020-01-06 09:05:39 +01:00
Ken-Patrick Lehrmann b6d2c1b238 Fix github CI (#2477)
* Fix github CI

```
Checking lib/check.cpp: __CPPCHECK__=1...
lib/symboldatabase.h:719:5: warning: Class 'Function' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
    Function(const Token *tokenDef);
    ^

Checking lib/templatesimplifier.cpp: __CPPCHECK__=1...
lib/symboldatabase.cpp:1754:33: warning: Condition 'settings' is always true [knownConditionTrueFalse]
    const Library * const lib = settings ? &settings->library : nullptr;
                                ^
lib/symboldatabase.cpp:1751:9: note: Assuming that condition '!settings' is not redundant
    if (!settings)
        ^
lib/symboldatabase.cpp:1754:33: note: Condition 'settings' is always true
    const Library * const lib = settings ? &settings->library : nullptr;
```

* Compile parseClangAstDump
2020-01-05 21:10:48 +01:00
Daniel Marjamäki 07cc3e47c4 cppcheck.vcxproj: Try to make appveyor happy 2020-01-05 19:34:25 +01:00
Daniel Marjamäki 0b765cd253 Clang importing; Use ValueFlow 2020-01-05 19:21:13 +01:00
Daniel Marjamäki fa727185e5 Clang import; IfStmt 2020-01-05 19:18:32 +01:00
amai2012 b621c35539 Astyle formatting [ci skip] 2020-01-05 17:00:34 +01:00
Daniel Marjamäki 211af1d4fe Clang import: debug output 2020-01-05 16:58:13 +01:00
Paul Fultz II 90f82d0374 Fix issue 9541: false negative: knownConditionTrueFalse (#2473)
* Fix issue 9541: false negative: knownConditionTrueFalse

* Add another test case

* Add another test

* Fix FPs

* Format

* Fix compile error

* Remove double conditions

* Fix compile error
2020-01-05 16:25:33 +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
Daniel Marjamäki bc17b9a1be Importing Clang ast dump: Run ValueFlow analysis 2020-01-05 16:23:02 +01:00
Daniel Marjamäki b03bdfaf72 Import Clang ast dump (experimental) 2020-01-05 15:12:53 +01:00
Maksim Derbasov a3ed9116e5 Clarify error msg for hidingInheritedPublic (#2474) 2020-01-05 09:32:39 +01:00
Daniel Marjamäki 4f1e8bc5e7 astyle formatting
[ci skip]
2020-01-04 18:47:05 +01:00
Paul Fultz II e1a97c524d Fix issue 9554: False positive: The address of local variable 'x' is accessed at non-zero index. (#2470)
* Fix issue 9554: False positive: The address of local variable 'x' is accessed at non-zero index.

* Format

* Remove unnecesary condition check
2020-01-04 11:39:52 +01:00
Ken-Patrick Lehrmann a9d423eef2 Fix #8938: FP identicalInnerCondition (#2471) 2020-01-04 11:38:56 +01:00
Ken-Patrick Lehrmann eca7ee9260 9356: Prevent false positive when passing non-const reference to member constructor (#2370)
* Add cases for 9356

* 9356: Prevent false positive when passing non-const reference to member constructor

This workarounds false positives 'Parameter  can be declared with const [constParameter]'
when said parameter is used in constructor call. It assume the
constructor call might change the parameter (without any checks.
The drawback is that we have false negative, in cases where we could
check the constructor actually takes a const reference, or a copied by
value parameter.

* Add todo comment in isVariableMutableInInitializer
2020-01-04 11:36:45 +01:00
Paul Fultz II e07801a891 Fix issue 9563: new daca crash: findLambdaEndToken not finding end token (#2472) 2020-01-04 10:45:24 +01:00
orbitcowboy 1e0f8ae9b4 Running astyle [ci skip]. 2020-01-04 00:06:27 +01:00
Paul Fultz II dd05839a7e Fix false positives in knownConditionTrueFalse when using expressions with const variables (#2469) 2020-01-03 19:35:28 +01:00
Daniel Marjamäki 0e369edd8c Verification; Only warn about uninitialized function arguments if VERIFY_UNINIT is defined 2020-01-02 06:16:36 +01:00
Daniel Marjamäki e32c01b13c Verification; printing debug output on std::cout 2020-01-01 19:57:49 +01:00
Maksim Derbasov fc5fd3c40c Check that virtual function non-narrow access modifier in derived class (#2229)
* Check that virtual function has not narrowed access in derived class

* motivation info added

* error reporting moved to func

* added suppression for CI
2020-01-01 16:09:43 +01:00
Rikard Falkeborn 7514544d94 Fix #8758 (add syntax error for invalid code) (#2466) 2020-01-01 15:46:09 +01:00
Daniel Marjamäki f23d880a7e Verification; use <uninit> configuration 2020-01-01 14:37:20 +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
Daniel Marjamäki b44029cdaa Refactoring; CWEs should be clarified 2020-01-01 09:09:10 +01:00
Daniel Marjamäki 28c37bb63f Verification; Clarify error message 2020-01-01 08:36:40 +01:00
Daniel Marjamäki 443e8cfbcf Verification; avoid false positive for known float value 2020-01-01 08:33:27 +01:00
Daniel Marjamäki d4ec8075a4 Verification; Fix false positive in while loops 2019-12-31 22:32:16 +01:00
Daniel Marjamäki 043634be27 Verification; Better handling of assignment in while 2019-12-31 20:31:31 +01:00
Daniel Marjamäki 446256a503 Verification; assume non-const pointer argument might point at uninitialized data 2019-12-31 17:51:58 +01:00
Daniel Marjamäki 10010eba95 Verification; Avoid fp for array declaration 2019-12-31 16:50:20 +01:00
Dmitry-Me 1a2b770bfd Break the loop once a match is found 2019-12-31 18:32:45 +03:00
Dmitry-Me 895910b769 Fixed #7159 (wrong handling of function parameters) 2019-12-31 18:26:12 +03:00
Daniel Marjamäki f55d72e821 Verification; uninitialized local variable 2019-12-31 14:57:42 +01:00
Daniel Marjamäki 48be067dd1 Verification; Added --verify-diff option 2019-12-31 12:05:08 +01:00
Daniel Marjamäki 3af3219076 Verification; Juliet *_float_* division by zero tests 2019-12-31 09:02:06 +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 fde86b696d Verification; Use ValueFlow for improved accuracy 2019-12-31 05:59:06 +01:00
Daniel Marjamäki 3ff31b799c Verification: Use separate id for floating point division by zero 2019-12-30 19:50:22 +01:00
Daniel Marjamäki 4b5585e75b Verification; floating point division by zero 2019-12-30 19:47:18 +01:00
Daniel Marjamäki a60efa6774 Verification; Experimental checking for uninit 2019-12-30 18:55:16 +01:00
Daniel Marjamäki 6ea1875a84 Verification; Ensure assertions for variable type limits are added 2019-12-30 12:53:59 +01:00
Daniel Marjamäki d247ffb13a Fix compiler warning 2019-12-29 21:22:20 +01:00
Daniel Marjamäki 29b599b0e5 Verification; callbacks in executeCast 2019-12-29 19:17:36 +01:00
Daniel Marjamäki 9723b28385 Verification; struct pointer member 2019-12-29 18:42:35 +01:00
Daniel Marjamäki 2710a94b4b Verification; Merged handling of pointers and arrays 2019-12-29 16:26:11 +01:00
Paul Fultz II 75de485c4d Fix issue 9551: Out-of-bounds in getLifetimeTokens() (#2461) 2019-12-29 08:23:58 +01:00
Daniel Marjamäki d16ea3293e Verification; Fix testing 2019-12-28 22:09:16 +01:00
Daniel Marjamäki ab2e87191f Verification; Avoid crash 2019-12-27 20:27:21 +01:00
Daniel Marjamäki 49ed1a82b4 Verification; save report in custom file 2019-12-27 19:25:06 +01:00
Daniel Marjamäki 4b4f7ea60b Verification; Updated report 2019-12-27 19:05:22 +01:00
Dmitry-Me 147cf9319f Restore compilation in gcc-4.6 2019-12-27 18:26:44 +03:00
Daniel Marjamäki ec4668353d Verification; Determine argument number properly 2019-12-26 18:32:59 +01:00
Daniel Marjamäki 31bddb6ae0 astyle formatting
[ci skip]
2019-12-26 15:48:29 +01:00
Paul Fultz II ce1fc56e96 Fix issue 6890: ValueFlow: min/max value for variable, after condition (#2460)
* Set bounds when combining values

* Adust bounds when they are negated

* Try to infer conditional values

* Switch false and true

* Fix checking of conditions

* Fix compare

* Fix remaining tests

* Fix overflows
2019-12-26 15:47:53 +01:00
Daniel Marjamäki 8c652afd6e Verification: Added IntRange::isLessThan and IntRange::isGreaterThan 2019-12-26 15:39:08 +01:00
Dmitry-Me 678560bf0d
Use "override" keyword in clang (#2459) 2019-12-25 18:19:00 +03: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 0cd2935dc7 Verification; Verify that function call argument values meet annotations 2019-12-25 09:23:07 +01:00
Daniel Marjamäki f0ac19514b Verification: Handle Cppcheck annotations __cppcheck_low__ and __cppcheck_high__ 2019-12-24 21:14:14 +01:00
Daniel Marjamäki 755e2d261c Fixed #9402 (ExprEngine: && and || in condition) 2019-12-24 15:52:02 +01:00
Daniel Marjamäki 747a01f74d Verification; Check function argument values 2019-12-23 22:10:43 +01:00
Daniel Marjamäki eb551728a5 Verification; Avoid FP for known values 2019-12-22 21:24:39 +01:00
Daniel Marjamäki 93f10da981 Verification; Detect errors after bailout 2019-12-22 21:03:43 +01:00
PKEuS 8218120fd5 Moved function from .h to .cpp 2019-12-21 11:55:11 +01:00
Daniel Marjamäki 7f110f3ec3 Set version 2019-12-21 11:49:01 +01:00
Daniel Marjamäki 6890757986 Update Copyright year 2019-12-21 11:23:01 +01:00
Daniel Marjamäki fe23d017f3 Fixed #8419 (False positive accessMoved on int) 2019-12-21 07:39:14 +01:00
Daniel Marjamäki c2f8fb5603 Fixed #9405 (false positive: (style, inconclusive) Boolean expression 'dqOpen' is used in bitwise operation. Did you mean '&&') 2019-12-20 19:38:30 +01:00
Daniel Marjamäki 33ec78fe6e Fixed #9036 (false positive: (style) Condition 's.x<127U' is always true) 2019-12-20 19:06:35 +01:00
Daniel Marjamäki bd83630f2e Fixed #8990 (False positive: struct member not used (union)) 2019-12-20 18:31:55 +01:00
Daniel Marjamäki 252c3a17fa Fixed #7107 (False positive iterators - using alias for container) 2019-12-20 12:13:26 +01:00
Daniel Marjamäki 9ffb657c1a Fixed #8597 (False positive - Array index is used before limits check.) 2019-12-20 09:46:01 +01:00
Daniel Marjamäki 02eaf6fa93 Fixed #8998 (False positive uninitStructMember related to reference to member) 2019-12-19 20:18:32 +01:00
Daniel Marjamäki c84ba10b37 Fixed #8774 (Wrong handling of function with name 'or') 2019-12-19 19:22:39 +01:00
Daniel Marjamäki 2a2fa49098 Thread safety: use std::atomic for global flags 2019-12-19 18:38:22 +01:00
Daniel Marjamäki 235ef0a01e Fixed #9420 (False positive - redundantInitialization) 2019-12-18 19:39:23 +01:00
IOBYTE ec4c979cd8 fix daca error: Internal Error: Invalid syntax (#2452)
* fix daca error: Internal Error: Invalid syntax

* fix cppcheck warnings
2019-12-18 11:48:36 +01:00
Daniel Marjamäki caab1e61bb Fixed #9542 (Better error handling for --addon) 2019-12-17 12:00:01 +01:00
Maksim Derbasov 68a67a910e Remove .dump file after plugins execution (#2451) 2019-12-17 08:40:59 +01:00
Dmitry-Me 7d6582c7a5 Resolve C4800 Visual C++ warning 2019-12-16 18:11:12 +03:00
Paul Fultz II ad352daa08 Fix issue 9535: Syntax Error: AST broken, 'if' doesn't have two operands. (#2450) 2019-12-16 12:17:01 +01:00
Daniel Marjamäki a241be0ecc Fixed #9434 (False positive: Out of bounds access when using const pointer) 2019-12-15 20:10:28 +01:00
Daniel Marjamäki 36f369473e isPointerDeref: Return false for function declarations 2019-12-15 16:36:46 +01:00
Daniel Marjamäki f614d32d6a Fixed #9519 (Syntax error on valid C++ 'enum {} (a)') 2019-12-15 08:40:04 +01:00
Daniel Marjamäki bcfc5924fa Fixed #9532 (False positive: Out of bounds access in expression 'v[0]' because 'v' is empty.) 2019-12-14 19:04:19 +01:00
Paul Fultz II 06752d75a5 Fix issue 9485: knownConditionTrueFalse false positive with integer constants (#2447)
* Fix issue 9485: knownConditionTrueFalse false positive with integer constants

* Formatting
2019-12-14 09:15:00 +01:00
IOBYTE 0e4efea530 fix #9539 (Syntax error for valid C++14 code) (#2446) 2019-12-12 20:50:20 +01:00
RobkeBaer 370196a14c Fix extern c typedef syntax error (#2438)
* Fix extern c typedef syntax error

* Fix extraWhiteSpaceError

* Move test from testgarbage to testtokenize
2019-12-12 13:51:14 +01:00
orbitcowboy f89adef1c1 Running astyle [ci skip] 2019-12-11 15:01:21 +01:00
Sebastian 6f2879a59b
errorlogger.cpp: Handle empty file-name like "*" (unmatchedSuppression) (#2440)
Using "--suppress=unmatchedSuppression" did not suppress the error-id in
all files, one needed to specify "*" as file-name. This commit also
allows empty file-names to suppress "unmatchedSuppression", not only "*"
or the exact file-name.
The manual uses the following example for suppressions specified in a
file:
// suppress all uninitvar errors in all files
uninitvar

This example suggests that no "*" has to be used to get suppression in
all files. I think that the command line parameter should work in the
same way.
2019-12-11 09:07:18 +01:00
Paul Fultz II ad2f71338c Fix issue 9525: Syntax Error: AST broken, 'if' doesn't have two operands inside lambda (#2433)
* Fix issue 9525: Syntax Error: AST broken, 'if' doesn't have two operands inside lambda

* Fix incorrect matchers
2019-12-10 21:21:07 +01:00
Rikard Falkeborn 1c92170179 ValueFlow: Remove unused argument (#2442) 2019-12-10 17:48:27 +01:00
Sebastian 95696ead23
Catch preprocessor errors possibly issued during loading files (#2430)
* Also catch preprocessor errors possibly issued during loading files

Currently only errors that are issued during preprocessing are caught.

* Bump simplecpp, implement suggestions

Use return value checking instead of catching an exception for calling
Preprocessor::loadFiles().
Handle new enum value simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND
where the corresponding enum is used in Cppcheck.

* Use "noloc" location if an explicit include can not be opened
2019-12-09 19:16:55 +01:00
Paul Fultz II ea2916a3e4 Fix issue 9514: Syntax Error: AST broken, 'for' doesn't have two operands. (#2429)
* Fix issue 9514: Syntax Error: AST broken, 'for' doesn't have two operands.

* Fix typo
2019-12-07 21:16:25 +01:00
Paul Fultz II 56e17fb228 Fix issue 9524: Syntax Error: AST broken, 'if' doesn't have two operands. (#2432) 2019-12-07 21:06:45 +01:00
Sebastian 95e0b0d0f9
Fix #9510: Crash in valueflow.cpp solveExprValues() (division by zero) (#2420)
`break` if divider `intval` is 0 to avoid division by 0 as suggested by @pfultz2
Trac ticket: https://trac.cppcheck.net/ticket/9510
2019-12-06 08:08:40 +01:00
IOBYTE f637d97080 Fix 9509 (Syntax error on empty attribute list) (#2423) 2019-12-06 05:17:19 +01:00
Paul Fultz II 2978c67e6f Fix issue 9511: Syntax Error: AST broken, 'if' doesn't have two operands. (#2428) 2019-12-06 04:19:46 +01:00
IOBYTE 5979eec2c0 Fix 9518 (Syntax error on valid C++) (#2424) 2019-12-05 20:51:36 +01:00
versat e712df7cb4 Run astyle [ci skip] 2019-12-04 13:53:10 +01:00
John Marshall 297efcd049 Avoid some additional memleakOnRealloc false positives (#2422)
* Avoid some additional memleakOnRealloc false positives

checkReallocUsage() already contains code to suppress the
`p = realloc(p, size)` error message when the pointer has been
previously copied from another variable (hence there is an additional
copy of the original pointer value) within the same function, as in
the added realloc21() test case.

Extend this so that `p = *pp` and `p = ptr->foo` are also recognized
as copies from another variable with the same original pointer value,
as in the added realloc22() and realloc23() test cases.

* Rewrite as a single findmatch() expression
2019-12-04 12:13:44 +01:00
Paul Fultz II 36977becba Fix issue 9196: Lambda confuses check (#2415) 2019-12-03 18:30:52 +01:00
amai2012 0e8a145d6c Run astyle 2019-12-02 22:04:22 +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
Paul Fultz II 2bdb7dc236 Fix issue 9390: valueFlowTerminatingCondition bailout: Skipping function due to incomplete variable NULL (#2412)
* Fix issue 9390: valueFlowTerminatingCondition bailout: Skipping function due to incomplete variable NULL

* Uncomment keyword

* Add nullptr as well
2019-12-01 15:09:21 +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 a71f58ffc2 Fix issue 9441: false positive: new(std::nothrow) and nullPointerRedundantCheck (#2403)
* Fix issue 9441: false positive: new(std::nothrow) and nullPointerRedundantCheck

* Skip new if it is a variable
2019-12-01 12:16:31 +01:00
Paul Fultz II 79a2e61721 Fix issue 6850: Valueflow: pointer alias, conditional value (#2402) 2019-11-30 09:22:03 +01:00
Paul Fultz II f9d33c07f8 Fix issue 9458: Crash with shadow variables in a lambda (#2406)
* Fix issue 9458: Crash with shadow variables in a lambda

* Format
2019-11-29 09:45:02 +01:00
IOBYTE f554a71dea fix #9495 (Crash when parsing angle brackets in template with type traits (assertion failure)) (#2407) 2019-11-29 09:44:27 +01:00
Daniel Marjamäki 676a837af6 Fixed #9335 (FP constStatement "Found a statement that begins with string constant") 2019-11-28 17:49:33 +01:00
Daniel Marjamäki 937c82efbe AST: initializer list with lambda 2019-11-27 06:44:58 +01:00
Sebastian c3c3d6770c
Fix #9478: Valueflow: printf does not change value (#2388)
Format-string arguments are now marked to have `in` direction, except
for `scan`-functions (like `scanf`) where these arguments are explicitly
marked to have `out` direction.
2019-11-24 01:40:31 +01:00
Daniel Marjamäki ab2274b8ad AST: lambdas and scopes in expressions 2019-11-23 21:36:36 +01:00
Daniel Marjamäki ebd32cfd73 Syntax error: if (retval==) 2019-11-23 18:50:46 +01:00
IOBYTE fb1d60bfb1 fix syntax error for num.operator std::string()[0] (#2389) 2019-11-23 17:42:24 +01:00
Dmitry-Me b3ed9f8231 Make iterator checks useful 2019-11-21 18:15:26 +03:00
IOBYTE df952926f8 fix syntax error for a.operator++() ? a.operator--() : 0 (#2382) 2019-11-20 22:13:32 +01:00
Dmitry-Me 28ef31c981 Fix "one past end" illegal iterator computation 2019-11-20 18:10:05 +03:00
Sebastian c990d10ffa
Check for JSON error when parsing addon .json files + fixes (#2374)
* cppcheck.cpp: Check for JSON error when parsing addon .json files

This fixes that errors in JSON files given via `--addon=*.json` are
silently ignored and maybe only a part of the JSON file is used.
Now the error message which picojson can return is checked and a
corresponding error message is returned again by getAddonInfo().

* naming.json: Fix missing comma

* CLI: Fix naming violations detected by addon naming.py via naming.json

* Addon naming: Add argument for validating names of constants

* LIB: Rename functions/variables so they are valid, loosen naming rules

* GUI: Fix naming violations
2019-11-20 15:37:09 +01:00
IOBYTE 590aeea8f8 Fix #9483 (Assertion `tok && tok->str() == ">"' failed) (#2381) 2019-11-20 07:02:25 +01:00
Paul Fultz II 479fbb85a2 Fix issue 9443: Internal error: Token::astOperand2() cyclic dependency. (#2376)
* Improve nested init lists

* Fix issue 9443: Internal error: Token::astOperand2() cyclic dependency.
2019-11-19 11:38:03 +01:00
Paul Fultz II ed1acc319d Fixx issue 9355: FP constParameter when returning non-const reference to struct member (#2373) 2019-11-18 06:39:50 +01:00
IOBYTE 7f6ebaa6b2 fix syntax error for VTK_LEGACY_BODY(vtkMatrix3x3::operator[], "VTK 7.0"); (#2372) 2019-11-18 06:38:53 +01:00
Daniel Marjamäki 1d441f64c1 CheckUnusedVar: Quick heuristic so we don't bailout for 'auto' variables 2019-11-17 15:44:57 +01:00
Daniel Marjamäki d0daf1f90d CheckUnusedVar: Assume that assignment has 'standard behavior' by default 2019-11-17 12:33:26 +01:00
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 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
Daniel Marjamäki 5654630099 Fixed #8978 (False positive: Variable assigned value that is never used when assigning via iterator) 2019-11-16 19:49:54 +01:00
Daniel Marjamäki 7cd7aff60a Fixed #9285 (Misleading warning message) 2019-11-16 17:24:54 +01:00
Daniel Marjamäki bae4faa786 Fixed #9422 (FP uninitdata - writing pointer to output stream) 2019-11-16 11:47:57 +01:00
Daniel Marjamäki 7f57c980f0 Refactoring; shorter code 2019-11-16 11:20:26 +01:00
IOBYTE 754c1fff66 fix syntax error for conversion operator for type with global namespace (#2365)
* fix syntax error for conversion operator for type with global namespace

* fix syntax error when taking address of operator function

* fix syntax error for using ::operator "" _a;

* fix syntax error for template<> void operator "" _h<'a', 'b', 'c'>() {}

* fix syntax error for operator in parentheses
2019-11-16 08:03:13 +01:00
Daniel Marjamäki b9835fd4f9 Fixed #9445 (Syntax error on typeof word in C) 2019-11-15 21:20:57 +01:00
IOBYTE 3a617fa04a Fix #9472 (Syntax error on valid C++ code) (#2363)
There are probably a lot more valid code patterns that generates syntax
errors so I added "operator" to the error message to make it easier to
find them.
2019-11-15 07:03:57 +01:00
Daniel Marjamäki 7e0fc4fb00 Tokenizer: Detect more syntax errors when operator does not have operands 2019-11-14 21:18:31 +01:00
IOBYTE 2eb575d990 Fix #9468 (Syntax error on valid C++) (#2358) 2019-11-14 09:26:21 +01:00
IOBYTE f88ae21d8f Fix #9467 (False positive on local variable when template specialization is used) (#2357) 2019-11-13 21:34:27 +01:00
Paul Fultz II 7841430793 Fix issue 9428: FP uninitvar for pointer passed to sscanf (#2344)
* Add indirect to library cfg files

* Check indirect for non null arguments

* Reenable subfunction analysis

* Use indirect 1 when using not-null

* Parse correct string name

* Update documentation

* Make attribute optional
2019-11-13 12:46:54 +01:00
Daniel Marjamäki 49d6bfbd7b Fixed crash in harfbuzz found by daca@home 2019-11-12 18:22:11 +01:00
Daniel Marjamäki f5a6aa530d Fixed #9417 (FP uninitvar - member initialized in operator()) 2019-11-11 15:00:53 +01:00
Rikard Falkeborn 38dea4719b Fix #9166 (print proper types in invalidCast message) (#2347)
* Fix #9166 (print proper types in invalidCast message)

* Use ValueType->str()

* astyle

* Set default sign to avoid issues on different platforms
2019-11-11 07:17:50 +01:00
Daniel Marjamäki eaa5bfcadd Remove 'unsafeClassDivZero' warning. The software verification will cover this better. 2019-11-10 16:49:34 +01:00
Daniel Marjamäki fcc5fad3ed Fixed #9113 (false positive: (error) Buffer is accessed out of bounds) 2019-11-10 16:42:48 +01:00
Paul Fultz II 6f29e299fc Fix issue 9439: false positive: unique_ptr and nullPointerRedundantCheck (#2346) 2019-11-10 09:44:59 +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
IOBYTE 0fed6f0091 fix clang testsuite crash (#2341) 2019-11-09 18:00:21 +01:00
Daniel Marjamäki 81fff2edf1 Fixed #9464 (Import compile database; only check given configuration) 2019-11-09 17:51:42 +01:00
Paul Fultz II c75bbbe253 Fix issue 9404: False positive: Either the condition 'if(x)' is redundant or there is possible null pointer dereference: a->x (#2322)
* Fix issue 9404: False positive: Either the condition 'if(x)' is redundant or there is possible null pointer dereference: a->x

* Use simpleMatch

* Add a test case for the FP

* Check if expression is changed

* Check for no return scope

* Use simpleMatch
2019-11-08 08:11:41 +01:00
Rikard Falkeborn 1fcbd696be Token::ConcatStr(): Handle mixed string literals (#2337)
Improve handling of adjacent string literals of different types.

Example of adjacent string literals: "ab" L"cd".

In C89, C++98 and C++03, this is undefined. As of C99 and C++11, this is
well defined and the two string literals are concatenated to L"abcd".
C11 and C++11 introduces the utf16, utf32 and (C++ only) utf8 string
types. Concatenating any of these with a regular c-string works exactely
as the wide string example above. The result of having two adjacent
string literals with different prefix is implementation defined, unless
one is an UTF-8 string literal and the other is a wide string literal.
In this case the behaviour is undefined.

Ignore the undefined and ill-formed programs (this behaviour is unchanged)
and make sure that concatenating a plain c string literal with a prefixed
one works correct (in C99 and C++11 and later versions). It also makes the
behaviour consistent since previously, "ab" L"cd" would result in "abcd"
while L"ab" "cd" would result in L"abcd".

It also means the somewhat awkward updatePropertiesConcatStr() test can
be removed since the added tests would not work if update_properties()
was not called in concatStr().

Since the prefix is stored in the token, testing the type of the string
is not relevant in TestSimplifyTokens. It is tested extensively in
TestToken::stringTypes().
2019-11-08 08:03:45 +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 c61880c457 Search relative path first before install path (#2328) 2019-11-05 07:09:59 +01:00
Daniel Marjamäki 06ea1a2b53 Fixed #9312 (FP : variable is assigned a value that is never used (static)) 2019-11-04 17:59:16 +01:00
Paul Fultz II acd2a92efc Fix issue 9395 and 9423: False positive: nullPointerRedundantCheck (#2323) 2019-11-04 07:02:25 +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
Daniel Marjamäki c7a23f126f Fixed #9373 (False Positive - missingOverride) 2019-11-03 18:42:04 +01:00
Daniel Marjamäki c3ae028a41 Fixed #8617 (False positive: uninitdata for memory allocated and initialized in function called new (C code)) 2019-11-03 17:08:28 +01:00
Daniel Marjamäki 8c8952ae7c Fixed #9324 (FP compareBoolExpressionWithInt - when using C++ and/or operator synonyms) 2019-11-03 12:53:30 +01:00
Daniel Marjamäki 03ae0ccef3 AST: Do not hang for code 'foo({ for (a;b;c) {} });' 2019-11-03 11:02:59 +01:00
Daniel Marjamäki 791242ea78 Fixed #6975 and #9376 (Tokenizer: unknown macro without semicolon) 2019-11-02 19:34:19 +01:00
Daniel Marjamäki 28182084f2 Fix crash when there are too many nested scopes. Bail out after 1000 nested scopes. The crash was in gcc and was seen with daca@home. 2019-11-02 18:23:10 +01:00
Dmitry-Me f2cf71f6e9 Fix typo 2019-11-01 18:39:53 +03:00
IOBYTE 3f0ef01154 Fix #9446 (Syntax error on valid C++ code) (#2316) 2019-11-01 09:11:29 +01:00
Daniel Marjamäki 35d04cd2d3 AST: non-standard handling of ; in argument list for unknown macro 2019-11-01 09:05:45 +01:00
Daniel Marjamäki 6e9d496ab3 ValueFlow: handling of char literal size before ValueType has been set 2019-10-31 14:06:46 +01:00
versat 181e1baa69 cppcheck.vcxproj.filters: Also update this Visual Studio file
This .filters file has been automatically updated by Visual Studio when
the two new files were added. So it should also be updated.
2019-10-31 09:05:58 +01:00
Daniel Marjamäki 9094ff01d3 Fixed #9363 (knownConditionTrueFalse: False positive about function parameter) 2019-10-31 08:34:09 +01:00
versat 470f0cdfe3 lib/cppcheck.vcxproj: Fix Visual Studio build, add new files. 2019-10-31 08:29:19 +01:00
Daniel Marjamäki 6d1c84e3a6 Fixed #9449 (SymbolDatabase: Function lookup fails when string literal is converted to bool) 2019-10-30 21:05:42 +01:00
Daniel Marjamäki b96a347914 Tokenizer: Report unknown macro when argument list contains if/for/while/switch 2019-10-30 19:36:19 +01:00
Daniel Marjamäki 33d43808f7 Run dmake 2019-10-30 18:38:37 +01:00
Daniel Marjamäki 8c591308cb astyle formatting
[ci skip]
2019-10-30 18:19:45 +01:00
Paul Fultz II 694d147097 Refactor ProgramMemory and PathAnalysis (#2311)
* Traverse conditions for container size

* Move program memory to seperate file

* Revert "Traverse conditions for container size"

This reverts commit 914783769f.

* Move pathanalysis to seperate files
2019-10-30 17:57:46 +01:00
Rikard Falkeborn 239b660a52 Fix #9438 (Don't warn for return (void*) malloc(1)) (#2307) 2019-10-30 17:55:47 +01:00
Daniel Marjamäki 277c59e5f3 AST: Fixed AST for lambda that returns template type 2019-10-30 16:05:34 +01:00
IOBYTE 02e7f4f61c Fix template templates where the template template parameter is not the first parameter. (#2309) 2019-10-30 12:12:47 +01:00
Daniel Marjamäki 210232d35c Fixed #9314 (false positive: (error) Uninitialized variable: ret) 2019-10-29 20:36:58 +01:00
cyy cf5dd48994 add override (#2305) 2019-10-29 20:06:40 +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 c3c9559bee Fix Cppcheck warning 2019-10-27 18:22:47 +01:00
Daniel Marjamäki c899d7becf --verify: Fix false negative in itc 2019-10-27 16:47:56 +01:00
Daniel Marjamäki 2fa9a29ea7 --verify: Fix false negative in itc test suite 2019-10-27 16:40:16 +01:00
Daniel Marjamäki 83a7987f6f --verify: Fix false negative in itc test suite 2019-10-27 16:23:37 +01:00
Daniel Marjamäki c56a45840a Verify: Fix false negative in itc 2019-10-27 15:35:04 +01:00
Daniel Marjamäki 2c1905cc2b AST: Somewhat better handling of '{x}' function parameters 2019-10-27 12:00:08 +01:00
Daniel Marjamäki f03945a9e2 AST: better handling when returning list of lambdas 2019-10-26 19:19:20 +02:00
IOBYTE 6b4a3bc830 fix #9431 (Invalid syntax error on valid C++ code) (#2298) 2019-10-26 17:39:46 +02:00
Georgy Komarov 72f07c8a33 Add MISRA checks for rules 21.1 and 21.12 (#2284)
* Add MISRA 21.1 check

This also required add static field for functions in symboldatabase.

* Add MISRA R21.12

* Use newer ASSERT macroses in tests
2019-10-26 08:32:46 +02:00
Daniel Marjamäki 37bb19f02c Verify: Fix a false negative in the itc test suite 2019-10-25 21:46:02 +02:00
Wolfgang Stöggl 1ea3fc8083 Allow SSIZE_T in addition to ssize_t (#2263)
The Windows Data Type SSIZE_T is declared in BaseTsd.h
However, it is written in capital letters

- Fixes e.g. the following false positive:
  (portability) %zd in format string (no. 1) requires 'ssize_t' but the
  argument type is 'SSIZE_T {aka signed long long}'.
  [invalidPrintfArgType_sint]
2019-10-24 21:51:20 +02:00
Daniel Marjamäki 8cfc833381 ExprEngine: Better handling of container arguments 2019-10-23 22:04:48 +02:00
Daniel Marjamäki dedee2b173 SymbolDatabase: Better ValueType handling for containers 2019-10-23 19:54:59 +02:00
Daniel Marjamäki 052c02f8ee ExprEngine: Refactoring 2019-10-23 18:42:40 +02:00
Daniel Marjamäki bcfc0d32fe ExprEngine: :: 2019-10-23 18:23:25 +02:00
Daniel Marjamäki 7b50b76b89 ExprEngine: container value 2019-10-23 18:06:10 +02:00
Daniel Marjamäki 4d218d1b47 ExprEngine: Clarify output 2019-10-23 16:40:49 +02:00
Daniel Marjamäki 87f65230ae SymbolDatabase: Better valuetype handling of container addition 2019-10-23 12:42:46 +02:00
Daniel Marjamäki f131a99ae3 SymbolDatabase: Improved ValueType in range for loop 2019-10-23 11:52:29 +02:00
Daniel Marjamäki c5c07b61a6 SymbolDatabase: Fix type for expression 'x = uint8_t(a[b])' 2019-10-22 20:40:36 +02:00
Daniel Marjamäki cf1dd2e6f6 AST: Fix AST when returning list of lambda functions 2019-10-22 18:39:59 +02:00
Daniel Marjamäki 3699227b12 ExprEngine: Throw exception if there is unhandled expression in assignment LHS 2019-10-22 18:39:59 +02:00
Rikard Falkeborn 73a569be97 TestBufferOverRun: Handle string literals (#2287) 2019-10-21 07:11:22 +02:00
Rikard Falkeborn f83eb127ae ValueFlow: sizeof string and char literals (#2285) 2019-10-20 21:02:28 +02:00
Daniel Marjamäki 78c02f0505 ValueFlow: Fixed false positives after escape scope 2019-10-20 20:57:16 +02:00
Daniel Marjamäki 223ceeb97f SymbolDatabase: Do not set constructor flag for function in namespace 2019-10-20 18:12:52 +02:00
Daniel Marjamäki 82d8f3e7f5 SymbolDatabase: Fix crash if std::shared_ptr type is only forwarded, not defined 2019-10-20 17:00:15 +02:00
Daniel Marjamäki e50b9e2bef Fixed #8784 (False positive uninitialized variable) 2019-10-20 15:20:05 +02:00
Daniel Marjamäki 68ea60d207 Try to make Travis happy 2019-10-20 07:44:56 +02:00
Rikard Falkeborn 5c061c1c12 Set correct type and size of string and char literals (#2275)
* Set correct type and size of string and char literals

Use that string and char literal tokens store the prefix. This makes
it possible to distinghuish between different type of string literals
(i.e., utf8 encoded strings, utf16, wide strings, etc) which have
different type.

When the tokens holding the string and character values have the correct
type, it is possible to improve Token::getStrSize() to give the correct
result for all string types. Previously, it would return the number of
characters in the string, i.e., it would give the wrong size unless
the type of the string was char*.

Since strings now can have different size (in number of bytes) and
length (in number of elements), add a new helper function that returns
the number of characters. Checkers have been updated to use the correct
functions.

Having the size makes it possible to find more problems with prefixed
strings, and to reduce false positives, for example in the buffer
overflow checker.

Also, improve the stringLiteralWrite error message to also print the
prefix of the string (if there is one).

* Add comment and update string length
2019-10-20 07:11:57 +02:00
Daniel Marjamäki 00fae7fb42 Fixed #9261 (Inconsistent violation report between using global enum and namespaced enum.) 2019-10-20 07:07:38 +02:00
Daniel Marjamäki 4943771e41 Fix #9262 (False positive on variable assignment when putting enum in namespace) 2019-10-19 21:41:50 +02:00
Daniel Marjamäki 9a2b71494f ValueFlow: Set value for :: 2019-10-19 21:08:59 +02:00
Daniel Marjamäki 574141a492 shadowVariable: Add comment 2019-10-19 18:51:36 +02:00
Daniel Marjamäki 24db81adb5 Fixed #8903 (False positive 'shadows outer variable' when using GCC statement expressions) 2019-10-19 18:50:27 +02:00
IOBYTE 5658dfcaf3 better fix for #9392 that also handles namespaces (#2282) 2019-10-18 18:05:48 +02:00
Daniel Marjamäki e0093c99ce Fixed #9276 (False positive: ValueFlow does not handle return in switch properly.) 2019-10-18 16:16:56 +02:00
Daniel Marjamäki 3a0a0fdefb Fixed #9424 (False positive: known condition after function call) 2019-10-18 08:21:07 +02:00
Daniel Marjamäki 99ef64459b Fixed #9344 (FP redundantAssignment related to increasing index variable for vector) 2019-10-17 18:31:05 +02:00
Daniel Marjamäki 15d7b9c83f Fixed #9347 (FP uninitvar for pointer passed to sscanf) 2019-10-17 17:41:54 +02:00
IOBYTE e4d2e9d2af Fix #9421 (syntaxError on incomplete code (from z3)) (#2274) 2019-10-16 20:56:53 +02:00
Ken-Patrick Lehrmann 24211cf8b9 Fix crashes in valueflow (#2236)
* Fix crashes in valueflow

http://cppcheck1.osuosl.org:8000/crash.html

For instance in http://cppcheck1.osuosl.org:8000/styx
```
==19651==ERROR: AddressSanitizer: SEGV on unknown address 0x00000000001c (pc 0x556f21abc3df bp 0x7ffc140d2720 sp 0x7ffc140d2710 T0)
==19651==The signal is caused by a READ memory access.
==19651==Hint: address points to the zero page.
    #0 0x556f21abc3de in Variable::isGlobal() const ../lib/symboldatabase.h:342
    #1 0x556f221f801a in valueFlowForwardVariable ../lib/valueflow.cpp:2471
    #2 0x556f22208130 in valueFlowForward ../lib/valueflow.cpp:3204
    #3 0x556f221e9e14 in valueFlowReverse ../lib/valueflow.cpp:1892
    #4 0x556f221f1a43 in valueFlowBeforeCondition ../lib/valueflow.cpp:2200
    #5 0x556f2223dbb5 in ValueFlow::setValues(TokenList*, SymbolDatabase*, ErrorLogger*, Settings const*) ../lib/valueflow.cpp:6521
    #6 0x556f220e5991 in Tokenizer::simplifyTokens1(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ../lib/tokenize.cpp:2342
    #7 0x556f21d8d066 in CppCheck::checkFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::istream&) ../lib/cppcheck.cpp:508
    #8 0x556f21d84cd3 in CppCheck::check(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ../lib/cppcheck.cpp:192
    #9 0x556f21a28796 in CppCheckExecutor::check_internal(CppCheck&, int, char const* const*) ../cli/cppcheckexecutor.cpp:884
    #10 0x556f21a24be8 in CppCheckExecutor::check(int, char const* const*) ../cli/cppcheckexecutor.cpp:198
    #11 0x556f22313063 in main ../cli/main.cpp:95
```

* Add test case for crash in valueflow
2019-10-16 20:54:07 +02:00
Rikard Falkeborn 297360920a Keep prefix in string and char literals (#2272)
Keeping the prefix in the token allows cppcheck to print the correct
string and char literals in debug and error messages.

To achieve this, move some of the helper functions from token.cpp to
utils.h so that checks that look at string and char literals can reuse
them. This is a large part of this commit.

Note that the only user visible change is that when string and char
literals are printed in error messages, the prefix is now included.

For example:

	int f() {
		return test.substr( 0 , 4 ) == U"Hello" ? 0 : 1 ;
	};

now prints U"Hello" instead of "Hello" in the error message.
2019-10-16 11:41:33 +02:00
Daniel Marjamäki 7d6d561c84 SymbolDatabase: Better handling of function call using smart pointer 2019-10-15 19:33:25 +02:00
Daniel Marjamäki 4a4b4963cc SymbolDatabase: Fix function lookup for '::func()' 2019-10-15 12:39:02 +02:00
Daniel Marjamäki d98ac017f7 ExprEngine: Improved handling of struct member assignments in loops 2019-10-14 22:04:12 +02:00
Daniel Marjamäki 62d972061b astyle formatting
[ci skip]
2019-10-14 19:41:51 +02:00
Daniel Marjamäki 8c5c070d6a ExprEngine: Improved handling of struct member assignments in loop 2019-10-14 19:41:32 +02:00
Daniel Marjamäki ee280a94fb ExprEngine: New handling of << and >> 2019-10-14 17:20:35 +02:00
Daniel Marjamäki 4e49b14721 ExprEngine: << and >> are not handled well, throw exception for now. 2019-10-14 11:56:39 +02:00
Daniel Marjamäki c7a56529bb ExprEngine: Clarify verificationIntegerOverflow message 2019-10-14 11:54:43 +02:00
Daniel Marjamäki bf61bcf402 ValueType: Set ValueType for constructor calls 2019-10-14 09:19:16 +02:00
Sebastian 267d23f1b8
gnu.cfg: Define `__typeof__` as `typeof`, fix simplifyTypedef() (#2260)
`__typeof__` is just an alternative keyword for `typeof`, see
https://gcc.gnu.org/onlinedocs/gcc/Typeof.html
Since `typeof` is handled in several checkers it makes sense to define
`__typeof__` as `typeof`.
Tokenizer::simplifyTypedef(): Use `typeof` instead of `__typeof__` to
be consistent with the rest of the code.
2019-10-14 08:20:22 +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
KenPatrickLehrmann 5a08ac361a Better handle const/noexcept methods (#2211)
* Better handle const/noexcept methods/conversion operator

const or noexcept in a method / (conversion) operator definition were
badly parsed, ending in a bad ast.
This patch tries to make it better, at least making the ast less bad,
so as to avoid errors in later checks.

* Fix parsing of some operator

It is still very broken, but at least, it does not fail.

Here is the previous error:
```
TestSimplifyTypedef::simplifyTypedef129
terminate called after throwing an instance of 'InternalError'

Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51	../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
 #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
 #1  0x00007ffff612a801 in __GI_abort () at abort.c:79
 #2  0x00007ffff6b1d957 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
 #3  0x00007ffff6b23ab6 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
 #4  0x00007ffff6b23af1 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
 #5  0x00007ffff6b23d24 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
 #6  0x0000555556366bf8 in Tokenizer::cppcheckError (this=0x7fffffffc2d0, tok=0x607000006760) at ../lib/tokenize.cpp:8721
 #7  0x000055555636a4bb in Tokenizer::validate (this=0x7fffffffc2d0) at ../lib/tokenize.cpp:9154
 #8  0x000055555633e3aa in Tokenizer::simplifyTokenList1 (this=0x7fffffffc2d0, FileName=0x603000002d50 "test.cpp") at ../lib/tokenize.cpp:4477
 #9  0x00005555563223ca in Tokenizer::simplifyTokens1 (this=0x7fffffffc2d0, configuration="") at ../lib/tokenize.cpp:2286
 #10 0x00005555563235c8 in Tokenizer::tokenize (this=0x7fffffffc2d0, code=..., FileName=0x555556fda9a0 "test.cpp", configuration="") at ../lib/tokenize.cpp:2345
 #11 0x00005555569410ea in TestSimplifyTypedef::tok[abi:cxx11](char const*, bool, cppcheck::Platform::PlatformType, bool) (this=0x555557728580 <(anonymous namespace)::instance_TestSimplifyTypedef>,
     code=0x7fffffffcb70 "class c {\n  typedef char foo[4];\n  foo _a;\n  constexpr operator foo &() const noexcept { return _a; }\n};", simplify=false, type=cppcheck::Platform::Native, debugwarnings=true) at ../test/testsimplifytypedef.cpp:192
 #12 0x000055555697239e in TestSimplifyTypedef::simplifyTypedef129 (this=0x555557728580 <(anonymous namespace)::instance_TestSimplifyTypedef>) at ../test/testsimplifytypedef.cpp:2599
 #13 0x000055555694092c in TestSimplifyTypedef::run (this=0x555557728580 <(anonymous namespace)::instance_TestSimplifyTypedef>) at ../test/testsimplifytypedef.cpp:167
 #14 0x00005555569cab84 in TestFixture::run (this=0x555557728580 <(anonymous namespace)::instance_TestSimplifyTypedef>, str="simplifyTypedef129") at ../test/testsuite.cpp:306
 #15 0x00005555569cb445 in TestFixture::runTests (args=...) at ../test/testsuite.cpp:329
 #16 0x000055555687bdfb in main (argc=2, argv=0x7fffffffd988) at ../test/testrunner.cpp:44
```

* Replace some ASSERT_EQUALS with TODO_ASSERT_EQUALS when the actual result is still wrong

* Remove invalid code from simplifyTypedef129

* Properly skip parentheses
2019-10-12 11:46:00 +02:00
Paul Fultz II 19cf636a4a Move necessary code into valuetype (#2265)
* Fix parsing of smart pointers

* Improve deduction of return type

* Valuetype computation for decayed pointers
2019-10-12 11:40:02 +02:00
IOBYTE f99e83ece0 Fix #9411 (new daca crash related to using namespace) (#2264) 2019-10-12 11:39:14 +02:00
Daniel Marjamäki 530d4d2427 ExprEngine: Throw exception if we do not handle array well yet 2019-10-10 20:29:43 +02:00
IOBYTE fe1f601b91 Fix #9389 ("debug: Executable scope 'x' with unknown function." with … (#2261)
* Fix #9389 ("debug: Executable scope 'x' with unknown function." with "using namespace")

* use static rather than anonymous namespace for new functions
2019-10-10 20:25:09 +02:00
Daniel Marjamäki c2b514dc45 ExprEngine: Throw exception if assignment in loop is not handled 2019-10-10 11:12:36 +02:00
orbitcowboy a9386fa093 Running astyle [ci skip] 2019-10-10 08:17:41 +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 0c1e979af7 SymbolDatabase: Refactor handling of variable declarations in if condition 2019-10-09 22:27:48 +02:00
Daniel Marjamäki 5b9bc4918e ExprEngine: Better error output when solver fails 2019-10-09 22:16:30 +02:00
Daniel Marjamäki 63bd182e83 ExprEngine: Adapt to z3 handling of bool/int expressions 2019-10-09 20:18:17 +02:00
Daniel Marjamäki 9f4db5018d SymbolDatabase: Added testcase for variable in if-scope 2019-10-09 16:41:07 +02:00
Daniel Marjamäki 3776604f06 SymbolDatabase: Add variable in if condition 'if (auto x = bar())' 2019-10-09 15:55:54 +02:00
Daniel Marjamäki 273a1a7402 ExprEngine: Fix FP for 'int' overflows 2019-10-09 11:24:57 +02:00
Sebastian b7e48a9b27
Fix #9399 (Build Failure on x86: error: unknown type name '__int128_t') (#2254)
https://stackoverflow.com/questions/16088282/is-there-a-128-bit-integer-in-gcc
suggests to test for __SIZEOF_INT128__. This test is added now and
Cppcheck now also compiles for a 32 bit target with the expected
warning that there is no 128-bit integer. "make test" also works.
2019-10-09 10:25:21 +02:00
Daniel Marjamäki ab6354754f ExprEngine: Catch z3::exception and print message 2019-10-09 09:42:18 +02:00
Daniel Marjamäki c04e25e936 Revert "#9391 Detecting uninited member variables with default ctor (#2249)"
This reverts commit 08bc369296.
2019-10-09 08:17:47 +02:00
Daniel Marjamäki b27fe83da4 ExprEngine: Handle << and >> 2019-10-08 21:38:10 +02:00
Daniel Marjamäki 3e50150dbf ExprEngine: Fix the checking for integer overflows 2019-10-08 20:13:25 +02:00
blacktea 08bc369296 #9391 Detecting uninited member variables with default ctor (#2249) 2019-10-08 19:33:07 +02:00
IOBYTE c98732dd8b fix using type aliases in out of class destructors (#2250) 2019-10-08 19:30:41 +02:00
Daniel Marjamäki 1abf70a7cb SymbolDatabase: Add null pointer check for ast operand for '(' token 2019-10-08 17:53:29 +02:00
Steve Mokris 506a952ad2 Parse `extern "C"`, and use it to avoid FP reference warnings (#2234)
Previously, cppcheck discarded the `extern "C"` specifier.  This patch modifies cppcheck to parse each as a Scope in the symbol database, then uses that scope to avoid false positives when making recommendations about changing a function argument to be a reference (since variable references is a C++ feature, unavailable in C, and thus unavailable in `extern "C"`).
2019-10-08 17:48:09 +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
Daniel Marjamäki 79356b1883 SymbolDatabase: Better ValueType handling of 'LibraryType(..)' 2019-10-08 11:25:05 +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
Daniel Marjamäki 21774cbdc4 ExprEngine: Handle while/for loops 2019-10-07 17:45:06 +02:00
Daniel Marjamäki d82b1b29ce ExprEngine: Initial handling of switch 2019-10-06 19:58:51 +02:00
Daniel Marjamäki 05aae9569b ExprEngine: Execute false execution path even if there is no else, upon Z3 exception assume that value is in range (safe option) 2019-10-06 18:26:40 +02:00
Daniel Marjamäki 6c0c9ba6d3 ExprEngine: Handle 'break' and 'while (0);' 2019-10-06 17:43:30 +02:00
Daniel Marjamäki dcf8a7213f ExprEngine: ExprData::getConstraintExpr 2019-10-06 14:47:50 +02:00
IOBYTE 78b9fd9bb9 Fix #9383 ("debug: Function::addArguments found argument 'x' with varid 0." with variadic templates) (#2238) 2019-10-06 12:45:42 +02:00
Daniel Marjamäki 3c085fd88a Fixed #9359 (SymbolDatabase: function lookup fails when -funsigned-char is used) 2019-10-06 12:05:58 +02:00
Tyson Nottingham 0950a97df2 Fix false negatives in checkBitwiseOnBoolean (#2220)
* Fix false negatives in checkBitwiseOnBoolean

Use AST-based tests in favor of token-based tests for greater coverage.

* Travis: add suppressions for bitwiseOnBool
2019-10-06 09:57:31 +02:00
Daniel Marjamäki b97436e8f8 Fixed #9382 (Hang: CheckLeakAutoVar pellepl/spiffs/src/spiffs_hydrogen.c) 2019-10-06 09:52:05 +02:00
IOBYTE 8f46bb3ef6 fix #9392 (SymbolDatabase: Weird default constructor outside class) (#2243) 2019-10-06 07:21:12 +02:00
Daniel Marjamäki 7294145797 SymbolDatabase: set value type for std::move() 2019-10-05 19:57:52 +02:00
Daniel Marjamäki 4e525e52ec ExprEngine: Avoid endless recursion for struct members that have struct type 2019-10-05 18:29:41 +02:00