Commit Graph

647 Commits

Author SHA1 Message Date
Daniel Marjamäki 86c84029e3 New check: Check public interface of classes (#8248) 2017-10-20 02:02:51 +02:00
Florin Iucha 6e737082da Store the defined types in a map, for faster lookup 2017-10-17 09:00:14 +02:00
Ayaz Salikhov be2c65eb58 Simplify int vs bool 2017-10-08 07:54:39 +02:00
Dmitry-Me 7e823e6d8e Extract repeating checks, break loop early 2017-09-05 00:04:48 +03:00
Dmitry-Me 79f74fc4d3 Break loop early 2017-09-05 00:00:02 +03:00
Dmitry-Me 7c8cb29d14 Extract repeating checks 2017-09-04 23:58:14 +03:00
Dmitry-Me 5885988b1f Cache and reuse value 2017-09-04 23:33:52 +03:00
Dmitry-Me aece2254d7 Put faster checks first 2017-09-04 23:33:14 +03:00
Dmitry-Me f7ab8c5ebb Drop unneeded parentheses
Those are a misleading leftover from old code
2017-09-04 22:49:05 +03:00
Dmitry-Me 6303437163 Resolve C4800 2017-08-15 17:42:56 +03:00
Dmitry-Me b995e59ff2 No need for counting here 2017-08-14 18:06:23 +03:00
Ayaz Salikhov b8cd7dbb5c Use nullptr instead of 0 or NULL (#936) 2017-08-09 20:00:26 +02:00
Robert Reif f5044bb65f Fixed #8142 (false positive: The class 'B' has 'copy constructor' but lack of 'operator='.)
Do not count static member variables when trying to figure out if
'operator =' is needed.
2017-08-01 19:52:41 -04:00
Daniel Marjamäki 01f023dc0a CheckClass: Refactor hasAssignSelf to use AST 2017-07-28 23:49:11 +02:00
orbitcowboy 0e575ce12c Modernize: make use of 'nullptr' and added a rule-file for finding non-nullptr (zero) initializations. 2017-07-28 15:20:43 +02:00
Daniel Marjamäki a3916c501c Refactor loop, use continue 2017-07-26 22:03:55 +02:00
Steve Browne b58562fc7d Added test cases for catching when assignment comes after an operator, compound assignment, or comparison for ticket #7429 and fixed the tests. 2017-05-28 16:00:06 +02:00
Ayaz Salikhov 28aa939d69 iwyu - include what you use 2017-05-27 04:33:47 +02:00
PKEuS b1f4bd7504 Refactorization: Reimplemented Settings::_enabled as a bitfeld instead of std::set (#7995) 2017-04-11 11:49:26 +02:00
Daniel Marjamäki 1faca91c1d Added 'endsWith' utility function. This will make compiling the democlient easier. 2017-04-01 18:14:18 +02:00
PKEuS ea215c3b7b Fixed false positives in CheckClass::checkConst() due to unmatched function overloads
Fixed function matching if constness mismatches
2017-04-01 10:19:32 +02:00
Alexander Alekseev abba762d42 New check: checking for copy ctor and eq operator co-existence 2017-03-24 12:00:20 +01:00
PKEuS 996501a449 Fixed false positive #7953: Support type conversion operators returning pointers 2017-03-23 18:12:46 +01:00
PKEuS 2f0db369f0 Refactorization: Avoid construction of empty strings by using emptyString 2017-03-01 10:50:50 +01:00
Matthias Krüger 6f1e7e897d simplify if(tok && Token::{simple,}Match) to if(Token::{simple,}Match). 2017-02-06 15:37:12 +01:00
Matthias Krüger 01e5f14bf8 CheckClass::virtualDestructorError and a variation of CheckNullPointer::nullPointerError would print inconclusive,warning messages altough no --enable=warning was given. Fix. 2016-11-23 00:13:09 +01:00
PKEuS 02d8f691f8 Fixed false positive: Do not show useInitializationList message for enums 2016-11-22 12:09:30 +01:00
Harald Scheidl 0de47f709e Fixed #7755 (false positive: member variable is not initialized in the constructor) 2016-10-26 10:39:53 +02:00
Dmitry-Me d2e667ae7b Put apostrophes consistent with other similar messages 2016-10-18 15:45:08 +03:00
Simon Martin dc61b6342d Ticket #7068: Treat "memset(&this->member, ..." as member initialization. 2016-10-01 13:46:58 +02:00
Daniel Marjamäki 4d22ada078 Fixed #5839 (False positive: Function can be const, if this is passed to functor) 2016-09-04 16:36:04 +02:00
Daniel Marjamäki ce7bfba416 Refactoring CheckClass::checkConst. Use continue. 2016-09-04 16:06:54 +02:00
Daniel Marjamäki 54db79305b Redo refactoring of CheckClass::checkConst. 2016-09-04 16:02:59 +02:00
Daniel Marjamäki 530a05e40e Refactoring CheckClass::checkConst. Use continue. 2016-09-04 15:38:56 +02:00
Daniel Marjamäki 706877df2d astyle formatting
[ci skip]
2016-08-24 12:43:45 +02:00
Roberto Martelloni 4c6f4f6708 CWE mapping of functionConst, functionStatic, initializerList, badBitmaskCheck, knownConditionTrueFalse, invalidTestForOverflow, unhandledExceptionSpecification, coutCerrMisusage,
invalidPrintfArgType_int
2016-08-23 16:48:36 +01:00
Roberto Martelloni 41dee04e90 CWE mapping of assignBoolToFloat, strncatUsage, sizeArgumentAsChar, terminateStrncpy, bufferNotZeroTerminated, negativeArraySize, noExplicitConstructor, virtualDestructor 2016-08-14 18:23:41 +01:00
Dmitry-Me 89e8f51a28 Explicit continue instead of init-set-check 2016-08-05 15:05:37 +03:00
Daniel Marjamäki 50352c8d69 Fixed #3552 (Don't warn about missing ctor for class inside union) 2016-05-25 19:05:16 +02:00
Daniel Marjamäki 99fc13ee70 Fixed #6968 (unusedPrivateFunction not correct, called by inner class) 2016-05-16 20:52:50 +02:00
Daniel Marjamäki 65998f1d7c CheckClass: previous change introduced false positives when Token::function() is wrong. Avoid those false positives. 2016-05-16 10:55:22 +02:00
Daniel Marjamäki bce15b1ade CheckClass: refactored the code, use symboldatabase instead of name comparisons when possible, fixed a FN. 2016-05-16 09:36:26 +02:00
PKEuS 17ccb0fbe6 CheckClass::checkMemsetType(): Skip arrays of pointers (#7456) 2016-05-04 13:38:36 +02:00
Alexander Mai 0533d7bf9c Run astyle + minor refactoring 2016-02-27 16:03:50 +01:00
Roberto Martelloni d3645d874e Mapped toomanyconfigs ,AssignmentAddressToInteger
,AssignmentIntegerToAddress ,CastIntegerToAddressAtReturn
,CastAddressToIntegerAtReturn ,assertWithSideEffect ,assignmentInAssert
,uselessAssignmentArg ,uselessAssignmentPtrArg
,comparisonOfFuncReturningBoolError
,comparisonOfTwoFuncsReturningBoolError ,comparisonOfBoolWithBoolError
,incrementboolean ,comparisonOfBoolWithInt ,compareBoolExpressionWithInt
,negativeIndex ,pointerOutOfBounds ,arrayIndexThenCheck
,possibleBufferAccessOutOfBounds ,argumentSize
,arrayIndexOutOfBoundsCond ,noConstructor ,copyCtorPointerCopying
,noCopyConstructor ,uninitMemberVar ,operatorEqVarError
,unusedPrivateFunction ,memsetClassFloat ,mallocOnClassWarning
,operatorEq ,thisSubtraction ,operatorEqRetRefThis ,operatorEqToSelf
,useInitializationList ,duplInheritedMember ,assignIfError
,comparisonError ,multiCondition ,mismatchingBitAnd
,oppositeInnerCondition ,incorrectLogicOperator ,redundantCondition
,moduloAlwaysTrueFalse to their CWEs ids.
2016-02-26 23:53:52 +00:00
PKEuS 5d9f275ff8 Fixed false positive uninitMemberVar with member function of template (#7205) 2016-01-30 20:18:13 +01:00
Daniel Marjamäki 5e10e680da CWE: refactoring. use constants instead of magic numbers. 2016-01-25 20:01:48 +01:00
Roberto Martelloni 5ce69da02d Mapped 26 errors to their CWEs ID. 2016-01-24 20:53:05 +00:00
Dmitry-Me 499e15d96a Cleanup variable names, omit redundant actions 2016-01-11 13:04:52 +03:00
Lauri Nurmi 996c9244d8 Update copyright year to 2007-2016. 2016-01-01 15:34:45 +02:00
Dmitry-Me 7fdbd8f0ca Use set instead of list 2015-12-25 16:19:27 +03:00
Dmitry-Me 458f0da197 Reduce variable scope, better name 2015-12-24 17:08:49 +03:00
PKEuS 940d569980 Refactorization: Removed redundant %any% patterns. 2015-12-24 14:40:48 +01:00
Alexander Mai e69377d5a8 #7183 CheckClass::checkMemset() uint overflow. Plus some minor refactoring 2015-12-05 18:22:01 +01:00
PKEuS 308fd1ba50 Fixed false positive 'noCopyConstructor' for static member variable (#7198) 2015-12-04 18:26:49 +01:00
PKEuS 32e2fb2f78 Refactorization: Prefer Token::simpleMatch over Token::Match also for non-const patterns. 2015-12-03 13:04:55 +01:00
Alexander Mai f762affea0 Small refactoring: replace NULL by nullptr, remove redundant static keyword, Tokenizer::setVarId() uses const variable 'notstart' 2015-11-30 22:13:49 +01:00
PKEuS e8522c7883 Small refactorizations:
- #include cleanup
- Use std::array instead of std::vector
- Do not create a stringstream to concatenate 4 strings
- Use std::cout instead of printf
2015-11-29 10:56:44 +01:00
PKEuS ac17541ca9 Refactorizations:
- Fixed a few more MSVC warnings by using correct types
- Store severity as enum instead of string in Settings::Rule
2015-11-28 12:30:21 +01:00
Daniel Marjamäki 6b124a37d8 Cleanup some casts 2015-11-28 10:11:07 +01:00
Daniel Marjamäki 0f9d90d2be Changed Copyrights. Removed my name. 2015-11-18 20:04:50 +01:00
PKEuS 41fbc5355d Revert "Partially reverted 5cd36d6f8a for upcoming release."
This reverts commit 5f8a8aba6d.
2015-11-15 10:04:27 +01:00
Alexander Mai bda9c8c2d5 --exception-handling now prints callstack on SIGINT, allows to debug program hangs. Also add handler for some more signals. 2015-11-14 19:59:22 +01:00
PKEuS 5f8a8aba6d Partially reverted 5cd36d6f8a for upcoming release. 2015-11-14 18:53:49 +01:00
Daniel Marjamäki b10110b5ac CheckClass: Removed noExplicitCopyMoveConstructorError after discussion in http://sourceforge.net/p/cppcheck/discussion/general/thread/b2ce9d3d/. 2015-11-13 12:48:26 +01:00
PKEuS 5cd36d6f8a Refactorization: Use varid instead of variable name in CheckClass::initializeVarList() and fixed issue in setVarId().
Fixed internal warning.
2015-11-09 23:00:14 +01:00
PKEuS db342ea910 Handle alias variables in CheckClass::initializeVarList() (#6921) 2015-11-09 21:02:06 +01:00
PKEuS aca8a69f5e Skip over lambdas in CheckClass::checkPureVirtualFunctionCall() (#4992) 2015-11-09 20:15:26 +01:00
Daniel Marjamäki 8317369c91 Explicit constructors: don't warn for abstract classes unless C++11 is used. 2015-11-09 08:36:47 +01:00
PKEuS a5f577d179 Support range-based for-loop in CheckClass::checkConst() (#5514) 2015-10-26 18:48:01 +01:00
Simon Martin 0f7e20c11d Ticket #7017: Properly interpret operator= return type for template classes in CheckClass::operatorEq. 2015-10-02 23:23:44 +02:00
Matthias Krüger 49e2573b5c fix -Wodr warning/violation putting struct 'VarInfo' into anonyous namespace
Was:

lib/checkclass.cpp:1994:8: warning: type ‘struct VarInfo’ violates one definition rule [-Wodr]
 struct VarInfo {
        ^
lib/checkleakautovar.h:32:7: note: a different type is defined in another translation unit
 class CPPCHECKLIB VarInfo {
       ^
lib/checkclass.cpp:1998:21: note: the first difference of corresponding definitions is field ‘var’
     const Variable *var;
                     ^
lib/checkleakautovar.h:40:39: note: a field with different name is defined in another translation unit
     std::map<unsigned int, AllocInfo> alloctype;
2015-09-08 16:57:28 +02:00
Simon Martin b4b636b6a2 Ticket #6959: Properly handle arrays of pointers in CheckClass::constructors. 2015-08-29 13:11:00 +02:00
Simon Martin 101cebbde1 Ticket #6957: Properly handle arrays of pointers in CheckClass::constructors. 2015-08-28 23:06:39 +02:00
Dmitry-Me 0cef076f10 Prefer previous() to tokAt(-1) 2015-08-28 15:19:24 +03:00
Simon Martin 2e2f9facf5 Ticket #6953: Fixed flawed logic in PR#650. 2015-08-27 23:35:22 +02:00
Simon Martin 8beb95e179 Fix CheckClass::checkMemset for arrays of pointers. 2015-08-23 19:57:58 +02:00
PKEuS ab8afec3eb Refactorizations:
- Avoid unnecessary loop iterations
- Avoid unnecessary condition checking
- Reduced code duplication in symboldatabase.cpp
2015-08-16 14:23:07 +02:00
PKEuS 4d80df2f4a Added pointer to Type to Token (similar to Token::Variable() and Token::function()):
- Accessible via Token::type()
- Renamed former Token::type() to Token::tokType()
- Removed SymbolDatabase::isClassOrStruct()
2015-08-15 11:19:21 +02:00
PKEuS b0bf69bae7 Fixed false positive #6763 and reordered conditions
Ran AStyle
2015-08-14 12:50:45 +02:00
PKEuS 8ed0180279 Use C++11 string.back() instead of string[string.length()-1] 2015-07-25 17:19:53 +02:00
PKEuS a3eb725c3f Support C++03-style of declaring a copy ctor as deleted (#6585) 2015-07-21 13:46:50 +02:00
Alexander Mai defee734f5 #6846 segmentation fault (invalid code) in CheckClass::hasAssignSelf 2015-07-20 19:04:34 +02:00
Alexander Mai 6e03e7dca2 Remove some code checking for invalid class hierarchy which got obsolete since 480a5672b0. Run astyle 2015-07-01 07:50:13 +02:00
Alexander Mai 40d7baa6bb Fix more (potential) multi-threading issues by moving static local vars (non-POD-type) to file scope 2015-06-13 16:22:43 +02:00
amai2012 e41beb4f8d Fix #6718 and #6719 (crashes on garbage code).
Local fixes avoiding access to NULL-token.  Also minor correction to
TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates()
2015-05-29 18:34:00 +02:00
Alexander Mai f0bc300198 #6510 False positive performance warning for std::list::size(). Fix this and other similar false positives. Refactoring of Variable::isStlType(), use fail-safe std::set instead of plain array. Run astyle 2015-05-17 20:02:41 +02:00
Daniel Marjamäki 88f59ad7e8 Partial fix for #6656 (Allow that CWE is mapped for error message) 2015-04-25 17:48:11 +02:00
Daniel Marjamäki ad6db2ba81 Reverted 105de8e917, new checker had FPs that need to be fixed. 2015-04-25 15:35:31 +02:00
Matthias Krüger 42f0955e3f Move more setting checks out of loops and use const bools instead. Reorder a few related checks.
Follow up to eedcb6abcb .
2015-04-10 14:31:19 +02:00
Gustav Palmqvist 105de8e917 #220 uninitialized variable: using variable in ctor before it has been initialized. Implement new check usageBeforeInitialization 2015-04-07 22:01:13 +02:00
Matthias Krüger eedcb6abcb move setting flags checks out of for loops, make them const. 2015-04-07 07:23:28 +02:00
Frank Zingsheim 1f5265c1bd Fixed #6253 ([False Positive] Variable not initialized in the constructor) 2015-04-06 19:47:21 +02:00
Matthias Krüger 592177200a don't print warning message if --enable=warning is not given.
message was of type:
(warning) Call of pure virtual function 'foo' in constructor.
2015-04-06 13:34:44 +02:00
Dmitry-Me 0383998aea Better variable name 2015-03-23 11:58:56 +03:00
PKEuS cd84d78e92 Ran AStyle, fixed VS2015 warning in symboldatabase.h 2015-03-11 20:26:53 +01:00
Jakub Melka e1e1dbfe97 Ticket #695: Fixed VS 2010 issue, switched to "style" severity, changed error messages and updated unit tests 2015-03-10 19:35:12 +01:00
Jakub Melka 2af9212b16 Ticket #695: new style check : explicit declaration of ctor 2015-03-07 20:07:54 +01:00
Alexander Mai 26c2c4a824 Extend verbose message for memsetClassFloat 2015-02-22 15:41:02 +01:00
PKEuS 18b0e14590 Refactorizations: Fixed a pattern in checkbufferoverrun.cpp, simplified one in checkclass.cpp 2015-01-31 12:32:05 +01:00