Commit Graph

6200 Commits

Author SHA1 Message Date
orbitcowboy a7ded1e19f Merge branch 'master' of https://github.com/danmar/cppcheck 2015-01-22 06:53:23 +01:00
PKEuS 7364cc8040 Fixed false positive in fityk: operator new calling constructor 2015-01-22 10:37:31 +01:00
orbitcowboy 2cfb286558 Added test case for #5412. 2015-01-22 06:53:11 +01:00
orbitcowboy dd241501f3 Added test case for #6341. 2015-01-22 06:37:09 +01:00
PKEuS c3e47f7eaa Fixed false positive in CheckUninitVar and internal message 2015-01-21 22:26:44 +01:00
PKEuS 94c3c45350 CheckUninitVar: Use function information from library, bailout for '?' 2015-01-21 22:02:25 +01:00
PKEuS ecb9d87e42 Fixed false positive: Bailout in checkuninitvar.cpp if setjmp is found 2015-01-21 16:49:34 +01:00
PKEuS 8f1e44f1b7 Stricter false positive testing: Perform old and new check on uninitialized variables false positives tests (with a few exceptions for FP in old checker that don't exist in the new one) 2015-01-21 16:45:15 +01:00
PKEuS 81dc96f373 Refactorization: Rearranged code in testuninitvar.cpp, avoid copying of settings 2015-01-21 16:26:27 +01:00
PKEuS 5334aaa25f Refactorization:
- Removed a few unit tests of old uninitialized variable checking expecting other results than same test for new checking
- A few tweaks to new uninitvar checking to improve results when run on tests for old check
- switched some (TODO) tests to new check if the TODO is fixed
2015-01-21 16:17:58 +01:00
PKEuS 346532d312 Fixed false positives in CheckUninitVar::checkStruct() 2015-01-21 13:11:48 +01:00
PKEuS 54de731cac Refactorized CheckUninitVar::checkScope(), fixed false negative 2015-01-21 12:20:03 +01:00
PKEuS 3274a00b82 Moved some more tests to testgarbage.cpp 2015-01-21 10:04:46 +01:00
Martin Ettl fab34a8382 Fixed a few inconclusive warnings regarding const-correctness in cppcheck code base. 2015-01-20 16:50:16 +01:00
Thomas Jarosch ec21134817 Fix false negatives for local suppressions
Introduce a new bool setting jointSuppressionReport
that will be set by the analyseWholeProgram() code path.

When the flag is enabled, unmatched suppressions are
collected after running the final whole program analysis
to prevent false positives for the unusedFunction check.

The check functions in the unit test
for single / multi file suppressions were unified.
2015-01-20 18:47:30 +01:00
orbitcowboy bf1565bd34 Fixed inconclusive warnings regarding const correctness. 2015-01-20 09:09:16 +01:00
orbitcowboy ff415871bd Fixed some const correctness issues in the test suite. 2015-01-19 18:00:05 +01:00
Robert Reif 56dc0b02ef Fixed #6432 (cppcheck fails to detect ctor - partial template specialization) 2015-01-19 16:15:11 +01:00
Robert Reif 3b8540fdc0 Fixed #6424 (false negative: Use of 'class Ns::C' silence Cppcheck) 2015-01-19 06:38:54 +01:00
Matthias Krüger 01dba4062f testrunner: add testcases for fixed crashes in Template code: #5950 #6034 #6108 #6117 #6225 2015-01-18 14:13:59 +01:00
Thomas Jarosch 58cb6cc116 Add new "style" check to catch redundant pointer operations
Doing "&*some_ptr_var" is redundant and might be the remainder
of a refactoring. Warnings for expanded macros are excluded though:
They are often used with and without pointers and
do something like this: "func(&(*macroarg))".

The new check is fully AST based and was given
strong false positive testing on a large code base.
2015-01-18 00:34:07 +01:00
Thomas Jarosch e6f042dadc Multi process check: Sanitize error messages for illegal characters
before sending them across the pipe.

The deserializer died while deserializing
a string containing a binary zero.
2015-01-17 16:12:00 +01:00
Thomas Jarosch 36bcefc39d Don't crash when the deserialization of an error message fails
Found while scanning the code of an
open source project related to onions.
2015-01-17 16:09:58 +01:00
Robert Reif 193645318b Tokenizer: Remove macro in class declaration like 'class DLLEXPORT Fred {}' to be able to handle the class better later 2015-01-17 07:42:49 +01:00
Thomas Jarosch 08985bf68a Throw exception in getVariableFromVarId() if called with out_of_range varId
That way we have a chance to catch code bugs at all.
2015-01-15 18:52:11 +01:00
Thomas Jarosch cf64fd3dad Add more complex variation of the #6406 unit test
This is a false negative right now.
2015-01-15 14:45:10 +01:00
Thomas Jarosch 0286abfb45 Add unit test for #6406 2015-01-14 23:05:33 +01:00
Thomas Jarosch 1cc85bfce3 Add bounds check to getVariableFromVarId()
While poking around the memory leak check,
I managed to trigger an out-of-bounds access
in the symbol database.

Fix it by sanity checking the variable id
passed to getVariableFromVarId().
2015-01-14 23:00:38 +01:00
orbitcowboy a26aa1cd16 testmathlib: Fixed typo in comment, no functional changes. 2015-01-14 00:51:50 +01:00
Robert Reif 68bb197bcb Destructor detected as constructor resulting in false variable not initialized warnings 2015-01-12 06:11:22 +01:00
Martin Ettl 910af75e3a testmemleak: Added missing () in test case. 2015-01-11 10:27:37 +01:00
Martin Ettl 37c89a6b70 Fixed #6311: Add support for GNU get_current_dir_name(). 2015-01-11 10:12:39 +01:00
Aneesh Azhakesan S fe5d2fc245 Fixed #5906 (false negative: 'else if' expression is always false (use library to determine if function is pure)) 2015-01-10 12:21:55 +01:00
PKEuS 7452613479 Refactorization:
- Merged messages exceptThrowInNoexecptFunction, exceptThrowInNoThrowFunction, exceptThrowInAttributeNoThrowFunction and exceptThrowInDeclspecNoThrowFunction into a single message.
- Merged Token::fIsDeclspecNothrow into Token::fIsAttributeNothrow
2015-01-09 20:18:09 +01:00
Daniel Marjamäki 6a8293a8b7 Library: More strict matching of functions 2015-01-08 19:31:41 +01:00
Robert Reif ba1c24ee65 Fixed #6422 (symbol database: put function flags into a single flag variable) 2015-01-08 05:45:31 +01:00
Matthias Krüger 0259b4a672 testgarbage: add code example from #6361 to testrunner 2015-01-07 16:44:46 +01:00
Thomas Jarosch 2cb2161c5d Fix unmatched local suppression error message for "unusedFunction" (#6228)
This fixes a regression from commit
e35329aba3
(fix for #4946)
2015-01-07 15:40:12 +01:00
orbitcowboy 4c2e42a52c alwaysTrueFalseStringCompare: Added more test cases to ensure no FP appears. 2015-01-07 08:38:39 +01:00
orbitcowboy c07b07b8fe Fixed #6415 - FP stringCompare memcmp(ptr, ptr+offset, length). 2015-01-07 08:30:05 +01:00
Daniel Marjamäki a87fb96eaf Uninitialized variables: fix fp when 'a=((b)=c)' is used 2015-01-06 18:03:40 +01:00
Daniel Marjamäki eee9183406 ValueFlow: improved handling of conditional noreturn scope in valueFlowForward 2015-01-06 14:12:35 +01:00
Daniel Marjamäki f2e5fbd30d Uninitialized variables: bailout when ({..}) are used to avoid fp. it can be handled better. 2015-01-06 07:44:04 +01:00
Daniel Marjamäki 1f698ca493 ValueFlow: Fixed valueFlowForward, when condition is false and else-block returns dont set values below the else-code 2015-01-05 16:39:47 +01:00
Daniel Marjamäki fe8d04e840 CheckNullPointer: Fix FP when x is NULL and address is calculated with expression '&x->y.z[0]' 2015-01-05 14:54:24 +01:00
Daniel Marjamäki c5467766e2 ValueFlow: Fix for valueflow analysis after for loop 2015-01-05 14:00:12 +01:00
Daniel Marjamäki a80101f277 CheckMemoryLeak: Fix FP for allocation functions that register memory before returning it 2015-01-05 13:23:38 +01:00
Daniel Marjamäki fb685f096a CheckOther:checkNegativeBitwiseShift: Fix FP when shift is protected by ?: 2015-01-05 10:01:04 +01:00
Daniel Marjamäki d1927e3492 Removed Tokenizer::simplifyStructInit simplification. 2015-01-04 16:48:52 +01:00
Daniel Marjamäki 7bafbfbd6e Tokenizer: cleanup simplification of '!= 0' to avoid FP in 'x[(y & 0x80) != 0]' (linux) 2015-01-04 13:50:54 +01:00
PKEuS e06a4cdf00 Refactorized CheckStl::if_find():
- Added support for find()-like functions to Library::Container
- Use <container> information from library
- Fixed false positive #6402
2015-01-04 12:43:50 +01:00
Daniel Marjamäki f94243f85e CheckMemoryLeak: Fix fp for allocation function that returns success value 2015-01-04 11:46:26 +01:00
Daniel Marjamäki b3c2ea2c4f CheckUninitVar: Fix fp for 'int x=2+x();' when x() is an unseen preprocessor macro 2015-01-04 11:13:20 +01:00
Zachary Blair 22bd20c94a New check: Use make_shared/make_unique (#5673) 2015-01-04 11:07:53 +01:00
PKEuS 11fa185cae Fixed crash on range-based for-loop 2015-01-03 22:36:39 +01:00
PKEuS 7ece58c3a0 CheckStl::stlOutOfBounds() now uses <container> information from Libraries 2015-01-03 22:18:33 +01:00
PKEuS e39729ffcc Library: Add <container> tag to Libraries, provide configuration for std::vector, std::deque, std::array and STL strings
Token: Added function to jump to the next template argument
2015-01-03 22:18:33 +01:00
Daniel Marjamäki eb1c048d2a Tokenizer: Fix wrong simplification when checking linux kernel 2015-01-03 21:35:03 +01:00
PKEuS 267552779d Improved check (#6391): Detect identical code in both branches of ternary operator 2015-01-03 18:01:49 +01:00
Daniel Marjamäki ff11ba9847 Updated copyright year to 2015 2015-01-03 12:14:58 +01:00
PKEuS 1355f49af7 Fixed false positive: Support assignments in CheckStl::if_find() 2015-01-03 11:29:13 +01:00
PKEuS 8885ac3eba Fixed #6217, refactorized CheckStl::if_find(): allow all comparison operators, use AST, fixed wrong unit tests 2015-01-03 11:07:11 +01:00
Martin Ettl 465f74b3bb Fixed #6398 - false negative: (warning) Unnecessary comparison of static strings. 2015-01-02 12:58:04 +01:00
PKEuS 417f42f732 Fixed #6096: bool is an integral type, but there is no portability issue if a pointer is assigned to a bool. 2015-01-02 21:07:02 +01:00
PKEuS 274e1a838a Fixed #5871: Properly parse initialization list in setVarId() if constructor is declared as noexcept 2015-01-02 20:03:06 +01:00
orbitcowboy d53f2f583c Fixed #6388: Support strncasecmp 2015-01-02 14:04:55 +01:00
PKEuS c4fd8919a2 Fixed #6014: Added plausibility check before issuing null pointer messages on function calls defined in library 2015-01-02 13:35:39 +01:00
PKEuS 88990bac59 Fixed #6386: Improved behaviour on unknown language (header file) 2015-01-02 12:32:23 +01:00
Daniel Marjamäki 2831bbd420 ValueFlow: better handling of goto to avoid false positives 2015-01-01 14:29:49 +01:00
Alexander Mai d2caf89706 #6385 crash in Variable::getFlag(). Catch token without variable in fix for #6095. 2014-12-31 18:19:10 +01:00
Daniel Marjamäki 5c2a2a5c22 Fixed #6095 (False positive oppositeInnerCondition - neglecting statements with side-effects) 2014-12-31 15:14:22 +01:00
PKEuS 58f4660c94 Fixed #5223: Bailout in valueFlowForLoop1() for complex conditions
Refactorization: Reuse result instead of calling MathLib::toLongNumber() twice
2014-12-30 19:56:47 +01:00
PKEuS 5dc45bd4ac Fixed #5497: Support designated initializers in array size detection 2014-12-30 19:23:01 +01:00
PKEuS ec826a0e0e Fixed #6022: Support ++%var% in valueFlowForLoop1
Fixed TODO unit test: properly handle loops that are never executed
2014-12-30 18:50:22 +01:00
PKEuS 9e8a66ee40 Fixed #6373: Support bitops in clarifyCalculation check 2014-12-30 17:55:29 +01:00
Thomas Jarosch 17b47f1ce0 New internal check: Catch extra whitespace in match patterns
Inspired by a recent commit from PKEuS.
2014-12-30 14:21:18 +01:00
Robert Reif 9e60f584d9 Fixed #6321: Implemented function Token::swapWithNext(). 2014-12-27 10:53:26 +01:00
Dmitry-Me 14f13afa0a Don't care which type protected operator= returns 2014-12-26 15:38:22 +01:00
Daniel Marjamäki 6194a4eefd Fixed #6357 (Improve check: pointer arithmetic 'p+x' overrun, conditional x) 2014-12-26 09:12:00 +01:00
Daniel Marjamäki 7ab12cea63 Improved pointer arithmetic message 2014-12-25 14:31:46 +01:00
Daniel Marjamäki bc594d52c8 Fixed #6349 (Pointer arithmetic: clarify message) 2014-12-25 10:05:55 +01:00
Daniel Marjamäki 0c086cf247 Incomplete statement: tweaked bailout for '0;' statement using isExpandedMacro() 2014-12-24 21:47:37 +01:00
Daniel Marjamäki 7cfa54f0e0 Fixed #6353 (False positive: CheckBufferOverrun checking reassigned array function parameter) 2014-12-24 14:03:52 +01:00
Daniel Marjamäki fb3f5a159d Token: Added flag for attribute noreturn (#6328) 2014-12-24 12:50:51 +01:00
Daniel Marjamäki de1a91f30d Incomplete statement: tweaked bailout for '(void*)0' using isCasted() 2014-12-23 18:19:33 +01:00
Daniel Marjamäki 1b2a23b3fe Fixed #6350 (Tokenizer::simplifyCast: set Token::isCasted when cast is removed) 2014-12-23 16:16:14 +01:00
Thomas Jarosch d5e10c18d3 checkUnreachableCode(): fix FP for statements that just hide compiler warnings about unused function arguments
Seen throughout the rockbox codebase.
2014-12-22 11:18:23 +01:00
Daniel Marjamäki 10ae551fef CheckBufferOverrun: Use portability warning for pointer arithmetic UB. It can be used by intention and usually works as intended. 2014-12-22 10:56:17 +01:00
Thomas Jarosch bac1dfce86 Add test cases when sizeof is used on struct members 2014-12-22 09:59:34 +01:00
Thomas Jarosch dca65ce3da Fix FP if sizeof is used without parentheses on struct members
Right now we only support checking basic pointer types.
Pointers inside structs are not supported yet.

Consider the tokens "foo@1 . bar@2",
Token::Match( "sizeof ( %varid% )" ) won't match it.
Token::Match( "sizeof %varid%" ) did match it -> FP.
2014-12-22 09:44:08 +01:00
Daniel Marjamäki 93ac5a41cd Fixed #6346 (pointer calculation overflow) 2014-12-22 09:38:00 +01:00
Daniel Marjamäki 293dc1efc7 Fixed #6327 (Unwanted constStatement on (void)0) 2014-12-21 13:42:21 +01:00
PKEuS e03f49360f Merge pull request #484 from simartin/ticket_6181
Ticket #6181: Properly handle >> terminating template parameter lists.
2014-12-21 12:21:17 +01:00
Daniel Marjamäki a95e5bff2b Fixed #6344 (false positive: out of bounds access when array size is unknown) 2014-12-20 18:50:08 +01:00
Daniel Marjamäki b8371ebd87 Revert 2e45df3b. Because there are FP. 2014-12-18 06:37:15 +01:00
orbitcowboy 2e45df3b72 Fixed #6341: false negative uninitvar pattern "return foo ( %var%" 2014-12-17 17:43:31 +01:00
orbitcowboy 4cbbca3db0 Refactoring: Avoid to load posix.cfg multiple times while testing (testother.cpp) (#6336) 2014-12-17 16:33:55 +01:00
Daniel Marjamäki a1537e1a6e Fixed #6339 (false negative: array index out of bounds on allocated buffer using valueflow) 2014-12-17 16:23:48 +01:00
orbitcowboy f13475ceb2 Refactoring of testuninitvar: Splitted large test functions into smaller pieces. 2014-12-16 22:02:03 +01:00
orbitcowboy ade7365cc0 testuninitvar: moved more tests to checkUninitVar2, which does not rely on ExecutionPath. 2014-12-15 19:47:20 +01:00
orbitcowboy bf4b6dfd19 testuninitvar: changed test cases to do not rely on ExecutionPath. 2014-12-15 15:41:03 +01:00
orbitcowboy 32cd7d727d Fixed #6325: false negative: uninitialized variable usage (write, posix). 2014-12-15 10:05:44 +01:00
Simon Martin 4c7a8c5497 Ticket #6181: Properly handle >> terminating template parameter lists. 2014-12-14 15:14:27 +01:00
Thomas Jarosch 6b78ae7c46 Add mmap() / mmap64() / munmap() to posix.cfg. Enables basic leak tracking
Includes function prototype in posix.cfg as comment
for easier overview of the function arguments.
2014-12-14 13:30:24 +01:00
PKEuS 010eb1c8cb Merge pull request #483 from simartin/ticket_6172
Ticket #6172: Properly grok %type%... template parameters.
2014-12-14 17:01:25 +01:00
Simon Martin 859c6381cc Ticket #6172: Properly grok %type%... template parameters. 2014-12-14 14:33:37 +01:00
Daniel Marjamäki 5490fad8c7 Fixed #5840 (False positive (inconclusive): Possible nullpointer dereference - use before for-loop over nested list) 2014-12-14 14:10:42 +01:00
orbitcowboy ac4f7879db posix.cfg: Added support for rewinddir(). 2014-12-10 16:10:03 +01:00
Thomas Jarosch 269a4419f0 Fixed false positives about strdupa() / strndupa() memleak
strdupa() / strndupa() allocates memory on the stack using alloca().
This memory is freed automatically once the current function is left.
2014-12-10 22:23:52 +01:00
orbitcowboy def3491829 posix.cfg: Added support for readdir(). 2014-12-10 17:44:21 +01:00
PKEuS ff5ede342b Fixed #6266: Support noexcept(false) 2014-12-09 23:53:50 +01:00
PKEuS 493ab541ab Fixed #6291 and #6293: Support :: in front of function name in checkUnusedFunctions
Simplified code in CheckUnusedFunctions
2014-12-09 22:04:51 +01:00
PKEuS e9bc3b7acf Fixed #6308: Properly associate Function with Scope for destructors in SymbolDatabase 2014-12-09 21:36:09 +01:00
orbitcowboy b8cca63a76 Improved test coverage of MathLib. 2014-12-03 18:24:27 +01:00
Alexander Mai ec2c4aa2e3 #6301 Unused shared lock variable. Add exception for std::shared_lock() to CheckUnusedVar::checkFunctionVariableUsage_iterateScopes() 2014-12-07 15:32:09 +01:00
Alexander Mai d11eb4931a #6306 false positive with strxfrm NULL argument. Adjust std.cfg in favor of no false positive 2014-12-07 15:24:27 +01:00
Alexander Mai c2584aa635 #6303 crash in CheckBufferOverrun. Add check on loop variable in CheckBufferOverrun::checkScope(). 2014-12-04 20:49:58 +01:00
Robert Reif c5bfd21d48 Tokenizer::simplifyTypedef: Add test that #5191 is fixed (function pointer) 2014-12-04 05:43:58 +01:00
Daniel Marjamäki e3892a95b5 Fixed #6290 (Tokenizer: Because 'and' is not simplified to '&&' there are false positives) 2014-12-03 16:32:05 +01:00
Robert Reif 418c2e51a0 Fixed #3314 (cppcheck incorrectly reporting Syntax error.) 2014-11-28 17:44:36 +01:00
Robert Reif 0dad8b64e8 Fixed #6268 (False positive functionStatic (inconclusive) - nested namespaces) 2014-11-27 06:29:33 +01:00
Alexander Mai 1779921306 Increase test coverage for MathLib 2014-11-26 17:35:32 +01:00
Dmitry-Me f926958acb Fix false positive about return type when there's =delete in operator= declaration 2014-11-25 15:52:52 +01:00
Daniel Marjamäki a002654c47 Reverted refactoring 828417c for now. It caused a major slowdown in the unused functions checking. 2014-11-24 06:37:08 +01:00
Frank Zingsheim 9497732ac8 Fixed #6238 (false positive with double fopen) 2014-11-20 22:19:39 +01:00
Daniel Marjamäki 051d42ae6b astyle formatting 2014-11-20 14:20:09 +01:00
orbitcowboy 4a2a4474c9 Fixed #6281: MathLib: Long integer suffix i64 is not supported. 2014-11-20 10:23:09 +01:00
orbitcowboy f5d804f71a running astyle 2014-11-20 10:13:03 +01:00
Robert Reif d12f14844a Fixed #6279 (False Positive: Member variable 'Fred::i' is not initialized in the constructor) 2014-11-20 06:18:29 +01:00
Robert Reif b7c9187539 Fixed #6280 (MathLib: binary literals are integers) 2014-11-19 06:43:52 +01:00
Alexander Mai 1c191845fb Fix invalid assertion from recent commit. Make single argument givenACodeSampleToTokenize ctor explicit. 2014-11-18 19:52:06 +01:00
PKEuS 4163f1e122 Fixed #6260 - C++11 style array initialization 2014-11-18 19:50:09 +01:00
PKEuS 428587f3d4 Fixed #6275: Simplification of = (NULL); to = 0; 2014-11-18 19:39:38 +01:00
Alexander Mai 85c02df56c Fix compiler warning. run astyle 2014-11-18 19:36:47 +01:00
PKEuS ad8749c0bd Fixed #6278: Remove casts to references to pointers in Tokenizer::simplifyCasts() 2014-11-18 19:23:59 +01:00
Alexander Mai 0ba3c15c52 Cure null pointer access within Scope::findFunction introduced by recent cs 2014-11-17 23:05:15 +01:00
Robert Reif c5e15950df Fixed #6230 (SymbolDatabase: Wrong function() is set for token) 2014-11-17 16:04:44 +01:00
Robert Reif 7c4a137e14 Fixed #6274 (MathLib::isFloat doesn't recognize long double literal suffix L or l) 2014-11-17 06:53:32 +01:00
Alexander Mai ea94b2748f #633 Adding tests for some MathLib member functions, should reach 100% function coverage now 2014-11-16 18:09:21 +01:00
Daniel Marjamäki 828417c934 CheckUnusedFunction: Refactorings to use same infrastructure for whole program analysis as CheckUninitVar and CheckBufferOverrun 2014-11-15 18:44:23 +01:00
Daniel Marjamäki de7e9223b8 Fixed #6272 (Improve check: multifile checking in checkbufferoverrun) 2014-11-15 10:43:49 +01:00
Daniel Marjamäki 149fe74d9d astyle formatting 2014-11-14 21:43:37 +01:00
orbitcowboy b9a9f51fe0 MathLib: Added test for isDec() and removed not required state. 2014-11-14 04:29:35 +01:00
Dmitry-Me cb9a6c1cb5 Don't show warning for same expressions alongside == in static_assert 2014-11-13 16:04:34 +01:00
Daniel Marjamäki 189dfd64f7 Revert "Fixed #6230 (SymbolDatabase: Wrong function() is set for token)"
This reverts commit 685fce6b91.
2014-11-11 07:29:16 +01:00
Daniel Marjamäki ea765c24f2 Fixed #3262 (Tokenizer: wrong 'return a=1,b=2,...;' simplification;) 2014-11-10 17:31:19 +01:00
Simon Martin cc6b51f2d9 Ticket #6059: Properly handle class... in parameter lists. 2014-11-07 23:08:54 +01:00
Daniel Marjamäki 685fce6b91 Fixed #6230 (SymbolDatabase: Wrong function() is set for token) 2014-11-07 11:10:20 +01:00
Robert Reif 1f32e9eee5 Symbol database: added test for findfunction 2014-11-07 10:46:31 +01:00
Daniel Marjamäki 8012ac9562 Fixed #5993 (FP: memleak (linux list)) 2014-11-07 07:44:12 +01:00