Commit Graph

3404 Commits

Author SHA1 Message Date
Edoardo Prezioso 697af4f7be Improve 'CheckMemoryLeakInClass::check'. 2012-01-28 23:24:00 +01:00
Edoardo Prezioso fa77f98b1c Tokenizer: it's possible to set null lower bound for eraseDeadCode when used inside simplifyFlowControl.
Remove now unused 'beginindent' and moved 'goto' simplification together with 'return' group.
2012-01-28 21:37:30 +01:00
Edoardo Prezioso bb703f4d0b Fixed: (warning) Found simple pattern inside Token::Match() call. 2012-01-28 20:31:12 +01:00
PKEuS 91a01a0a0d - checkUnsignedDivision checks for variable/variable (inconclusive). General bailout for if-statements.
- Make use of recently implemented symboldatabase functions (catch-support, reference-support)
- Other refactorizations
2012-01-28 12:32:28 +01:00
Daniel Marjamäki 46b8dc5e16 Fixed #3527 (Internal error. Token::Match called with varid 0. Please report this to Cppcheck developers) 2012-01-28 10:00:41 +01:00
Daniel Marjamäki 01f6bbda62 Null pointers: fixed false positive when '?' is used in return statement. Ticket: #3560 2012-01-28 08:06:03 +01:00
Robert Reif 42afd2d63a fix #3561 (SymbolDatabase: throw foo; creates a variable with type throw) 2012-01-27 19:24:01 -05:00
Edoardo Prezioso 8289e2428d Tokenizer: Stylish change to condition. 2012-01-27 17:12:28 +01:00
Edoardo Prezioso 0dd4b9ad3a Temporary workaround to ticket #3459 (Simplify goto before loop) :
don't simplify code which contains the label pointed by 'goto'.
2012-01-27 16:56:12 +01:00
Edoardo Prezioso 6314d04a04 Tokenizer: Add 'BOOST_FOREACH' pattern where it was missing. 2012-01-27 16:47:26 +01:00
Edoardo Prezioso ca8e8d26c7 Tokenizer: extract realloc simplification and simplify also when each argument is done by more than one token.
Restyling of a comment in tokenize.h.
2012-01-27 13:56:06 +01:00
Edoardo Prezioso 421ae9df03 simplifyCondition: handle also '( a || true || b)' -> '(true)' and '( a && false && b)' -> '(false)'.
Clarify a comment about previous commit.
2012-01-26 23:14:44 +01:00
Edoardo Prezioso 0f1f3c0f5f Tokenizer::removeRedundantCondition: refactoring due to various reasons.
1) Remove the dead code with 'eraseDeadCode', not with 'eraseTokens' because of the possible presence of labels.
2) It's impossible that in tokenizer there is pattern like 'if (true|false) {code;} else if (cond) {code_cond;}' because the function 'Tokenizer::elseif' adds '{' between 'else' and 'if', hence a code path is redundant, so it's removed from code.
2012-01-26 22:32:11 +01:00
Edoardo Prezioso b6763313c5 Tokenizer::simplifyQuestionMark: use links instead of indentation level number. 2012-01-26 17:55:22 +01:00
Edoardo Prezioso 6e164ae7ed Fixed ticket #3557 (Tokenizer: simplification of '[]' doesn't work well):
extract undefined size array simplification and handle multiple arrays and combos between pointers and arrays, don't handle the definitions as arguments of function.
2012-01-26 17:25:52 +01:00
PKEuS 6906001366 Added support for references to symboldatabase 2012-01-26 17:04:25 +01:00
PKEuS 5c2af0b2e3 - initialising std::string with 0 in initialisation list is partially detected in nullpointer check (#3520)
- executionpath checking makes use of symboldatabase
- CheckExceptionSafety::checkRethrowCopy makes use of symboldatabase
2012-01-26 16:50:59 +01:00
Edoardo Prezioso f428a29d8e Improve simplifyReturnStrncat when each argument is not composed by one token. 2012-01-26 16:09:32 +01:00
Edoardo Prezioso 20372eecfa Fixed gcc warning: variable which shadows a member of 'this'. 2012-01-26 15:20:20 +01:00
Edoardo Prezioso b6a0896ce6 Change 'simplifyReturn' to 'simplifyReturnStrncat' because it's not clear what this function does. 2012-01-26 11:49:08 +01:00
Robert Reif 4d56395504 symbol database: add simple try/catch tests 2012-01-25 22:48:18 -05:00
Robert Reif 6b0aff487f symbol database: add preliminary support for throw/catch block scopes. Just like the rest of cppcheck, ... is not handled properly for variables. Deep namespaces are also not handled properly yet. This is not an issue because this new capability is not used by any checks so it should be harmless. 2012-01-25 22:05:29 -05:00
PKEuS 42a75692d4 Improved nullpointer check:
- More accurate checking for dereferences and non-dereferences
- improved checking for nullpointer dereferences after return statement
- Supports pointer dereferences by std::string
- Code optimization/refactorization
2012-01-25 15:16:22 +01:00
Zachary Blair 589a2461bd Fixed ticket #3550 (false positive: (error) Memory pointed to by 'pxpm' is freed twice) 2012-01-24 22:43:44 -08:00
Robert Reif b6afa8a025 symbol database: add missing variable flag debug printing 2012-01-24 20:45:38 -05:00
Daniel Marjamäki 8e2c40b4b3 Fixed #3323 (#undef needs different handling) 2012-01-24 07:43:26 +01:00
Edoardo Prezioso 5953ed7318 Fixed ticket #3528 (Tokenizer: improve simplifyFunctionParameters to take count of square brackets) 2012-01-23 16:10:15 +01:00
Daniel Marjamäki 9f139cf414 Fixed #3509 (FP: Variable 'itemList' is not assigned a value, when << operator is used) 2012-01-23 08:02:59 +01:00
Daniel Marjamäki 9eb1a5864b Fixed #3502 (segmentation fault of cppcheck (struct{x y:};)) 2012-01-23 07:39:31 +01:00
Robert Reif e39b70c1be symbol database: add missing endl in debug dump 2012-01-22 22:32:53 -05:00
Daniel Marjamäki f81557da50 Fixed #3508 (Symbol database: mixing up constructors and destructors) 2012-01-22 19:48:36 +01:00
Edoardo Prezioso 6cac600d37 Token::replace: Little style change. 2012-01-22 00:03:33 +01:00
Edoardo Prezioso 3a2ba173ac Token::move|replace: update progressValues correctly. 2012-01-21 21:06:30 +01:00
Daniel Marjamäki b8faee9d30 Fixed #3497 (False positive: Uninitialized variable) 2012-01-21 20:42:41 +01:00
PKEuS 36479499e7 - Solved FIXME: Made detection of code that is no pointer-dereference more robust, uncommented code (checknullpointer.cpp)
- Removed more indendation level counters
- Make use of symbol database more often
- Other refactorizations
2012-01-21 19:55:32 +01:00
PKEuS 87e19d2552 Refactorized check for dead pointers after throw:
- Less bailouts for inconclusive checking
- Support for static variables
- Changed severity to warning (error is not certain)
2012-01-21 19:11:06 +01:00
Edoardo Prezioso b0dac2fa2e Tokenizer::copyTokens: add optional parameter which preserve the line number differences between tokens to be copied. 2012-01-21 17:18:16 +01:00
Ahti Legonkov 78461093f0 Fixed #3531 (When macro definition contains parenthesis, the #defined symbol does not get #defined.) 2012-01-21 12:51:54 +01:00
PKEuS 96ae010e48 - Correctly set Scope::function variable in symboldatabase
- Refactorizations
- Fixed some cppcheck warnings
2012-01-21 10:08:09 +01:00
Zachary Blair 0415444e28 Merge branch 'master' of github.com:danmar/cppcheck 2012-01-19 23:02:33 -08:00
Zachary Blair b89adff9fd Fixed Ticket #3300 (false negative: doublefree of pointer) 2012-01-19 22:59:54 -08:00
seb777 9be2d1cc62 It is a good practice to clear container after deleted all the items 2012-01-19 12:41:14 +01:00
Daniel Marjamäki 525e7fba20 Fixed #3490 (False positive: sscanf with %c) 2012-01-18 23:57:08 +01:00
Stefan Weil 7607e4c68d Fixed #3519 (Wrong line number in warning charBitOpError) 2012-01-18 13:09:46 +01:00
seb777 0be8af5214 Fix ticket #3530 (Add some windows data types to tokenizer) 2012-01-18 12:57:41 +01:00
Edoardo Prezioso 9019190a37 Tokenizer: various improvements to code. 2012-01-17 11:51:11 +01:00
Edoardo Prezioso 40739eb3fb Reverted some changes in commits 4b05c3e19f and 4b08b13845. 2012-01-16 11:44:31 +01:00
Edoardo Prezioso 4b05c3e19f Tokenizer::simplifyIfAddBraces: improve comments; handle independently 'a = { .. };'; reduce use of 'Token::(simple)Match' functions. 2012-01-15 19:53:11 +01:00
Edoardo Prezioso 4b08b13845 Tokenizer: reduce usage of Token::Match in some cases. 2012-01-15 15:00:52 +01:00
Edoardo Prezioso 963f6ce3ef Tokenizer: report syntaxError if there's nothing after 'if|for|while ()' and if there's nothing inside round brackets;
TestTokenizer: change test cases accordingly;
TestSimplifyTokens: ditto.
2012-01-15 14:50:01 +01:00
Daniel Marjamäki a6d96f5b72 Fixed #3496 (false positive: syntax error) 2012-01-15 14:33:53 +01:00
PKEuS 461565c50a Fixed #3517 and #3513 2012-01-15 12:32:02 +01:00
PKEuS c294b15360 Removed more indendation counters. 2012-01-15 12:31:49 +01:00
Daniel Marjamäki d891d1ce5d Fixed segfault in TestTokenizer::cpp0xtemplate3 2012-01-15 12:14:47 +01:00
Daniel Marjamäki 7e3735988d TemplateSimplifier : Fixed bug in recent commit. 2012-01-15 11:58:07 +01:00
Edoardo Prezioso 4399fca769 Code style: Use 'linkAt' instead of 'tokAt(..)->link'. 2012-01-14 15:21:45 +01:00
Reijo Tomperi dd18f595b1 Fix #3516 (inaccurate warning: "An unsigned variable will always be positive" (unsigned n; if (n >=0);))
http://sourceforge.net/apps/trac/cppcheck/ticket/3516
2012-01-14 12:50:09 +02:00
Edoardo Prezioso 6a248c35b5 Fixed ticket #3512 (segmentation fault of cppcheck ( 1 *p = const)) 2012-01-14 00:43:58 +01:00
Edoardo Prezioso 37f3aa1528 Fixed ticket #3486 (segmentation fault of cppcheck) 2012-01-13 23:53:53 +01:00
Daniel Marjamäki 0648b3ed5e Fixed #3504 (segmentation fault of cppcheck) 2012-01-13 07:57:12 +01:00
Daniel Marjamäki 47716ee4ca Fixed #3497 (False positive: Uninitialized variable) 2012-01-13 07:26:56 +01:00
seb777 8754caa36d Fix ticket #3483 (POSIX.1-2008 - obsolete functions)
From POSIX.1-2008 specification (see http://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap01.html#tag_22_01_01_04):
- remove obsolete functions ctime, asctime, rand, tmpnam (non reentrant functions check)
- add obsolete base functions (obsolete functions check):
 - rand_r
 - tmpnam, tmpnam_r
 - utime
 - asctime, asctime_r
 - ctime, ctime_r
- update unit tests (non reentrant function)
- update messages (cosmetic) (obsolete functions check)
2012-01-12 22:28:12 +01:00
Robert Reif 6f3807d915 add some more windows types 2012-01-10 21:55:24 -05:00
Reijo Tomperi be7691c7b4 Refactoring: Move rest of the template simplification into TemplateSimplifier
simplifyCalculations() was temporarily moved into TemplateSimplifier also, it should be moved to a better place.
2012-01-09 21:33:11 +02:00
Reijo Tomperi 756b8762ab Catch InternalError by reference instead of creating a copy of it. 2012-01-09 18:30:36 +02:00
Edoardo Prezioso 2dd53ec966 Fixed ticket #3485 (segmentation fault of cppcheck ( {a:1;}; )) 2012-01-09 16:24:11 +01:00
Edoardo Prezioso 54f54761b4 Fixed ticket #3482 (segmentation fault of cppcheck ( switch(){case} )) 2012-01-09 14:37:20 +01:00
Edoardo Prezioso 57fcde8090 Fixed ticket #3481 (segmentation fault of cppcheck) 2012-01-09 13:39:02 +01:00
Edoardo Prezioso a951d34aa8 Fixed ticket #3480 (segmentation fault of cppcheck) 2012-01-09 12:48:52 +01:00
Reijo Tomperi 194327048a Add InternalError and change MathLib to throw it in case of an error.
- Previously MathLib errors did not provide a filename, but after this change at least source file name should be printed
and if token is provided, also line number should be printed.
- Change also Token to use InternalError
- Modify Cppcheck-class to catch InternalError instead of Token
- Run dmake to update Makefile
2012-01-08 22:19:44 +02:00
PKEuS c273d6d31d Refactorized checkautovariables.cpp. Removed indendation counters.
Fixed #3478
2012-01-08 15:32:22 +01:00
Kamil Dudka e09b0330e4 Class: Don't warn about uninitialized union members because they are often combined with a second variable 2012-01-08 12:17:55 +01:00
Daniel Marjamäki 65ce55e675 Fixed #3472 (false positive: (error) Passing value 0 to log() leads to undefined result) 2012-01-08 12:07:25 +01:00
Daniel Marjamäki ee55d3294a Refactoring. Assume that .C files contain C code on case insensitive filesystems. 2012-01-08 10:34:31 +01:00
Daniel Marjamäki 304980848f Fixed #3473 (False positive: variable is assigned value that is never used (used in return statement)) 2012-01-08 08:44:18 +01:00
Daniel Marjamäki 70c83d9ca9 Fixed #3467 (False positive: Variable is not assigned a value (new)) 2012-01-08 08:31:00 +01:00
Reijo Tomperi 3c0ada52e6 Refactoring: Extract sizeof simplifying from template simplifying 2012-01-08 00:21:12 +02:00
Reijo Tomperi 93e3e7361e In unix .C is considered C++. Changed isC() and isCPP() to work like they were before refactoring. 2012-01-07 10:47:15 +02:00
Daniel Marjamäki 6a63104743 Fixed #3320 (False positive: Member variable is not initialized in the constructor (namespaces).) 2012-01-07 09:28:26 +01:00
Daniel Marjamäki a5264f6395 Symbol database: dump if --debug and --verbose is given 2012-01-07 08:21:34 +01:00
Reijo Tomperi 2a79399a53 astyle fix 2012-01-06 21:57:59 +02:00
Reijo Tomperi e91d239ea5 Refactor: Move file extension checks from Tokenizer to Path class. This has also functional change as now also file.JAVA is considered a Java file. 2012-01-06 21:56:28 +02:00
PKEuS 8378153669 Fixed missing include 2012-01-06 18:11:06 +01:00
Daniel Marjamäki de4a64332e Refactoring: Copy FileLister::acceptFile to Path::acceptFile. Use Path::getFilenameExtension and Path::acceptFile in Tokenizer. Use Path::acceptFile in CppCheck::processFile instead of hardcoded handling. 2012-01-06 17:31:10 +01:00
Daniel Marjamäki 9a102702cb Refactoring: Disable debug warnings when file extension is neither .c nor .cpp. To somewhat prevent that people fix java/c# specific debug warnings. 2012-01-06 16:08:08 +01:00
Edoardo Prezioso 05f16a25af Fixed ticket #2405 (debug messages provide incorrect file:line information) 2012-01-06 15:15:52 +01:00
Daniel Marjamäki bd8c21fc6b Refactoring: Made Preprocessor::simplifyCondition nonstatic 2012-01-06 08:42:07 +01:00
Daniel Marjamäki 66472b09c0 Refactoring: Made Preprocessor::match_cfg_def nonstatic 2012-01-06 08:15:48 +01:00
Daniel Marjamäki e4875178fa Refactoring: Removed redundant settings parameter for Preprocessor::removeComments 2012-01-06 08:09:53 +01:00
Daniel Marjamäki 94d220e370 Refactoring: Made Preprocessor::getcode nonstatic 2012-01-06 08:01:50 +01:00
Reijo Tomperi eda04ad906 Refactoring: Move template code into templatesimplifier: simplifyTemplatesExpandTemplate() 2012-01-05 22:45:19 +02:00
Daniel Marjamäki 07776e90ad Preprocessor: cleanup 2012-01-05 18:37:15 +01:00
Daniel Marjamäki c5f62c19d6 astyle formatting 2012-01-05 18:24:27 +01:00
Daniel Marjamäki 56a5e08f6b Use symbol database dump code written by Robert Reif. The symbol database is dumped if --debug is used. 2012-01-05 18:22:54 +01:00
Edoardo Prezioso a7029291fd Tokenizer::simplifyGoto: process also derived class/structs. 2012-01-04 17:08:53 +01:00
Edoardo Prezioso b0e4dc3ab8 Refactoring: replace forgotten code with function call 'simplifyRedundantConsecutiveBraces'. 2012-01-04 16:47:36 +01:00
Edoardo Prezioso 6f9cd110d0 Improve Tokenizer: improve 'simplifyDoublePlusAndDoubleMinus' when there are negative numbers. 2012-01-04 13:45:27 +01:00
Edoardo Prezioso 75fbe310ff Extract various functions inside the Tokenizer class and fix tokenization of 'return __LINE__ ;'. 2012-01-04 12:57:58 +01:00
PKEuS eabdc9082e Fixed false positives related to %*[] in scanf format string (#3468) 2012-01-04 11:22:42 +01:00
Reijo Tomperi 0369681a2c Refactoring: Move template code into templatesimplifier: simplifyTemplatesGetTemplateNamePosition() 2012-01-03 23:49:50 +02:00