Commit Graph

731 Commits

Author SHA1 Message Date
PKEuS 7a1e64fdd4 Replaced unsafe local isFunction() function by symboldatabase. 2012-09-29 11:32:11 +02:00
PKEuS c17853949d Fixed scope handling problems with CheckOther::checkComparisonOfFuncReturningBool(), removed its experimental status. 2012-09-29 11:23:30 +02:00
Daniel Marjamäki 52be4a5925 Disabled checkComparisonOfBoolWithBool since there are false positives. Ticket #2617 2012-09-28 19:11:36 +02:00
Daniel Marjamäki ff4f8b58f3 Disable checkComparisonOfFuncReturningBool check because of false warnings. Ticket #2617 2012-09-28 18:51:10 +02:00
Edoardo Prezioso 7362ca9e8f Fixed #4242 (segmentation fault of cppcheck (invalid code: '<')) 2012-09-28 11:24:35 +02:00
Mohit Mate 9e297c95f2 Fixed #2617 (improve check: comparing boolean with '<') 2012-09-26 18:18:36 +02:00
PKEuS 508e9394d3 Added some nullpointer-checks and removed some redundant ones based on VS2012 code analysis results. 2012-09-17 15:22:51 +02:00
PKEuS 5237ed2de9 Message refactorization: checkother.cpp 2012-09-16 19:44:02 +02:00
PKEuS 9a624576f4 Revert "CheckOther::clarifyStatement: improved message to show what's the 'bad' and the 'good' expression."
This reverts commit f8591f9004.
2012-09-15 20:19:02 +02:00
Daniel Marjamäki 7ec825cd5d Cppcheck: Fixed Cppcheck warning about variable scope 2012-09-15 15:54:52 +02:00
PKEuS 22a8e3f4e6 Replaced Tokenizer::getFunctionTokenByName() by SymbolDatabase::findFunctionByName(), which handles scopes slightly better. 2012-09-11 18:03:47 +02:00
PKEuS 5940d77a62 Disabled C++ specific checks and simplifications when checking a C or non-C++ file. 2012-09-10 19:02:32 +02:00
PKEuS a4b5824dec New internal check: checkRedundantNextPrevious().
Fixed findings by new internal check
2012-09-07 12:36:40 +02:00
PKEuS e4a693eaab Refactorizations:
- Fixed several findings of CheckInternal.
- Removed some debug code from CheckOther::checkRedundantAssignment().
2012-09-07 11:59:20 +02:00
Edoardo Prezioso 097d0816d0 Fixed #4150 (new ineffective statement check warning wrong). 2012-09-06 17:48:30 +02:00
Arpit Chaudhary 67e40a85e5 Improved check for shifting by negative values and removed false positives 2012-09-05 16:09:40 +02:00
Nilesh Kumar c7633fc73c Fixed #3645 2012-09-05 13:48:00 +02:00
Zachary Blair 8546bcc94e Fixed #2029 (new check: free invalid address) 2012-09-04 23:31:23 -07:00
Daniel Marjamäki 2197b84d78 astyle formatting 2012-09-04 16:29:23 +02:00
Edoardo Prezioso f8591f9004 CheckOther::clarifyStatement: improved message to show what's the 'bad' and the 'good' expression. 2012-09-04 02:07:55 +02:00
anuraggarg011 b156c727b0 Fixed #3939: Support ****foo++; 2012-09-03 17:10:27 +02:00
Ankita Gupta c3a65dca40 Fixed #3793 (improve check: calculation in sizeof) 2012-09-03 15:56:10 +02:00
PKEuS 27cafd495a Don't bailout for noreturn functions in checkRedundantAssignments outside switch. 2012-09-03 12:03:30 +02:00
PKEuS d98ee357d4 Fixed crash #4135 when using Q_DECLARE_METATYPE 2012-09-03 11:30:36 +02:00
PKEuS 2be2738c6e Moved duplicate code into function in CheckOther::checkRedundantAssignment() 2012-09-03 10:46:51 +02:00
PKEuS 81ff721113 Fixed variable shadow warning 2012-09-02 17:00:16 +02:00
PKEuS 7bd732efe4 Invented a fix that compiles on GCC and doesn't crash. 2012-09-02 16:53:38 +02:00
PKEuS 794a491515 Fixed two other compilation errors on GCC. 2012-09-02 16:42:38 +02:00
PKEuS 2d64b69cf4 New check: Detect redundant assignment to a variable and redundant copying to a buffer
This check partially replaces the check for redundant assignments in switch
2012-09-02 13:09:32 +02:00
pranav1509 6f6baa67e4 Added more patterns to redundant condition check. 2012-09-01 13:39:32 +02:00
PKEuS 808c3468c9 New check: detect suspicious comparison of string literal with char* variable
Bugfix: Update Token type when varId is set
2012-08-24 14:25:17 +02:00
PKEuS 76fbcce13f Restored (intentional) content of screwed up commits 1bcdf4ce3d and 674f7980d519712ff16d8f874dfe55a84deb4b5b:
- New check (Inconclusive): Array filled incompletely with memset/memcpy/memmove
-- This check only warns if the number of elements is given as size in bytes to memset, memcpy or memmove and if the size of an element is larger than 1 Byte. It does not warn for random numbers

- New check: Detect ineffective statements like '*foo++;' (Should be: '(*foo)++;')

Sorry for the inconveniences.
2012-08-24 11:28:50 +02:00
Edoardo Prezioso 0f1accc2da Revert latest two commits as they break the compilation and the style. PKEuS??? 2012-08-24 00:10:19 +02:00
PKEuS 1bcdf4ce3d New check: Detect ineffective statements like '*foo++;' (Should be: '(*foo)++;') 2012-08-23 12:28:40 -07:00
PKEuS 674f7980d5 New check (Inconclusive): Array filled incompletely with memset/memcpy/memmove.
This check only warns if the number of elements is given as size in bytes to memset, memcpy or memmove and if the size of an element is larger than 1 Byte. It does not warn for random numbers
2012-08-23 11:27:00 -07:00
Arpit Chaudhary 7c8da17c44 Added check for detecting if a variable or number is shifted by negative right operand. Statements like:
int i = -1;
 a << i;

 would result in an error message stating undefined behavior.
2012-08-22 15:44:20 +02:00
Kumar Ashwani afe030ce9b Fixed #2628: Detect redudant usage of operator++/-- in switch. 2012-08-22 14:40:57 +02:00
Edoardo Prezioso 2b5cd2effc Fixed G++ [-Wparentheses] warning. This also fixed #4073 (Crash on self assignment). 2012-08-21 20:15:04 +02:00
PKEuS b4b5c80db9 Improved check: Added message when checking sign of a pointer. 2012-08-21 03:28:02 -07:00
PKEuS b641a10e35 Fixed false negative: memset(foo, 0, sizeof(&foo)); is as suspicious as memset(foo, 0, sizeof(foo)); 2012-08-20 10:08:18 -07:00
PKEuS a243983242 Refactorized type handling in CheckIO and CheckOther:
- Added several types (std::) to isComplexType
- Types in namespace std:: are considered to have no side-effects (solved one TODO)
- Scope of a pointer can be limited without side effects
2012-08-20 08:57:28 -07:00
PKEuS c8773b891d Refactorization: Make use of Token::scope() replacing certain indentation counters 2012-08-12 03:13:07 -07:00
PKEuS 452f95cea0 More robust template detection in clarifyCondition check based on Token::link. (#3818)
Create links between < and > only on non-C code.
AStyle fix
2012-08-02 04:03:01 -07:00
Ettl Martin 98d608231d spelling fixes 2012-07-31 23:35:56 +02:00
PKEuS 4e2a86260f Really fixed #3941. 2012-07-29 06:50:05 -07:00
PKEuS 26a2379f9f Fixed false positive #3941. 2012-07-29 06:39:43 -07:00
PKEuS ae6201d289 Fixed false positive "Parameter 'x' is passed as a value" for types like std::vector<T>::size_type (#3986) 2012-07-23 01:41:20 -07:00
Zhao Qifa 188d2e143d add a performance checker for const assignment 2012-07-22 09:17:00 +02:00
PKEuS 41fecb2e6d Fixed evaluation of redundant conditions (#3972) 2012-07-13 06:01:19 -07:00
PKEuS e8f4dce25f Added check to CheckInternal: detect invalid patterns like "%typ%"
Replaced some Token::Match by Token::simpleMatch (suggestions of internal checks)
2012-07-11 08:45:16 -07:00
Robert Morin 25c1cc4c8e Improve check: warn when comparing boolean value with < <= > >=. Ticket: #2617 2012-07-03 06:39:13 +02:00
Daniel Marjamäki 162a430354 Fixed #3868 (false positive: (style) Same expression on both sides of '|'.) 2012-06-23 19:54:15 +02:00
Daniel Marjamäki a15dac9285 simple spell checking 'itis' => 'it is' 2012-06-23 10:08:18 +02:00
Daniel Marjamäki 3db58bb57f Reviewed C handling in CheckOther::clarifyCondition, never treat x<..> as a template in C files. 2012-06-23 07:29:49 +02:00
Daniel Marjamäki 8aba801360 Fixed #3800 (False negative: Self-assignement of variable declared as 'extern') 2012-06-22 11:23:50 +02:00
Zachary Blair fa2bca1e09 Ticket #3876: Improved check by only bailing of loops that contain break or continue 2012-06-16 13:11:09 -07:00
Daniel Marjamäki 89b1b4ea6e Fixed #3892 (False positive: 'if (var >= 0.0) then if (var >= 0.0) always returns true 2012-06-15 16:54:02 +02:00
Zachary Blair e2348560e4 Fixed Ticket #3876 (Error (double free) detected that can't possibly happen) 2012-06-10 17:50:31 -07:00
Daniel Marjamäki 905615e991 Fixed #3878 (Sign extension with unsigned char false positive) 2012-06-09 08:43:13 +02:00
PKEuS e191f0d7d4 Fixed test failures in testio caused by my last commit. 2012-06-08 10:35:08 -07:00
PKEuS c463d97386 Refactorization:
- Implemented consistent behaviour of Variable::typeStartToken/typeEndToken: Skip const and static on all variables.
- Simplified patterns containing "static|" or "const|" when matching typeStartToken.
2012-06-08 09:05:02 -07:00
Daniel Marjamäki 69846b2a06 Fixed #3872 ('char variables in bit operations' warning) 2012-06-08 17:24:54 +02:00
Zachary Blair 2bd171dded Fixed #3794 (New check: Missing break in switch (duplicate bitwise operation)) 2012-05-28 21:19:22 -07:00
PKEuS 9dc8123151 Refactorizations:
- Use const string references instead of const strings copies when possible
- Fixed cppcheck warning about postfix increment in CheckIO
- Use symbolDatabase to detect pointers in CheckOther::checkAssignBoolToPointer
2012-05-25 03:09:41 -07:00
PKEuS e2bab4b6a3 Implemented Function::nestedIn to be able to identify the scope the function belongs to, even if Function::functionScope.functionOf is not available.
Refactorized usage of SymbolDatabase in checkOther:
- Don't copy Function instances in checkExpressionRange
- Simplifications by more accurate usage of information in database
2012-05-24 08:40:43 -07:00
PKEuS 97c4af44ca Refactorizations in checkOther:
- More accurate usage of symbolDatabase to reduce code and false negatives
- Avoided unnecessary construction of pattern string
- Only search for class/struct definition before usage
2012-05-24 06:34:59 -07:00
PKEuS 334fc16f29 Refactorized CheckOther::checkSizeofForArrayParameter: Use symboldatabase to detect arrays. 2012-05-24 00:39:16 -07:00
Daniel Marjamäki 77e9106ec0 Fixed #3634 (False positive: compareBoolExpressionWithInt when using boost::tuples) 2012-05-22 19:01:21 +02:00
PKEuS b81eafe0dc Splitted CheckIO from CheckOther. 2012-05-20 02:57:07 -07:00
PKEuS be7b104a8e Added missing checks to CheckClass::classInfo()
Replaced tokAt(1) with next() in checkother.cpp
2012-05-19 01:51:47 -07:00
Andy Maloney 4686294d7e Fix compiler warning about empty for body 2012-05-18 14:00:10 -04:00
PKEuS a9cfe2814a Made some functions const according to cppcheck results 2012-05-17 02:54:17 -07:00
Daniel Marjamäki f803a18d50 Fixed #3749 (false positive: same expression on both sides of operator) 2012-05-17 07:26:57 +02:00
PKEuS 06a77679d4 Refactorizations:
- Added support for pointers in self assignement check
- Removed redundant for loop in checknullpointer.cpp
- Fixed warning about signed/unsigned mismatch in cppcheck.cpp by making Settings::_maxConfig unsigned
2012-05-11 10:38:19 -07:00
PKEuS ec00824fd3 Fixed #3357:
- Print "inconclusive" tag in cli
- Fixed inconclusive handling in checkbufferoverrun.cpp
- Merged reportInconclusiveError into reportError by adding an additional parameter "bool inconclusive" which is false per default
2012-05-06 10:37:41 -07:00
Ettl Martin bb8342fbb4 fixed misspelled word 'Comparision' --> 'Comparison' 2012-04-26 23:04:55 +02:00
PKEuS 92737578ac Refactorizations:
- removed unused function CheckOther::concatNames
- Replaced one indendation counter by Token::link() in checkother.cpp
- Forward declaration of Settings in threadexecutor.h
2012-04-26 15:29:39 +02:00
PKEuS 5ac7552e4e New check: Comparision of modulo results that are always true/false. 2012-04-26 15:23:47 +02:00
PKEuS dd5e9aa454 Make use of recently implemented Token::type() functionality 2012-04-25 09:56:07 +02:00
PKEuS 6a37c36ee8 Fixed #3741
Removed redundant nullpointer check (cppcheck catch)
2012-04-18 16:35:04 +02:00
PKEuS 8e5949c6ce Added several C++11 algorithms and containers to CheckStl
Added pattern "> %varid%" to CheckStl::stlBoundries()
Fixed message in checkOther (#1320)
2012-04-17 12:54:01 +02:00
PKEuS bac8ed7127 Refactorized stringification of tokens:
- Function that stringifies one token: Token::stringify()
- Functions that stringify a list of tokens: Token::stringifyList()
-- Single and powerful "base" function, used by several "light" functions
Refactorized
- testtokenize.cpp and testsimplifytokens.cpp: Use improved stringification functions instead of several local implementations
- Avoided redundand creation of std::string when using TestTokenizer::tokenizeAndStringify and in cmdlineparser.cpp
2012-04-16 19:51:07 +02:00
Daniel Marjamäki 66227c4da0 Fixed #3609 (clarifyCondition delivers false positives when using Windows-Traits as a template) 2012-04-08 18:07:11 +02:00
Daniel Marjamäki 6360afdcfa CheckOther: Use reportInconclusiveError to report inconclusive error 2012-04-08 10:47:01 +02:00
PKEuS b0f571b25c Fixed #3383: If there is an empty line between subsequent break statements, only issue a message for inconclusive checking 2012-04-05 10:38:29 +02:00
PKEuS c1fc7a2218 Improved CheckOther::checkComparisonOfBoolWithInt and CheckOther::checkComparisonOfBoolExpressionWithInt:
- Added support for comparision of bool constant with number constant (-> fixed #1877) and integer variable with boolean expression
- Moved a check from checkComparisonOfBoolWithInt to checkComparisonOfBoolExpressionWithInt
- Generalized some patterns
- Made error message more accurate concnerning the "neither 0 nor 1" part.
- Reduced number of Token::Match calls
2012-04-02 15:45:51 +02:00
PKEuS 033e4a2c1f Fixed #3676. 2012-04-02 11:21:04 +02:00
PKEuS 989ac449e4 Made invalidPointerCast message inconclusive for casting from floating point type* to char* (Fixed #3639) 2012-03-25 12:55:39 +02:00
Daniel Marjamäki 1d95416840 astyle formatting 2012-03-25 11:51:59 +02:00
Daniel Marjamäki ca6a93816b Merge pull request #89 from HeisSpiter/master
Merged two checks to get a better one regarding sizeof
2012-03-25 02:38:04 -07:00
PKEuS e4d92055e7 Improved sizeofCalculation check:
- Bailout on expanded macros for conclusive checking
- Support for more operators
- Removed indendation counter
Improved checkSignOfUnsignedVariable:
- Made the patterns more generic
- Improved verbose error message (-> Fixed #3080)
2012-03-25 11:32:00 +02:00
Pierre Schweitzer 2b5ddb7858 Merge the strncmp & malloc sizeof checks into a more generic test that handles several cases where sizeof is misused, or could be misused 2012-03-23 21:47:13 +01:00
PKEuS e938235385 Store functions which are declared but not implemented in the function list of the containing scope -> Fixed #3679
Refactorizations:
- Simplified some code
- Improved condition in findVariableType to reduce unnecessary comparisions of empty strings.
2012-03-23 17:59:51 +01:00
Pierre Schweitzer ec44967e13 Add a new test to check improper sizeof usage. It's for the moment limited to malloc calls. 2012-03-21 21:13:09 +01:00
PKEuS 4587a1a06c Fixed recently introduced assertion failure in debug mode 2012-03-15 21:06:24 +01:00
PKEuS b6057a1148 Improved CheckOther::checkIncorrectLogicOperator:
- Added a lot of additional pattern
- Rewrote error messages to make them more understandable and better fitting to the situation. (Fixed #3664)
- Cleanup in unit tests
Improved message of static string comparision check
2012-03-15 20:38:28 +01:00
PKEuS 7cfffc9c9d Improved CheckOther::checkIncorrectLogicOperator:
- Implemented automatic swapping of conditions and operands
- Added several patterns
- Added support for conditions outside of if/while
2012-03-12 19:06:30 +01:00
PKEuS 6f164de609 Improved static string comparision check: Implemented #3214
Fixed false negative on argument count of fnprintf/snprintf when first variable argument is a string. (#3655)
Uncommented call of virtualDestructorError in getErrorMessages in checkclass.h
Refactorizations:
- Rearranged code in checkother.h to make ordering more consistent and to increase encapsulation of private data
- Replaced some single-token-patterns
2012-03-11 11:01:39 +01:00
Daniel Marjamäki 3f1ab5af9b charvar: dont write warning about char type array index when array is small and the full valid range is accessible with the char type. If there are out of bounds access then, it is not because the type of the variable. 2012-03-10 12:19:28 +01:00
Simon Martin 190cba519d Fixed shadowing warning 2012-03-09 08:06:58 +01:00