Commit Graph

3997 Commits

Author SHA1 Message Date
anuraggarg011 913670d254 Fixed #3304 (simple cases) 2012-09-04 13:41:14 +02:00
kbajaj91 be716e81d3 Fixed #4138 - False positive about variable assigned a value that is never
used in loops
2012-09-04 13:06:04 +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
Edoardo Prezioso 6fd60eebb0 Tokenizer: added a workaround for #3690 (Support MSVC's 'for each'). 2012-09-03 20:23:53 +02:00
Edoardo Prezioso 6100776847 Tokenizer: remove unneeded initialization of strings explicitely with "". 2012-09-03 20:22:27 +02:00
anuraggarg011 bf11248a09 Fixed #1620 (tokenizer: simplify well known math functions) 2012-09-03 18:51:15 +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
Edoardo Prezioso 804fbe3f8f Tokenizer::simplifyEmptyNamespaces: remove useless condition.
Token::deleteThis handles the !tok->next situation well.
2012-09-03 14:22:31 +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
Kartik Bajaj ea0cbbcf78 Fixed #1481 2012-09-02 18:50:17 +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 8a474add19 Fixed compilation error - added missing function in symboldatabase. 2012-09-02 14:30:00 +02:00
deepak gupta 24659dee92 Fixed #4087 2012-09-02 14:26:39 +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
Deepak Gupta 4202866100 Fixed #4096 (Improve check: Buffer overrun in for loop, postfix increment in array access) 2012-09-01 19:17:28 +02:00
pranav1509 6f6baa67e4 Added more patterns to redundant condition check. 2012-09-01 13:39:32 +02:00
PKEuS c20adf91bf Moved simplification of wide character string literals (L"foo") to tokenize(). Token::isLong flag used to indicate that string is a wchar_t literal. 2012-09-01 13:12:47 +02:00
PKEuS dcf997007b Incremented version numbers to 1.57 dev 2012-09-01 13:04:09 +02:00
Daniel Marjamäki b8db27fcd1 1.56: Set versions 2012-09-01 10:54:15 +02:00
Daniel Marjamäki d7e521845b SymbolDatabase: Made function static after self-check suggestion 2012-09-01 10:46:09 +02:00
Daniel Marjamäki 769cd4503d Preprocessor: Made function static after self-check suggestion 2012-09-01 10:32:27 +02:00
Daniel Marjamäki 15bc552b37 Tokenizer: Fixed possible NULL pointer dereference 2012-09-01 10:11:18 +02:00
Daniel Marjamäki a8d419820b Tokenizer: removed unused variable 2012-09-01 09:57:48 +02:00
Ankita-gupta ff7373f46f Fixed bug in Token::Match (#3720) 2012-08-30 13:33:19 +02:00
Edoardo Prezioso 0d26a79f2c Tokenizer::simplifyEmptyNamespaces: new function.
It removes from the token list, if found, the following tokens: 'namespace %var% { }'. It won't involve C code.
2012-08-28 22:40:25 +02:00
PKEuS bbce79d7b3 Small refactorization: Handle std::map more efficient in setVarIdStructMembers() 2012-08-28 12:57:11 +02:00
PKEuS ea85dd305a Fixed #4086: Set varId in initialization list. 2012-08-28 12:44:40 +02:00
Daniel Marjamäki 9fe9944adb Fixed #4034 (false positive:(error) Dereferencing 'cfileP' after it is deallocated / released) 2012-08-28 06:38:38 +02:00
Daniel Marjamäki a7e67ac379 CheckObsoleteFunctions: asctime and ctime are not posix functions 2012-08-27 18:49:48 +02:00
Daniel Marjamäki 03f6a19dbd astyle formatting 2012-08-27 15:52:03 +02:00
Daniel Marjamäki 0d82b08080 Fixed #4040 (false positive: (error) Uninitialized variable: iter) 2012-08-27 15:48:21 +02:00
PKEuS 671f1b83d9 Fixed false positive: Return value of std::remove() ignored when std::remove(char*) is called (#4093) 2012-08-27 14:28:16 +02:00
Daniel Marjamäki 263e13e924 astyle formatting 2012-08-27 06:33:56 +02:00
PKEuS 4bab7f0ee2 Removed unused and obsolete functions Tokenizer::getParameterName() and Tokenizer::getNameForFunctionParams() 2012-08-26 16:53:40 +02:00
PKEuS 046712aaec Removed --doc formating hack that removes more than three newlines and added format testing of Check::classInfo instead.
- Fixed test failures shown by new test.
Use const_iterator instead of iterator in testcppcheck.cpp when possible
2012-08-26 16:22:46 +02:00
PKEuS 4b1075b34b Fixed #3729: Don't suggest recursive call to optimize away c_str() 2012-08-26 10:56:46 +02:00
PKEuS 839f7a32a4 It is ok to pass a nullpointer as first argument to mbstowcs and wcstombs, which then just return how long the buffer has to be to store the result. 2012-08-26 10:41:48 +02:00
PKEuS 6893948c72 Bugfix: Reset property info when Token::link() is set (< can be a bracket or a comparison operator). Fixes #4075. 2012-08-26 10:23:16 +02:00
PKEuS 8301b5d4d6 Bugfix for bugfix of Token::varId - Change Token::type also if varId is set to 0 2012-08-26 10:04:22 +02:00
PKEuS 662b0d2dbe Simplify 0[foo] to *(foo) (fixes #4083) 2012-08-26 10:03:05 +02:00
PKEuS 9fa7e15fb4 Fixed setVarId for nested templates (#3976, #3769) and support C++11 right angle brackets in TemplateSimplifier::templateParameters() 2012-08-26 09:49:38 +02:00
Reijo Tomperi 7ddd564ad6 Change file encoding to UFT-8 like it is for other files. 2012-08-26 00:12:38 +03:00
Daniel Marjamäki f127728582 Enable --std=c11 and --std=c++11 by default 2012-08-25 21:57:45 +02:00
Daniel Marjamäki 41797d409d Fixed #4036 (cppcheck hangs with 100% cpu load) 2012-08-25 13:24:17 +02:00
Daniel Marjamäki 7975ffba21 Fixed #3980 (Variable not assigned a value) 2012-08-25 13:07:33 +02:00
PKEuS bb068d2f78 Fixed false positive #4039: Handle operator precedence in CheckStl::size() 2012-08-25 12:36:13 +02:00
Daniel Marjamäki 985ac662ee Fixed #4035 (False positive: Memory leak: pTempFile) 2012-08-25 12:00:25 +02:00
Daniel Marjamäki 5051837c1a Reverted last commit. I pushed it by mistake. 2012-08-25 11:00:51 +02:00
Daniel Marjamäki 5e1ccfaf90 Fixed #4035 (False positive: Memory leak: pTempFile) 2012-08-25 10:55:20 +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
Daniel Marjamäki d24badbfda Fixed #4068 (Endless loop inside MathLib::add()) 2012-08-22 20:50:39 +02:00
Daniel Marjamäki f133c9e8ec Fixed #4020 (false positive: (style) Variable 'dst' is assigned a value that is never used) 2012-08-22 19:47:46 +02:00
PKEuS 4fb464982c Fixed crash reported in #4076 2012-08-22 10:17:23 -07:00
PKEuS f238f3fad5 Support sizeof in preprocessor directives
Applied "patch" provided by michaeln123 in #4071
2012-08-22 17:28:06 +02:00
PKEuS 43e01a2b1a Ran AStyle, removed redundant tokAt(0) 2012-08-22 16:51:44 +02:00
SAndeep 0600b0be8f sprintf changes 2012-08-22 16:46:14 +02: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
PKEuS e05a597066 Fixed false negatives in checkautovariables.cpp:
- Detect returning temporary instances (#4076)
- Added support for returning user defined types
2012-08-22 04:08:32 -07:00
PKEuS 00f6c635b8 Detect functions returning a template type in SymbolDatabase
Fixed comment
2012-08-22 03:37:50 -07:00
Edoardo Prezioso 2b5cd2effc Fixed G++ [-Wparentheses] warning. This also fixed #4073 (Crash on self assignment). 2012-08-21 20:15:04 +02:00
Daniel Marjamäki 41b624230f Fixed #3942 (false positive: (error) Memory leak: keyword) 2012-08-21 17:02:11 +02:00
PKEuS b4b5c80db9 Improved check: Added message when checking sign of a pointer. 2012-08-21 03:28:02 -07:00
PKEuS a5bca705a5 New check: Ensure that the return value of std::remove() is used. 2012-08-21 02:30:27 -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
Daniel Marjamäki 9ffc7f4c2d Fixed #3964 (False positive: Expressions in array declarations are not simplified 'char mac[17+1];') 2012-08-20 18:10:32 +02: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 4550cd2cd6 Refactorizations:
- Removed unnecessary 'if'
- Use symboldatabase instead of tokenizer to detect references and pointers
2012-08-20 08:27:43 -07:00
PKEuS c537a86363 Fixed false negative in unused variable checking when class without side effects inherits from another one. 2012-08-20 07:55:39 -07:00
PKEuS c7e2490f2b Refactorized iterator check:
- Handles reassignment (fix for #4062)
- Better support of execution paths
- Use symboldatabase for better performance
2012-08-20 04:57:24 -07:00
Daniel Marjamäki 7786e12ba2 Fixed #3922 (false positive: (error) null pointer dereference) 2012-08-18 22:11:48 +02:00
Daniel Marjamäki 6a5cc4727d Fixed #4019 (false positive: (style) Variable 'dest' is assigned a value that is never used) 2012-08-17 16:37:25 +02:00
Daniel Marjamäki 1601baa974 Fixed #4016 (false positive: incorrectLogicOperator) 2012-08-14 16:17:18 +02:00
Daniel Marjamäki e534ee0426 Fixed #3706 (cppcheck 1.53 hangs when processing a certain template with specializations) 2012-08-13 16:17:33 +02:00
Daniel Marjamäki 8afdde0b5e Fixed #3931 (FP: Buffer access out-of-bounds) 2012-08-12 17:06:54 +02:00
Edoardo Prezioso 358fb9a284 Fixed the GCC Wshadow warnings introduced recently. 2012-08-12 17:04:37 +02:00
Daniel Marjamäki 4368f66a00 Fixed #4018 (false positive: Dereferencing 'foo' after it is deallocated / released) 2012-08-12 16:18:07 +02:00
PKEuS 2ac2674f67 Fixed #4000, added support for function prototypes to TemplateSimplifier::templateParameters() 2012-08-12 05:19:56 -07:00
PKEuS a15e307df0 Replaced two more indentation counters 2012-08-12 04:12:17 -07:00
PKEuS c8773b891d Refactorization: Make use of Token::scope() replacing certain indentation counters 2012-08-12 03:13:07 -07:00
PKEuS 35d94c26d5 Changed creation of SymbolDatabase. Database always created after Tokenizer::tokenize() and Tokenizer::simplifyTokenList() instead of on-demand creation by Tokenizer::getSymbolDatabase.
-> With Token::scope() it is possible to access the symboldatabase without having to call getSymbolDatabase(). The change increases safety because it is guaranteed that the database is available in all checks, even if the specific check doesn't call getSymbolDatabase
- Tokenizer::_symbolDatabase does no longer have to be mutable -> Increased const correctness

The change above required two additional changes:
- A bug causing a debug message was fixed in the symboldatabase that became visible in the test suite by the change above.
- Simplify expressions like "struct struct Foo" which might be result of typedef instanciation.
2012-08-12 03:01:24 -07:00
PKEuS 4f68923add Fixed inverted id and msg of debug messages from symboldatabase 2012-08-12 02:11:54 -07:00
PKEuS 2ab33ef21b Added Pointer to enclosing scope to class Token (Only available when symboldatabase is created). 2012-08-11 11:47:11 -07:00
PKEuS 45bad7d1b2 Refactorized tokenizer:
- Don't run setVarId() twice, keep old varId's while/after simplifyTokenList
-> Modified two test cases in testmemleak.cpp. I consider this to be safe. Feel free to investigate this.
- Fixed two nullpointer issues shown by cppcheck

Ran Astyle on teststl.cpp
2012-08-10 09:31:22 -07:00
Edoardo Prezioso 1d8240356b Really fixed #4024. Now the simplification won't be done on non-executive scopes. 2012-08-10 17:43:09 +02:00
PKEuS 70de691551 Fixed false positive #4032 2012-08-10 06:26:07 -07:00
Daniel Marjamäki 0254344df5 Tokenizer::simplifyEnum: Reverted refactorings/optimisations as there were regressions (#3949, #3950, #4025) 2012-08-10 14:06:24 +02:00
Daniel Marjamäki ca4ed5e0c3 ErrorLogger: Throw InternalError if given severity is not handled 2012-08-10 12:43:53 +02:00
PKEuS 355c1322d6 Small refactorizations in checkunusedvar.cpp:
- Token::Match handles nullpointers
- In chained assignments variables are only written (not read) when assigned
- Fixed crash #4033
2012-08-10 03:36:08 -07:00
Daniel Marjamäki 6ff1760c72 TemplateSimplifier: Improved handling of unknown inner template instantiation inside template instantiation (#3818) 2012-08-09 17:19:36 +02:00
Daniel Marjamäki 4ec12209dc TemplateSimplifier: Fixed wrong match when inner template parameters are wrongly counted (#3818) 2012-08-08 06:43:41 +02:00