Commit Graph

10730 Commits

Author SHA1 Message Date
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 28a7bb63ec Parser; simplify (break out) init expression from if/switch/range-for 2021-04-25 14:37:27 +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 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 bccc0607d1 astyle formatting
[ci skip]
2021-04-22 19:08:24 +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 bfb98dbf51 TemplateSimplifier: updated output of uninstantiated c++17 fold expressions 2021-04-21 13:13:11 +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
Ken-Patrick Lehrmann 5768c3a726
Check stat return value in addFiles2 (#3214) 2021-04-18 21:52:14 +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
Daniel Marjamäki fe87afb2f9 TestTokenizer: Align function pointer test case names 2021-04-18 12:33:04 +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
IOBYTE 5568ac95e7
fix simplifyUsing debug warning for: using value_type = const ValueFlow::Value; (#3211) 2021-04-17 14:20:16 +02:00
Daniel Marjamäki c98afa83fd Tokenizer; Add test for c++14 lambda expression 'lambda=[value=1]{...}' 2021-04-16 15:18:02 +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 f62d9d5853 std.cfg: Fixed bufferAccessOutOfBounds false negative for strncmp(). 2021-04-13 19:13:00 +02:00
orbitcowboy 03bdcc4c42 Attempt to make CI happy 2021-04-13 16:57:31 +02:00
orbitcowboy e869452240 #10244: Fixed false negative: bufferAccessOutOfBounds 2021-04-13 16:40:38 +02:00
orbitcowboy 44c8b315c6 Attempt to make CI happy 2021-04-13 14:44:59 +02:00
orbitcowboy 040e58f943 std.cfg: strxfrm(): Added minize values to arg1 and arg2 and a TODO test case 2021-04-13 14:07:45 +02:00
orbitcowboy cf211610d3 wxwidgets.cfg: Fixed wrong configuration for wxLogApiError(). This function does return after appending data to wxLog(). Ensure that no duplicateBreak-warning is issued in case code resides afterwards. 2021-04-13 13:07:15 +02:00
Daniel Marjamäki eacc9e552e Function::returnsReference: handle type scope better 2021-04-10 14:31:50 +02:00
orbitcowboy f7e6d216b2 Running astyle [ci skip] 2021-04-09 08:53:32 +02:00
orbitcowboy b5719418ea #8206 - Added a regression test 2021-04-09 08:53:01 +02:00
orbitcowboy 260eb4acac Running astyle [ci skip] 2021-04-09 08:46:47 +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
orbitcowboy e60d79e2c9 wxwidgets.cfg: Added tests for commit ccb2cb26b2 2021-04-07 07:57:27 +02:00
Daniel Marjamäki 73e698b84d Fixed #9214 (Tests are run on simplified token list) 2021-04-06 21:21:53 +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 93f46f6e7b Fix testrunner after file0 tweaks 2021-04-05 13:11:23 +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
Daniel Marjamäki de2e836727 test/cfg/windows.cpp; Uncommented TODO, Cppcheck now writes a warning as it should about unused function return value 2021-04-05 05:20:42 +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
Oliver Stöneberg 052de79b6d
some test/CI related refactoring and cleanup (#3163) 2021-04-03 21:22:39 +02:00
Daniel Marjamäki 9ce0235e8e std.cfg: Fixed configuration of mbstowcs 2021-04-03 10:42:24 +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
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
DGarry82 77716ee398
fix w64-mingw32-ld linking error (#3184)
* fix w64-mingw32-ld linking error

use shlwapi instead of Shlwapi.lib in mingw-w64 build environment
(prevents "/usr/bin/x86_64-w64-mingw32-ld: cannot find -lShlwapi" error)

* same MinGW shlwapi fix for {tests,tools}/CMakeLists.txt

Co-authored-by: Igor Rondarev <igor.rondarev@gmail.com>
2021-03-29 17:04:42 +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
orbitcowboy e23a967215 #4750 Added a regression test 2021-03-28 09:29:46 +02:00
orbitcowboy 185a5e1ee6 #7682 Added regression test 2021-03-26 10:54:08 +01:00
orbitcowboy 6fd916a90f #3763 Added regression test 2021-03-26 10:01:44 +01:00
Lars Even Almaas 9786f1c34b
Suggested implementation for rule 8.2 (#3169) 2021-03-25 08:25:43 +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
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
orbitcowboy 8fffb84aad Running astyle [ci skip] 2021-03-16 09:44:58 +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
orbitcowboy 2a40ce6430 windows.cfg: Added support for more defines from WinBase.h and Winnt.h 2021-03-02 10:48:37 +01:00
Daniel Marjamäki fef956f3f0 Testing; Moved test/cli tests from travis to github actions 2021-03-01 18:49:59 +01:00
Daniel Marjamäki 6b166eb5a7 test/cli/test-other-projects.py: Temporarily disable test (to make Travis happy) 2021-02-28 23:11:25 +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
Daniel Marjamäki 199f9608cb TestSuite: Fixed getLocationStr 2021-02-27 04:33:16 +01:00
Daniel Marjamäki 7106e1f48f Moved TestTokenizer::simplifyCasts tests to TestSimplifyTokens 2021-02-27 04:19:54 +01:00
Daniel Marjamäki 81c7fa0348 Moved TestTokenizer::tokenize6 to TestSimplifyTokens 2021-02-27 04:07:33 +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
Daniel Marjamäki 1adea5c3b0 Move simplifyKnownVariables tests to TestSimplifyTokens 2021-02-25 21:32:56 +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 e03851f51c Fix compilation error 2021-02-24 22:31:46 +01:00
Daniel Marjamäki 15bc7ad5cb Fix compilation error 2021-02-24 22:20:11 +01:00
PKEuS 3998836b03 Refactorization: Improved string handling in test suite
Merged from LCppC.
2021-02-24 22:05:23 +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
Daniel Marjamäki 2baeeeb02f astyle formatting 2021-02-24 21:48:26 +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
shaneasd 02ac2b08a0
Fix some warnings (#3096) 2021-02-23 08:19:05 +01:00
Daniel Marjamäki 99ff242dde astyle formatting
[ci skip]
2021-02-20 13:33:57 +01:00
PKEuS 29a6031cea Fixed more false negatives (and recently introduced false positives) literalWithCharPtrCompare by using ValueType
Merged from LCppC.
2021-02-20 13:29:59 +01:00
Lukasz Czajczyk 0a06a083af
Additional macros (#3106) 2021-02-20 13:19:06 +01:00