Commit Graph

13165 Commits

Author SHA1 Message Date
Daniel Marjamäki 6234b5438e New check: Writing overlapping data, detect undefined behavior 2021-07-05 22:07:41 +02:00
yyny 3e6681e2b3
Fix assertion failure in errorlogger.cpp (#3318) 2021-07-05 08:08:15 +02:00
Daniel Marjamäki 6cb8f87798 missing return; fixed false positive for 'return {};' 2021-07-04 19:59:22 +02:00
Daniel Marjamäki 036c71d967 Fixed #5462 (non-void function does not return a value) 2021-07-04 11:27:57 +02:00
Daniel Marjamäki 803eea912c Set debug version 2021-07-04 11:19:08 +02:00
Daniel Marjamäki 3e3e9d8c50 2.5; Update versions 2021-07-04 08:40:41 +02:00
Daniel Marjamäki c489626167 updated copyright year 2021-07-04 08:09:11 +02:00
Daniel Marjamäki 0bb334c102 astyle formatting 2021-07-03 09:12:51 +02:00
Paul Fultz II fb9d659e25
Fix 10326: Regression: ValueFlow; Wrong Uninit value after do while (#3312) 2021-07-03 09:12:26 +02:00
Armin Müller fc90598077
Typos found by running "codespell" (#3324) 2021-07-02 17:41:51 +02:00
Robert Reif 68898e2be0
fix #10335 (Type alias remains unknown with using) (#3323)
Co-authored-by: Robert Reif <reif@FX6840>
2021-07-02 06:19:26 +02:00
Daniel Marjamäki 1a5449cbeb Fixed #10327 (ValueFlow; Wrong Uninit value in called function) 2021-07-01 22:08:00 +02:00
Daniel Marjamäki e1cff1d1ef Fixed #10334 (AST: hang with c++ initializer and emplace_back) 2021-06-30 21:40:45 +02:00
Daniel Marjamäki 1783fd1bba duplicateBreak; Allow extra return that clarifies for tool(s) that function does not continue 2021-06-29 11:17:12 +02:00
Georgiy Komarov b89f5fbeff
misra: Fix 8.2 false positives (#3309)
* misra: Fix 8.2 false positives

Fix false positives in rule 8.2 that occurred in cases when we have a
function definition and declaration in the same file.

For example, the following code generated false positives before this
commit:

```
void f(uint8_t * const x);
void f(uint8_t * const x)
{ (void)x; }
```

We need to distinguish the declaration and the definition, so the dump
file generation routine was extended to keep token where the definition
of the function. The analysis in the addon also been improved.

Closes Trac issue: https://trac.cppcheck.net/ticket/10219
2021-06-27 10:51:32 +02:00
Daniel Marjamäki 2a2e071a85 Tokenizer::simplifyAttribute; Set function attribute for function pointer 2021-06-26 14:23:39 +02:00
Paul Fultz II 66956ed959
Fix 10323: Wrong known value. x!=0 does not mean that x==1 (#3308) 2021-06-26 09:16:45 +02:00
Paul Fultz II 508188df2b
Fix 10297: Regression; ValueFlow known value, sign conversion (#3307) 2021-06-26 09:16:04 +02:00
Daniel Marjamäki 9769afe434 knownConditionTrueFalse; avoid several warnings when nonzero expression is compared to see if it is positive or negative 2021-06-25 16:25:25 +02:00
Daniel Marjamäki 769b20b426 ValueFlow: Clarify note when impossible value is assigned (#10297) 2021-06-24 17:10:06 +02:00
Paul Fultz II b13e44fce5
Fix 10309 and 10034: internalAstError with init lists (#3303) 2021-06-24 08:25:13 +02:00
Paul Fultz II 6e74fc64b9
Fix 10317: Regression: internalAstError on valid C++ code (#3302) 2021-06-24 08:22:03 +02:00
Daniel Marjamäki 2d08564c8a astyle formatting 2021-06-19 14:47:35 +02:00
Paul Fultz II dd178c3ad9
Fix 10314: Possible nullPointerRedundantCheck false positive (#3298) 2021-06-19 13:59:48 +02:00
Paul Fultz II 5922d5178b
Fix 10321: Two flags confuse null pointer check (#3300) 2021-06-19 13:58:57 +02:00
Paul Fultz II eb7b225fc1
Fix 10119: ValueFlow; object member is not uninitialized. happens when there is static member also. (#3299) 2021-06-19 13:58:18 +02:00
Daniel Marjamäki a7707a457d astyle formatting 2021-06-14 07:39:41 +02:00
shane a5664c3e49 allow token iteration in range for 2021-06-14 07:39:01 +02:00
Daniel Marjamäki 03445c01c1 Fix false positives when class might inherit from VCL TObject class 2021-06-13 18:56:04 +02:00
Daniel Marjamäki 7dbca470f7 Suppressions; Fixed problem with cppcheck build dir is used 2021-06-12 18:19:00 +02:00
Daniel Marjamäki 83d406806f CI; Fixed problems in windows paths 2021-06-12 12:45:31 +02:00
Daniel Marjamäki 4a4808e0ff ImportProject; Try to use relative paths 2021-06-12 11:10:35 +02:00
Daniel Marjamäki ed05a5c3b3 astyle formatting 2021-06-12 11:09:15 +02:00
Paul Fultz II f55a4563f9
Fix 10308: danglingTemporaryLifetime confused by function parameter (#3292) 2021-06-09 09:21:03 +02:00
Paul Fultz II f3a33ea330
Fix 10294: ValueFlow: Wrong <Uninit> value below loop (#3291) 2021-06-09 09:20:43 +02:00
Daniel Marjamäki 3c3435dd10 Fix bug in Tokenizer::simplifyVarDecl 2021-06-06 08:13:40 +02:00
orbitcowboy 195d413986 Running astyle [ci skip] 2021-06-05 08:53:15 +02:00
Paul Fultz II f90b05ea7c
Show lifetime kind in output (#3285) 2021-06-04 21:41:30 +02:00
Paul Fultz II 668b88d7c0
Fix 10284: False positive; valueFlowBeforeCondition does not seem to care about increment (#3287) 2021-06-04 21:40:57 +02:00
Paul Fultz II a14922ed85
Fix 10238: FP knownConditionTrueFalse std::string from const char* assumed non-empty (#3288) 2021-06-04 17:22:05 +02:00
Paul Fultz II 537fb5bcd9
Fix 10264: FP invalidContainer when address of container is passed inside struct (#3286) 2021-06-04 17:20:47 +02:00
Paul Fultz II b23c5aa742
Fix 10023: ValueFlow; Wrong result of post-increment in reverse analysis (#3289) 2021-06-04 17:20:21 +02:00
Paul Fultz II 486e440c4a
Fix 10298: ValueFlow: Wrong known value, 'x == -1' implicit unsigned cast for rhs (#3277) 2021-06-04 17:17:41 +02:00
Paul Fultz II 95c872b1ec
Fix todo test for returning a dangling reference (#3284) 2021-06-04 17:15:39 +02:00
orbitcowboy a585834445 Running astyle [ci skip] 2021-06-03 07:35:50 +02:00
Paul Fultz II 3e78e76fe8
Fix issue 10076: ValueFlow: False positive after address of var is taken 'T t = {{{&var}}};' (#3283) 2021-06-03 07:31:46 +02:00
Paul Fultz II 548ec10824
Fix issue 10306: FP knownConditionTrueFalse with modulo result converted to bool (#3282) 2021-06-03 07:26:36 +02:00
orbitcowboy 14ff646c92 Formatted the code [ci skip] 2021-06-02 16:59:34 +02:00
dummyunit 9652ca39a3
Improve support for labels in simplifyAddBraces step (#3278)
Previously only a single regular label before a compound statement was
allowed in simplifyAddBracesPair() after if/switch/do/while/for.
This patch adds support for:
* case-labels;
* labels before a single statement;
* labels before try/catch blocks;
* multiple consecutive labels.

Additionally the code for skipping a case label was extracted into a
separate function from simplifyLabelsCaseDefault() and reused in
simplifyAddBracesPair().
2021-06-02 07:00:37 +02:00
Maksim Derbasov f64011b669
Moving error reporting functions from header to cpp (#3279) 2021-06-02 07:00:10 +02:00
Maksim Derbasov 06c4542ac2
New check for rethrow without current handled exception (#3270) 2021-05-31 10:39:24 +02:00
Paul Fultz II 5f0fe1dfe7
Fix another FP with range for macro (#3276) 2021-05-26 04:52:55 +02:00
Daniel Marjamäki a4653a057a Uninitialized variables; Fixed FP for range for loop 2021-05-25 20:37:22 +02:00
Daniel Marjamäki 7d84b8f1bc Uninitialized variables; Fix FP when assigning struct members 2021-05-25 16:13:32 +02:00
Daniel Marjamäki b61eaec5b4 Cppcheck self-check; use Token::simpleMatch 2021-05-24 21:14:54 +02:00
Daniel Marjamäki 4cccc710ef Uninitialized variables; Fixed FP when bitmask is used on address 2021-05-24 20:55:13 +02:00
Paul Fultz II 0862045ef7
Refactor valueFlowUninit check (#3275) 2021-05-24 19:59:22 +02:00
Robert Reif c7be967769
fix #10295 (false negatives by inconsistent 'void' in argument list (declaration vs definition)) (#3274)
Co-authored-by: Robert Reif <reif@FX6840>
2021-05-24 19:32:15 +02:00
Daniel Marjamäki b7803ea6fb Uninitialized variables; Fixed false positives for reference cast and dereferencing address of uninitialized variable 2021-05-24 17:50:28 +02:00
Daniel Marjamäki 4ad90bf6f1 Uninitialized variables; Fixed FP in inner for loop 2021-05-24 17:02:19 +02:00
Daniel Marjamäki fa72ec20b2 Uninitialized variables; avoid false positives when passing uninitialized variable to unknown function 2021-05-24 15:54:09 +02:00
Daniel Marjamäki a2e709a652 Uninitialized variables; Try to remove heuristics for assignment with overloaded <<. That is non-standard behavior for the << operator. Let's see how much FPs we get. 2021-05-24 13:17:50 +02:00
Paul Fultz II ab50a75d8a
Fix 10289: ValueFlow; Wrong known value 'size_t - uint16_t > 0' (#3273) 2021-05-24 08:28:21 +02:00
Daniel Marjamäki 8ad0905e3b Uninitialized variables; Fixed FP in valueflow-based checking 2021-05-23 18:43:34 +02:00
Daniel Marjamäki cbbd7f0bd0 Uninitialized variables; Improved handling of function parameter 2021-05-23 14:36:56 +02:00
Daniel Marjamäki d64aea90fa astyle formatting 2021-05-23 14:36:45 +02:00
Daniel Marjamäki 8828619855 Fixed #10293 (Uninitialized variables; False positive for array in union) 2021-05-23 12:06:23 +02:00
Daniel Marjamäki 85723f8605 Uninitialized variables; Different heuristic needed for const pointer function parameter 2021-05-23 11:45:47 +02:00
dummyunit 247b2d8c83
Support array types in template simplifier (#3267) 2021-05-23 10:40:09 +02:00
Paul Fultz II 47a4144b47
Fix 10288: ValueFlow; False positives because of wrong known value when there is sign cast (#3268) 2021-05-23 10:20:29 +02:00
Paul Fultz II e2d9aaf23b
Fix 10286: false positive: uninitvar (#3271)
* Fix 10286: false positive: uninitvar

* Remove header
2021-05-23 07:58:19 +02:00
Paul Fultz II 8541e0503e
Fix 10290: false negative: container out of bounds (#3269) 2021-05-22 23:33:13 +02:00
Daniel Marjamäki 1df93f5474 Uninitialized variables; create utility function isSizeOfEtc 2021-05-22 19:45:46 +02:00
Daniel Marjamäki 5f6b56ada2 buffer overrun; Fixed false negative for dynamically allocated float buffer 2021-05-22 15:39:20 +02:00
Daniel Marjamäki 0db649c075 Fixed Cppcheck self check warning; redundant check 2021-05-22 15:34:39 +02:00
Daniel Marjamäki 87554bed7a Redundant pointer op; Fixed false positives when macro is used 2021-05-22 14:18:29 +02:00
Daniel Marjamäki 9a9f14bd8a Buffer overflow; Fixed FPs when array size is 1 2021-05-22 12:13:39 +02:00
Daniel Marjamäki 1cb48ad418 Uninitialized variables; Fixed false positive in sizeof() 2021-05-22 11:04:42 +02:00
Paul Fultz II c63aa2f2cc
Fix 10263: FP containerOutOfBounds when container is accessed via pointer (#3265) 2021-05-22 08:36:51 +02:00
Maksim Derbasov f0d1822a83
Better handling functions with try block for throwInNoexceptFunction (#3264) 2021-05-22 08:36:28 +02:00
Paul Fultz II 1e3ab460a3
Fix 10254: false positive: arrayIndexOutOfBounds in inline function (#3266) 2021-05-22 08:20:09 +02:00
Daniel Marjamäki 68c46e146d Uninitialized variables; Fixed FP when returning malloc pointer 2021-05-21 17:10:49 +02:00
Daniel Marjamäki 1e6a574cff Uninitialized variables; Passing address of uninitialized variable to function 2021-05-21 15:27:13 +02:00
Daniel Marjamäki 8adfcc848c Uninitialized variables; check RHS expression 2021-05-21 14:31:25 +02:00
Paul Fultz II 5409fa8afd
Fix disabled valueFlowUninit tests (#3262) 2021-05-21 07:28:34 +02:00
Daniel Marjamäki 4746d4b819 Uninitialized variables; Improved checking of loops 2021-05-20 22:56:14 +02:00
Daniel Marjamäki 8e650e4243 Uninitialized variable; Fixed FP after unconditional scope with conditional initialization 2021-05-20 18:38:59 +02:00
Daniel Marjamäki f1fff5e904 Fixed #10279 (ValueFlow/TokenList: function pointer dereference and call) 2021-05-20 13:54:17 +02:00
Robert Reif 3af3d7fc06
fix #10281 (Tokenizer; Wrong simplification for 'namespace ef = :🅰️🅱️:c::d::ef') (#3263) 2021-05-20 08:27:07 +02:00
Daniel Marjamäki ca5fab8219 Uninitialized variables; Fixed false positive in range for loop 2021-05-19 21:12:11 +02:00
Daniel Marjamäki abe810d718 Uninitialized variables; Fix false positive in switch inside loop 2021-05-19 13:07:04 +02:00
Armin Müller c70b8793a3
Typos found by running "codespell" (#3251) 2021-05-19 11:49:19 +02:00
Daniel Marjamäki e35c46bcb9 Uninitialized variables; Fixed false positive for overloaded & 'ar & a & b & c' 2021-05-18 21:03:43 +02:00
Daniel Marjamäki 216918756b Fixed #10276 (FP: (style) Variable '((uint8_t*)(uint16_t)0x1000)[0]' is assigned a value that is never used.) 2021-05-18 20:35:00 +02:00
Daniel Marjamäki 0aebc32ae0 Uninitialized variables; Fixed false positive for 'cin >> x[0]' 2021-05-18 20:13:27 +02:00
Paul Fultz II 4b11bb4ad3
10278: ValueFlow: Wrong known value, sign conversion (#3260) 2021-05-18 07:28:45 +02:00
Daniel Marjamäki 84f8b7b50a Uninitialized variables; Fixed error message, use Token::errorString 2021-05-17 16:51:30 +02:00
Daniel Marjamäki bde8b4316e Uninitialized variables; Fixed FP in range based for loop 2021-05-17 13:31:16 +02:00
Daniel Marjamäki 4322311482 Uninitialized variables; Fixed struct member access FP 2021-05-17 11:50:31 +02:00
Daniel Marjamäki c78a1dbbaf Fixed self-check warning, shadow variable 2021-05-17 11:35:04 +02:00
Daniel Marjamäki b115e4a932 Uninitialized variables; Fixed false positive in member assignment 2021-05-17 10:31:02 +02:00
Daniel Marjamäki 16ce0f1dbf Uninitialized variables; Clarify warnings, bailout for binary & to avoid FPs 2021-05-17 09:22:19 +02:00
Daniel Marjamäki 224492b0b5 Uninitalialized variables; Avoid FP for void cast 2021-05-17 05:59:28 +02:00
Daniel Marjamäki 30ef6db24c CI; Fixed self check 2021-05-16 23:39:10 +02:00
Daniel Marjamäki e034fa8a6e UninitVar: Rewrite CheckUninitVar::isVariableUsage(), use AST primarily 2021-05-16 22:27:04 +02:00
Daniel Marjamäki 2c155a7a78 Uninitialized variables; use AST 2021-05-16 11:58:51 +02:00
Daniel Marjamäki e73057eb44 Fixed #10275 (ValueFlow: condition 'x>=0 && x < 10') 2021-05-16 10:34:22 +02:00
Daniel Marjamäki 8476900a62 checkuninitvar; refactor code a bit 2021-05-16 08:38:51 +02:00
Daniel Marjamäki b8314289c6 testbufferoverrun; fixed TODO test cases for pointer arithmetic overflows 2021-05-15 20:32:46 +02:00
Daniel Marjamäki 899b88754f uninitialized variables; fix false positive in loop 2021-05-15 11:16:47 +02:00
Paul Fultz II eb96e4980e
Fix issue 10268: ValueFlow; Wrong value in for loop (#3257) 2021-05-15 08:39:20 +02:00
Daniel Marjamäki c67e618627 self check; Fix shadow variable 2021-05-14 23:05:27 +02:00
Daniel Marjamäki 809c70b9c3 uninitialized variables; fix FP in for loop 2021-05-14 21:36:51 +02:00
Daniel Marjamäki 404b82fc21 unused var; fix todo test cases, redundant assignment of array in loop 2021-05-14 19:07:30 +02:00
Daniel Marjamäki c29997b117 uninitvar: fixed TODO assertion 2021-05-14 11:54:18 +02:00
Daniel Marjamäki 45eb9f82a0 Fix CI; Cppcheck find some more unusedAllocatedMemory violations in test/cfg/.. 2021-05-13 23:08:58 +02:00
Daniel Marjamäki d549770b5b updated extracttests.py. fix syntax errors in test cases. 2021-05-13 20:21:02 +02:00
Daniel Marjamäki 7ba9e37296 unhandled char literal; changed severity to 'portability'. hopefully there will not be warnings for standard character literals. 2021-05-13 13:51:53 +02:00
Daniel Marjamäki fca7a270bf daca@home; show unhandled chars diagnostics 2021-05-13 13:44:32 +02:00
Daniel Marjamäki 22ab9ccd7f Fixed #10273 (False negative; Uninitialized variable in for loop) 2021-05-11 20:35:15 +02:00
Daniel Marjamäki 75311fba0f Fixed #10218 (FP uninitvar with input from stringstream in for loop) 2021-05-10 19:48:07 +02:00
Daniel Marjamäki db7be3e91b Fixed #9810 (Improve check: uninitialized struct member not detected) 2021-05-10 19:24:03 +02:00
Daniel Marjamäki c37b8ea55c Fixed #8299 (false negative: uninitialized struct member) 2021-05-10 18:38:44 +02:00
Daniel Marjamäki 271acf8aee Refactoring; Use isUnaryOp instead of simpleMatch 2021-05-10 18:18:21 +02:00
Daniel Marjamäki 2c24af02c8 Fixed self-check error. Use Token::simpleMatch for simple pattern. 2021-05-09 23:02:35 +02:00
Daniel Marjamäki 2e2d766e2b Fixed #6766 (Improve check; struct member is assigned value that is never used) 2021-05-09 20:09:10 +02:00
Daniel Marjamäki 3b37c14b3c Parser; Partial C++20 support, explicit(bool) 2021-05-09 18:47:02 +02:00
Daniel Marjamäki 32b28d568f Refactoring; Check structured binding in isVariableChanged() 2021-05-08 20:46:46 +02:00
Daniel Marjamäki 895a96f9dd Tokenizer::findGarbageCode: detect wrong struct declaration 2021-05-08 15:28:21 +02:00
Daniel Marjamäki a197e94573 Fixed #10266 (False positive; parameter can be const) 2021-05-08 13:40:52 +02:00
Daniel Marjamäki abb4200316 Fixed #10196 ("Unhandled char constant 'x'" with non-standard escape character) 2021-05-08 12:54:18 +02:00
keinflue 0a84ad874c
Fix case ranges with single quotes and escape sequences (#3248) 2021-05-08 11:24:07 +02:00
keinflue bfa26b5a72
Fix FP leakNoVarFunctionCall with passthrough returns (#3249) 2021-05-08 10:26:10 +02:00
Daniel Marjamäki be95e2bf21 Fixed #10271 (AST; Token::astOperand2() cyclic dependency in static_assert) 2021-05-07 13:19:28 +02:00
keinflue c9a9b56e0e
Increase max AST depth and throw error if exceeded (#3250)
Co-authored-by: keinflue <>
2021-05-06 11:43:15 +02:00
Daniel Marjamäki b8de69489d Fixed #10079 (AST: switch does not have two operands) 2021-05-04 20:15:57 +02:00
Daniel Marjamäki 2f984b201a AST; Fix wrong AST for initializer list 2021-05-04 19:02:29 +02:00
Daniel Marjamäki 08184f4681 Fixed #10070 (FP warning: Logical disjunction always evaluates to true) 2021-05-04 13:47:09 +02:00
dummyunit 661ebd3a96
Fix AST for brace initialization after decltype() (#3245)
Currently sub-expressions like decltype(x){} break AST creation for
subsequent tokens in the whole expression. In some cases this triggers
validation checks in validateAst() and analysis on the file stops.
For example, code like this:
    int x = decltype(0){} ? 0 : 1;
currently produces internalAstError.

To fix the issue iscpp11init_impl() was changed to recognize { preceded
by decltype(expr) as a start of C++11 brace initialization expression.
2021-05-03 21:40:49 +02:00
Daniel Marjamäki 82636d4f07 AST: Fixed ast for a:🅱️:c.. 2021-05-03 20:33:03 +02:00
Daniel Marjamäki 70ab30e3c6 AST; Fixed problem with initializer list and cleanup of compileScope 2021-05-03 20:22:08 +02:00
Daniel Marjamäki cb8ee825fd AST; remove special handling of semicolon in if|switch as Tokenizer will simplify the code instead 2021-05-03 10:43:14 +02:00
dummyunit ac505afe69
Fixed #9729 (AST broken: lambda with noexcept keyword) (#3243)
The previous fix for the issue (43b58dbc9e) didn't seem to actually fix
it because it added a check for noexcept without a condition, but when
AST is created noexcept always has a condition due to simplification
from "noexcept" to "noexcept(true)" in Tokenizer::simplifyKeyword().
The issue from the ticket couldn't be reproduced neither on 43b58dbc9e
nor on the previous commit, so it is hard to tell whether the fix was
effective or not.

The issue appeared again after a refactoring of AST code in ac67049661.
Test added with the original fix was unable to catch that because it
used testAst() helper function which skips most simplification steps.

To fix the issue we now check for noexcept with a condition and add a
proper regression test that:
1. Uses tokenizeAndStringify() to ensure that all simplifications are
   performed before AST is created.
2. Parses the code snippet from the ticket, as having "if (cond)" is
   crucial to reproducing the original issue (internalAstError).

Also fix AST creation for lambdas that have both constexpr and mutable
keywords.
2021-05-02 21:34:28 +02:00
Daniel Marjamäki f7d0bf7a59 Refactoring; Reuse simplecpp::characterLiteralToLL 2021-05-02 13:44:37 +02:00
dummyunit da27159d7c
Fixed #9728 (Support function level try blocks) 2021-05-02 09:05:12 +02:00
Daniel Marjamäki 6f60c6d965 Revert "Refactoring; Reuse function in simplecpp"
This reverts commit dbe9eb2a27.
2021-05-01 19:54:14 +02:00
Daniel Marjamäki e1dd04c536 Fixed make checkcfg 2021-05-01 19:17:07 +02:00
Daniel Marjamäki e03ef93ed7 Fix compiler error 2021-05-01 18:57:10 +02:00
Daniel Marjamäki e6d1b44758 Revert "Remove unnecessary null check (#3213)"
This reverts commit 6d13975def.
2021-05-01 18:54:51 +02:00
Ken-Patrick Lehrmann 6d13975def
Remove unnecessary null check (#3213) 2021-05-01 18:51:51 +02:00
Daniel Marjamäki e78612d280 Refactoring; Use TinyXml methods to parse bool/int attribute values 2021-05-01 18:40:20 +02:00
Daniel Marjamäki dbe9eb2a27 Refactoring; Reuse function in simplecpp 2021-05-01 18:13:40 +02:00
Daniel Marjamäki a32d6257d5 Fix Cppcheck self-check, extra whitespace in match patterns 2021-05-01 12:15:54 +02:00
Daniel Marjamäki 9b717b8835 Refactoring __attribute__ simplification 2021-05-01 11:39:26 +02:00
Daniel Marjamäki 07c1f28035 astyle formatting 2021-05-01 07:35:03 +02:00
DGarry82 d3035c246f
Attribute lists support (#3239) 2021-05-01 07:33:55 +02:00
Paul Fultz II 31e3e4d87b
Fix issue 10086: false positive: (style) constVariable: Variable 'x' can be declared with const (#3219) 2021-04-30 17:47:08 +02:00
Daniel Marjamäki d2d2124238 Revert "Clang import; This experimental feature didn't "take off" much. After a lot of work we are still far fram the goal. I remove it now but don't rule out completely that it could ever be added again."
This reverts commit 207361b174.
2021-04-30 16:47:02 +02:00
Robert Reif e1e822275d
fix daca2 paraview crash from uninstantiated recursive template (#3237) 2021-04-29 11:09:51 +02:00
Ken-Patrick Lehrmann 9aa131a12e
Remove unnecessary null check (#3215)
Spotted by coverity (as the condition in the `if` part `isArrayVar(tok)`
dereferences tok.
Tok can't be null here, because the condition in the `else if`on line
268 checks that there is a `%var%` following, and
`tok = Token::findmatch(tok->next(), "%var%");` simply gets this `%var%`
token.
2021-04-28 18:05:32 +02:00
keinflue d2184ac6a8
Fix UB on right-shift. (#3235) 2021-04-28 11:57:28 +02:00
Daniel Marjamäki bd97b8eb8a SymbolDatabase; Add variables when structured binding is used 2021-04-26 18:21:07 +02:00
Daniel Marjamäki 8aa9e448f5 Parser; Set varid for structured binding variables 2021-04-26 18:04:27 +02:00
Daniel Marjamäki 3a7979171c Set simplecpp std option 2021-04-26 16:32:44 +02:00
Daniel Marjamäki b798b99777 Parser; do not remove alignof and alignas in the same way 2021-04-26 11:44:08 +02:00
dummyunit b18e6f1e10
Fix varId assignment for uses of variables declared in the if condition (#3231)
Variables declared in the if condition (or in C++17 init-statement) are
visible not only in the if body but also in the else body. But logic in
Tokenizer::setVarIdPass1() handled such variables as if they were
declared in the if body.

As the result they were removed from variablesMap by the time the else
block was parsed and their uses in the else block were either given an
incorrect varId from variables in some outer scope or not given a varId
at all.

This then resulted in false positive unreadVariable errors for variables
declared in the if condition (or init-statement) and used only in the
else block.

Simplification from "else if ..." to "else { if ... }" was moved before
setVarId() to simplify detection for ends of blocks in if-else chains.
2021-04-26 07:38:03 +02:00
Daniel Marjamäki d6842007a8 Preprocessor; Set proper __cplusplus define value 2021-04-25 21:16:04 +02:00
Daniel Marjamäki 28a7bb63ec Parser; simplify (break out) init expression from if/switch/range-for 2021-04-25 14:37:27 +02:00
Oliver Stöneberg dcc90c6dfa
improved compiler warnings about missing attributes (#3232) 2021-04-25 12:52:09 +02:00
Daniel Marjamäki 4f43dbf954 Parser; fixed ast and auto type deduction for c++17 braced init lists 2021-04-25 10:38:33 +02:00
Daniel Marjamäki a41d8b436e Fix testrunner 2021-04-24 14:07:26 +02:00
Daniel Marjamäki c9dc92c266 Parser; C++20 for loop with initialization expression 2021-04-24 11:47:51 +02:00
IOBYTE bd7551411a
fix #10258 (coredump due to (?) template simplification) (#3228) 2021-04-22 22:23:01 +02:00
Daniel Marjamäki 26c0945309 Handle c++20 spaceship operator 2021-04-22 19:15:22 +02:00
Daniel Marjamäki 4907c7e3e4 Fix compiler warning, non-static function 2021-04-22 18:40:44 +02:00
dummyunit 229832e72e
Read error locations in the correct order from XML (#3226)
When ErrorMessage::callStack elements are serialized to XML they are
saved in the reverse order. But when they read back from XML they are
added at the end of the list. Thus the round trip via XML reverses the
order of ErrorMessage::callStack.

From the user point of view it looks like the usage of the
--cppcheck-build-dir option sometimes (when the file wasn't reanalyzed,
but that is hard to spot) results in incorrect location info for some
diagnostic messages.

Moreover, when the first location matches some suppression rule and the
last doesn't match any (or vice versa), usage of --cppcheck-build-dir
results in some diagnostic messages appearing and disappearing seemingly
at random (again, depending on whether the file was reanalyzed or not).
2021-04-22 14:28:33 +02:00
Daniel Marjamäki 207361b174 Clang import; This experimental feature didn't "take off" much. After a lot of work we are still far fram the goal. I remove it now but don't rule out completely that it could ever be added again. 2021-04-21 18:59:48 +02:00
Daniel Marjamäki b5aaf8d577 Suppress false positive 2021-04-21 14:49:06 +02:00
Daniel Marjamäki bfb98dbf51 TemplateSimplifier: updated output of uninstantiated c++17 fold expressions 2021-04-21 13:13:11 +02:00
Daniel Marjamäki 35c934c887 Fixed self-check warning 2021-04-20 16:46:05 +02:00
Daniel Marjamäki 04e9c13bc6 TemplateSimplifier; Better handling of c++17 fold expressions and c++20 concepts.
c++17 fold expressions are simplified to a __cppcheck_uninstantiated_fold__ if they are not instantiated.

c++20 concepts are skipped/removed by Cppcheck and these will be enforced by the compiler.
2021-04-20 15:40:25 +02:00
Paul Fultz II db5f00a16a
Fix issue 10214: FP: danglingTempReference doesn't account for reference lifetime extension (#3220)
* Fix issue 10214: FP: danglingTempReference doesn't account for reference lifetime extension
2021-04-19 14:20:29 +02:00
IOBYTE 59f7b937f1
fix daca2 gdcm template simplifier crash (#3221)
This only fixes the crash. The templates that are instantiated are
correct but one template is left uninstantiated. Fixing the missing
instantiation is not easy and will be looked at later.

Co-authored-by: Robert Reif <reif@FX6840>
2021-04-19 09:17:49 +02:00
Paul Fultz II c1bb1d771b
Fix issue 10012: False positive: mismatching container, not containers (#3222)
* Fix issue 10012: False positive: mismatching container, not containers
2021-04-19 09:17:02 +02:00
Paul Fultz II 691f681d86
Fix issue 10235: Regression: oppositeInnerCondition (#3223) 2021-04-19 09:15:03 +02:00
Oliver Stöneberg 5de58c4ddd
added clang-tidy to CI (#3218) 2021-04-18 21:51:47 +02:00
Paul Fultz II 563c9dd9cc
Fix issue 10208: FP: knownConditionTrueFalse in for loop with function that assigns by ref (#3198) 2021-04-18 21:42:27 +02:00
Daniel Marjamäki 56773b82c4 Simple handling of coroutines 2021-04-18 19:42:22 +02:00
Paul Fultz II a772d652d8
Fix issue 9932: FP: containerOutOfBounds (#3217)
* Fix issue 9932: FP: containerOutOfBounds
2021-04-18 10:43:38 +02:00
Daniel Marjamäki 9a9043a07e Fixed #4349 (Support C++11 variadic templates) 2021-04-17 21:57:21 +02:00
Oliver Stöneberg 3bc71f982a
enabled "debug" findings in self-check / split "simplifyUsing" and "simplyTypedef" from more generic "debug" (#3210) 2021-04-17 18:07:47 +02:00
IOBYTE 5568ac95e7
fix simplifyUsing debug warning for: using value_type = const ValueFlow::Value; (#3211) 2021-04-17 14:20:16 +02:00
Oliver Stöneberg 155ff890a5
split "autoNoType" and "bailoutUninitVar" from more generic "debug" (#3209) 2021-04-16 15:19:29 +02:00
Daniel Marjamäki 11f828a669 Fixed #9415 (C++11: `alignas` not handled -> wrong code -> false negatives) 2021-04-15 20:26:53 +02:00
orbitcowboy e869452240 #10244: Fixed false negative: bufferAccessOutOfBounds 2021-04-13 16:40:38 +02:00
Oliver Stöneberg 5a7e361442
run self-checks with standard set to C++11 (#3206) 2021-04-12 18:29:13 +02:00
Daniel Marjamäki eacc9e552e Function::returnsReference: handle type scope better 2021-04-10 14:31:50 +02:00
Paul Fultz II 5cf2f7e633
Fix issue 10087: false positive: error: Reference to temporary returned. (#3205) 2021-04-09 07:44:20 +02:00
Paul Fultz II 255f273c46
Fix issue 10088: ValueFlow: Array size, wrong known value (#3204) 2021-04-09 07:43:54 +02:00
ericmalenfant 1e9687aa8b
Fix noCopyConstructor with multiple inheritance (#3203) 2021-04-09 07:41:59 +02:00
Paul Fultz II f8dc9862da
Fix issue 10202: FP: constParameter (#3202) 2021-04-08 16:02:11 +02:00
Daniel Marjamäki c8e661f61f assignmentInCondition: Clarify error message 2021-04-07 19:46:00 +02:00
Daniel Marjamäki 72802554c9 Fixed #3593 (New Check: Check for assignment within conditional expression) 2021-04-07 17:21:34 +02:00
fschwa 806dbf77b6
use size() instead of hard-coded length value (#3199)
Co-authored-by: Frederik Schwarzer <frederik.schwarzer@smart-battery-solutions.de>
2021-04-06 16:57:27 +02:00
Paul Fultz II e0f9627201
Fix issue 10226: FP: redundant condition or invalid iterator (#3195) 2021-04-06 11:04:37 +02:00
Daniel Marjamäki 161ea81fd8 XML: Ensure file0 info is kept in multithreaded analysis. Write file0 attribute in top <error> element instead of in the <location> elements. 2021-04-05 12:03:39 +02:00
Paul Fultz II e65ea8575f
Fix issue 10207: FP: derefInvalidIteratorRedundantCheck with ternary operator (#3197) 2021-04-05 11:10:43 +02:00
Paul Fultz II f605f71e49
Fix issue 10225: false positive: knownConditionTrueFalse (#3196) 2021-04-05 10:20:14 +02:00
Yichen 8034a70bd3
Check for libc++ instead of clang to workaround a libc++ bug. (#3194) 2021-04-05 05:24:46 +02:00
Daniel Marjamäki bc05ee62d5 CheckFunctions::checkIgnoredReturnValue; Fixed testrunner 2021-04-05 05:17:29 +02:00
Daniel Marjamäki cf8a423636 Unreachable code; better handling of throw in C code 2021-04-05 04:53:07 +02:00
Daniel Marjamäki a21c81365d one definition rule: Fixed false positive for 'class A::B ..' 2021-04-04 21:29:45 +02:00
Daniel Marjamäki 084bc74080 Fixed #8223 (false negative: Statements following return, break, continue, goto or throw will never be executed.) 2021-04-04 19:43:51 +02:00
Daniel Marjamäki 518fb01553 Fixed #8412 (ignoredReturnValue not issued when return value is changed but not really used (by logical not for example)) 2021-04-04 18:26:07 +02:00
Daniel Marjamäki 44f914eaee astyle formatting
ci skip
2021-04-04 18:20:32 +02:00
Oliver Stöneberg 6397e29f84
cleaned up includes based on include-what-you-use (#3141) 2021-04-03 21:30:50 +02:00
Paul Fultz II 182ae75290
Fix issue 10216: FP containerOutOfBounds with std::array initialized with = {} (#3190) 2021-03-31 22:07:54 +02:00
Oliver Stöneberg 9b974f1b8e
fixed Visual Studio warnings about shadowed members (#3191) 2021-03-31 22:07:20 +02:00
Paul Fultz II 5077663684
Fix issue 9979: false positive: containerOutOfBounds with conditional resize (#3136) 2021-03-30 14:02:28 +02:00
Paul Fultz II 9de976b243
Fix issue 10194: hang with followAllReferences() (#3189)
* Decrease depth faster when there is multiple returns
2021-03-30 11:22:56 +02:00
Ken-Patrick Lehrmann cddaa6d671
10221: Fix setVarId in template code (#3187)
The computation of the classname was not expecting templates. Simply
skipping the template part seems to fix the issue.
2021-03-29 12:16:02 +02:00
Lars Even Almaas 9786f1c34b
Suggested implementation for rule 8.2 (#3169) 2021-03-25 08:25:43 +01:00
Tomasz Kłoczko 8d6828847b
Another gcc11 fix (#3179)
/home/tkloczko/rpmbuild/BUILD/cppcheck-2.4/lib/symboldatabase.cpp: In member function ‘void SymbolDatabase::createSymbolDatabaseExprIds()’:
/home/tkloczko/rpmbuild/BUILD/cppcheck-2.4/lib/symboldatabase.cpp:1443:32: error: ‘numeric_limits’ is not a member of ‘std’
 1443 |                 if (id == std::numeric_limits<nonneg int>::max()) {
      |                                ^~~~~~~~~~~~~~
/home/tkloczko/rpmbuild/BUILD/cppcheck-2.4/lib/symboldatabase.cpp:1443:54: error: expected primary-expression before ‘int’
 1443 |                 if (id == std::numeric_limits<nonneg int>::max()) {
      |                                                      ^~~
/home/tkloczko/rpmbuild/BUILD/cppcheck-2.4/lib/symboldatabase.cpp:1443:47: error: expected ‘)’ before ‘int’
 1443 |                 if (id == std::numeric_limits<nonneg int>::max()) {
      |                    ~                          ^      ~~~
      |                                               )

This patch adds missing `include #include <limits>`

Co-authored-by: Your Name <you@example.com>
2021-03-22 18:43:08 +01:00
Daniel Marjamäki cba0101df5 2.4: Set version 2021-03-21 21:25:54 +01:00
Daniel Marjamäki 42437277dc Update Copyright year 2021-03-21 20:58:32 +01:00
Daniel Marjamäki 51564504a8 astyle formatting 2021-03-20 18:54:46 +01:00
Daniel Marjamäki b2691bda88 Fixed false positive in self check 2021-03-20 18:54:46 +01:00
Paul Fultz II b0ac92ce8f
Report an error if analysis becomes cyclic (#3173) 2021-03-20 14:02:07 +01:00
Tetrix 9b7f1f6280
simplifyCPPAttribute tokenizer strips alignas (#3171) 2021-03-20 10:38:47 +01:00
IOBYTE 1874b9cb0f
fix crash in CheckClass::getFileInfo (#3172)
* fix crash in CheckClass::getFileInfo

* fix another crash

* fix memory leak

Co-authored-by: Robert Reif <reif@FX6840>
2021-03-19 09:19:48 +01:00
IOBYTE b1b7fbb63a
partial revert of b1eaa3021f (#3174)
It is necessary to use a fake NameAndToken in
mTypesUsedInTemplateInstantiation rather than a Token pointer so the
template simplifiers internal state is kept valid when tokens are
deleted. This prevents a use after free.

Co-authored-by: Robert Reif <reif@FX6840>
2021-03-18 09:15:21 +01:00
IOBYTE c9f09fc73f
small template simplifier fixes (#3168)
* small template simplifier optimization

* don't look for template parameter name in default values

* fix cppcheck warning

* add test for TemplateSimplifier::getTemplateParametersInDeclaration()

Also removed TemplateSimplifier::getTemplateParametersInDeclaration()
return value since it wasn't used.

* added another test

Co-authored-by: Robert Reif <reif@FX6840>
2021-03-16 09:31:52 +01:00
Daniel Marjamäki 7d4582d8ef Fixed #9832 (extract configurations; include guards not handled correctly '#if !defined(FILE1_H)') 2021-03-12 18:16:57 +01:00
Rikard Falkeborn 103e52f394
Fix tokenizing of x[i](0) (Fixes #8875) (#3167)
Fix faulty removal of parenthesis when "]" is followed by parenthesis
with a number inside, for example when calling a function pointer in
an array or (perhaps more common) in c++, calling operator ( on an
element in an array.

Fixes #8875 where such wrong simplification lead to a FP with too many
bits shifted due to "<<" was interpreted like a shift operator rather
than a stream output.
2021-03-11 08:16:25 +01:00
Daniel Marjamäki 3502036b14 Usability: Fixed loading of platform file placed in same path as project file 2021-03-05 08:39:09 +01:00
IOBYTE fe4964f22c
fix overloaded template instantiation (#3160) 2021-03-04 08:43:22 +01:00
Rikard Falkeborn 27316e04ed
Fix #10187 (memleak open with fd >= 0) (#3156) 2021-03-03 07:00:28 +01:00
Rikard Falkeborn 42a41e8b41
Fix #9139 (leak when variable has const qualifier) (#3159)
Also, in the tests, change socket/close to resource to get error
messages which say "resource leak" instead of "memory leak".
2021-03-03 06:58:38 +01:00
IOBYTE 8c57e2bb14
fix template simplifier overloaded specialized instantiations (#3154) 2021-02-28 21:52:14 +01:00
Daniel Marjamäki c9bc5a076f Fixed #10014 (-U switch ignored when using --project=compile_commands.json and --force) 2021-02-28 21:43:51 +01:00
IOBYTE bc8eb164a3
fix more daca simplifyUsing hangs (#3152) 2021-02-26 18:30:17 +01:00
Rikard Falkeborn c3eb37972d
Fix #10182 (FN memory leak with if-statement) (#3151)
Improve leak detections in if-statements. This is done by checking
for leaks every time a scope is left. This allows cppcheck to catch
more memory leaks, as well as improve some error messages which now
contain the line where the variable goes out of scope, instead of the
end of the function.
2021-02-26 12:58:52 +01:00
Rikard Falkeborn 951ca2c8b9
Fix #10186 (FP memleak with cast and assignment) (#3148) 2021-02-25 10:55:34 +01:00
Daniel Marjamäki 0988448319 Fixed self-check. Naming conventions 2021-02-25 10:54:29 +01:00
Daniel Marjamäki 849ea6b3c8 Fix compilation errors 2021-02-24 22:12:48 +01:00
PKEuS 141d2ac215 Refactorization: Improved internal implementation of severity and certainty levels
Backported from LCppC.
2021-02-24 22:00:06 +01:00
PKEuS c25b4f1ad6 Fixed false negatives incompleteArrayFill on user defined types (estimate size to determine if it is larger than one byte)
Merged from LCppC.
2021-02-24 21:48:26 +01:00
IOBYTE 9bb57a7b6f
fix #10183 (performance regression (hang) - ScopeInfo3::findInChildren()) (#3147) 2021-02-24 06:36:53 +01:00
IOBYTE fc1cfba5e0
fix simplifyUsing hang parsing class initializer list using {} (#3146)
Co-authored-by: Robert Reif <reif@FX6840>
2021-02-23 20:35:20 +01:00
IOBYTE a07f93f819
fix simplifyUsing crash and hang (#3145) 2021-02-23 09:48:15 +01:00