Commit Graph

298 Commits

Author SHA1 Message Date
PKEuS 95afa51b24 Fixed crash #5991: Don't crash when lambda is incomplete
Fixed crash #6004: Support struct initializations in AST
2014-07-31 23:15:36 +02:00
PKEuS 8c96cc59c9 Fixed false positive #5976: Properly handle shift from stream. 2014-07-17 10:03:58 +02:00
PKEuS 3d0ebe196b Several improvements to CheckUnusedVar::checkFunctionVariableUsage_iterateScopes():
- Use AST in some places
- Fixed misusage of Token::isStandardType (fixes false negative)
- Removed some redundant conditions
2014-07-02 00:18:40 +02:00
Thomas Jarosch 93341f4449 Use simple match where possible
Fixes these warnings found by "--enable=internal":

[lib/checkclass.cpp:972]: (warning) Found simple pattern inside Token::Match() call: "* *"
[lib/checkbufferoverrun.cpp:635]: (warning) Found simple pattern inside Token::Match() call: "."
[lib/checkbufferoverrun.cpp:1397]: (warning) Found simple pattern inside Token::Match() call: ";"
[lib/checksizeof.cpp:299]: (warning) Found simple pattern inside Token::Match() call: "."
[lib/checksizeof.cpp:301]: (warning) Found simple pattern inside Token::Match() call: ")"
[lib/checksizeof.cpp:303]: (warning) Found simple pattern inside Token::Match() call: "]"
[lib/checksizeof.cpp:318]: (warning) Found simple pattern inside Token::Match() call: ")"
[lib/checknullpointer.cpp:413]: (warning) Found simple pattern inside Token::Match() call: "delete"
[lib/checkio.cpp:1336]: (warning) Found simple pattern inside Token::Match() call: "> ("
[lib/checkstl.cpp:1509]: (warning) Found simple pattern inside Token::findmatch() call: ";"
[lib/checkstl.cpp:1512]: (warning) Found simple pattern inside Token::findmatch() call: ";"
[lib/checkstl.cpp:1594]: (warning) Found simple pattern inside Token::Match() call: "="
[lib/checkstl.cpp:1598]: (warning) Found simple pattern inside Token::Match() call: "] ="
[lib/checkunusedvar.cpp:755]: (warning) Found simple pattern inside Token::Match() call: "goto"
[lib/checkunusedvar.cpp:793]: (warning) Found simple pattern inside Token::Match() call: "="
[lib/checkuninitvar.cpp:376]: (warning) Found simple pattern inside Token::Match() call: "> ("
[lib/checkother.cpp:86]: (warning) Found simple pattern inside Token::Match() call: "> ("
[lib/checkother.cpp:2181]: (warning) Found simple pattern inside Token::Match() call: "> {"
[lib/valueflow.cpp:54]: (warning) Found simple pattern inside Token::Match() call: "&"
[lib/valueflow.cpp:409]: (warning) Found simple pattern inside Token::Match() call: "do"
[lib/valueflow.cpp:425]: (warning) Found simple pattern inside Token::Match() call: ") {"
[lib/valueflow.cpp:487]: (warning) Found simple pattern inside Token::Match() call: ") {"
[lib/valueflow.cpp:511]: (warning) Found simple pattern inside Token::Match() call: "} else {"
[lib/valueflow.cpp:615]: (warning) Found simple pattern inside Token::Match() call: "for ("
[lib/symboldatabase.cpp:80]: (warning) Found simple pattern inside Token::Match() call: "= {"
[lib/symboldatabase.cpp:1069]: (warning) Found simple pattern inside Token::Match() call: "std ::"
[lib/tokenize.cpp:2207]: (warning) Found simple pattern inside Token::Match() call: "< >"
[lib/tokenize.cpp:2730]: (warning) Found simple pattern inside Token::Match() call: ";"
[lib/tokenize.cpp:4234]: (warning) Found simple pattern inside Token::Match() call: "try {"
[lib/tokenize.cpp:4235]: (warning) Found simple pattern inside Token::Match() call: "} catch ("
[lib/tokenize.cpp:5500]: (warning) Found simple pattern inside Token::Match() call: "INT8"
[lib/tokenize.cpp:5752]: (warning) Found simple pattern inside Token::Match() call: "}"
[lib/tokenize.cpp:5752]: (warning) Found simple pattern inside Token::Match() call: "do"
2014-03-14 16:27:47 +01:00
Lauri Nurmi 70a67eaf85 Change some more 0 literals into nullptr. 2014-02-16 13:38:50 +02:00
Daniel Marjamäki fb5c2d4b48 use nullptr in lib/checkother.cpp 2014-02-15 08:46:28 +01:00
Daniel Marjamäki fd3a8a2a18 Update copyright 2014-02-15 07:45:39 +01:00
Heinrich Schuchardt 6bfd4af5f7 5355: False postive var not assigned
Avoid false positive "variable not assigned" for

struct Fred{
};
void foo () {
  Fred fred;
  throw fred;
}

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2014-02-01 22:40:35 +01:00
Lucas Manuel Rodriguez ad0269eeeb Refactor checks using Variable::isStlType() 2014-01-30 01:26:48 -03:00
Heinrich Schuchardt de20ba6763 [PATCH] Types in isRecordTypeWithoutSideEffects
The type definition of the iterator should match the type definition of the map <const Type *, bool>.
2014-01-24 06:10:19 +01:00
Daniel Marjamäki 853d9dd7a9 Fixed #4956 (false positive: Variable 'myIsFirst' is assigned a value that is never used.) 2013-10-26 15:22:28 +02:00
Daniel Marjamäki 3b8e9f5a2a Fixed #4899 (False positive on unused variable) 2013-09-03 17:02:46 +02:00
Daniel Marjamäki 4a1d1ce1a1 Fixed #3471 (Unused functions: take __attribute__((constructor)) in to consideration) 2013-08-30 06:27:46 +02:00
Daniel Marjamäki 65d99feddf fix 2013-08-27 15:46:51 +02:00
PKEuS a9a5dc0354 Updated to AStyle 2.03, require this version 2013-08-07 16:27:37 +02:00
Daniel Marjamäki 9c67af058a SymbolDatabase: Renamed Variable::varId() to Variable::declarationId() to make it more clear how it works. 2013-07-20 12:31:04 +02:00
Frank Zingsheim 395a474ec2 Fixed #4695: Infinite recursion inside isRecordTypeWithoutSideEffects() 2013-04-01 12:41:14 +02:00
Alexander Mai 7902cd0123 Fixed #4447 (false positive: (style) Variable 'X' is assigned a value that is never used (goto)) 2013-03-28 06:44:37 +01:00
Daniel Marjamäki dd155b57e4 Fixed #4487 (False positive: variable is not assigned a value (pointer alias)) 2013-03-20 06:38:53 +01:00
PKEuS 292e52364c Refactorizations:
- Removed empty implementation of CheckUninitVar::runChecks()
- Avoided unnecessary string copying
2013-03-12 08:11:18 -07:00
PKEuS 7bc729bc63 - Moved more functionality from Scope to Type: BaseInfo and FriendInfo
- Replaced Scope->findQualifiedScope by SymbolDatabase::findScope
- Improved SymbolDatabase::findType
2013-03-05 06:28:40 -08:00
PKEuS 66a3555897 Implement initial support for Types in Symboldatabase:
- For each class/struct/union, a Type instance is added to SymbolDatabase::typeList.
- A scope is no longer created for declared but not defined types

Fixed name detection for classes when they are declared like this: "class ::Foo::Sub {..."
2013-03-05 04:33:38 -08:00
Daniel Marjamäki 78a3a58a5a Fixed #4628 (False positive: Variable is assigned a value that is never used) 2013-03-04 19:13:49 +01:00
PKEuS 0105f8223c Simplified several Token::Match/simpleMatch calls when match string consists of a single pattern
Fixed two CheckInternal error messages
2013-03-01 03:42:04 -08:00
Daniel Marjamäki ecafe7a129 Fixed #4624 (Wrong error for instances of std::unique_lock (variable is never used)) 2013-02-28 17:02:58 +01:00
Daniel Marjamäki bce99a9e2f Fixed #4394 (FP: Variable 'a' is not assigned a value) 2013-02-20 17:43:16 +01:00
Robert Reif 42588e9729 Fixed #4535 (Simplify checks by caching symbol database Variable pointer in Token) 2013-02-06 06:39:58 +01:00
Erik Lax b538c50856 Fixed #4484 (1.58: new crash for linux kernel code) 2013-01-13 07:57:46 +01:00
Frank Zingsheim 498d03458f Fixed #4385: lock_guard RAII throws unreadVariable 2013-01-07 20:28:43 +01:00
Daniel Marjamäki eebfea2b23 Fixed #4381 (Inline type declaration on statics causes warning) 2013-01-07 19:20:15 +01:00
Reijo Tomperi 5d5f7085bf Updating year 2012 -> 2013 to .cpp and .h files and man page. 2013-01-01 18:29:08 +02:00
Daniel Marjamäki dde4cc39e5 astyle formatting 2012-12-29 17:13:54 +01:00
Daniel Marjamäki e7aa1ec396 Fixed #4411 (Variable is assigned a value that is never used.) 2012-12-29 12:45:37 +01:00
Daniel Marjamäki 1769240e15 Fixed #4022 (false positive: (style) Variable 'sort_entry' is assigned a value that is never used) 2012-12-28 18:18:36 +01:00
acm4me 7da155c8ba Support for Sun Studio C++ compiler 2012-12-27 11:51:12 +01:00
PKEuS d82048f5f5 Fixed compiler error in VS10 2012-12-20 04:03:36 -08:00
Daniel Marjamäki 3913fd8398 Fixed #4320 (False positives 'unassignedVariable' and 'uninitvar') 2012-12-18 19:02:30 +01:00
Daniel Marjamäki 1e2fb4f1a4 Unused var: Limit bailout for foreach loops. Only bailout if name contains 'foreach' or 'for_each'. Only bailout variables that are used more than once in the body. Ticket: #4155 2012-12-17 18:19:05 +01:00
Daniel Marjamäki 72ea94bf75 Fixed #4155 (false positive: Variable is assigned a value that is never used (inside BOOST_FOREACH loop)) 2012-12-17 17:07:56 +01:00
Edoardo Prezioso 0273c183a7 Run astyle and update the translation files.
I believe we need a hook script because else everytime we change a file we have to make a new commit to fix the discrepancies problems.
2012-12-07 01:49:51 +01:00
Frank Zingsheim b99d3f0767 Style change: Fixed #4369 (false positive: Variable 'i' is assigned a value that is never used)
based on aebdb3769f
due to comment in aebdb3769f
2012-12-05 20:18:14 +01:00
Frank Zingsheim aebdb3769f Fixed #4369 (false positive: Variable 'i' is assigned a value that is never used) 2012-12-04 21:39:51 +01:00
Daniel Marjamäki dba51c906e cleanup: removed redundant insideLoop assignment in checkunusedvar. Thank you zingsheim for the suggestion 2012-12-02 07:28:05 +01:00
Frank Zingsheim f23ce8d254 Fixed #4180 (false positive: (style) Variable is assigned a value that is never used (inside loop)) 2012-11-28 06:11:33 +01:00
Daniel Marjamäki 382e1e95ef Fixed #4168 (False positive: (style) struct or union member 'super::x' is never used) 2012-11-18 15:24:47 +01:00
Robert Reif 6b8e83a181 speed up checks by caching commonly looked up stuff in the symbol database (checkother, checkstl, checkunusedvar). Ticket: #4266 2012-11-16 06:50:49 +01:00
Daniel Marjamäki a2febc49d6 Fixed #4318 (False positive: 'unreadVariable') 2012-11-15 08:36:43 +01:00
PKEuS 24b98feadb Message refactorization: checkuninitvar.cpp, checkunusedfunctions.cpp, checkunusedvar.cpp 2012-11-01 18:40:20 +01:00
Daniel Marjamäki a64669b1ec Fixed #4203 (Don't warn about setting NULL value for pointers and not using that value) 2012-09-30 17:22:35 +02:00
PKEuS 1863306198 Fixed false negative in checkunusedvar.cpp and reduced code dupliaction. 2012-09-11 14:24:12 +02:00
PKEuS 623ffe23f0 Fixed #4145 2012-09-11 14:14:35 +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
PKEuS 536492d5f0 Applied two suggestions of XhmikosR:
- Added UTF8 signature to VS10 solution
- Prefer prefix operator++ (cppcheck catch)
2012-09-05 15:34:37 +02:00
PKEuS 8924e8af43 Fixed #4143: Give correct line numbers in checkunusedvar.cpp 2012-09-04 14:53:24 +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
Kartik Bajaj ea0cbbcf78 Fixed #1481 2012-09-02 18:50:17 +02:00
Daniel Marjamäki 7975ffba21 Fixed #3980 (Variable not assigned a value) 2012-08-25 13:07:33 +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 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 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
PKEuS c11e8cdbfa Fixed false positive "Variable is not assigned a value" on class types 2012-07-25 00:34:27 -07:00
PKEuS bb940e4722 Implemented unused variable checking for standard types (#2851) 2012-07-24 11:47:29 -07:00
Daniel Marjamäki cb7757f650 CheckUnusedVar: dont report false positives for extern variables 2012-06-28 17:22:56 +02:00
Daniel Marjamäki 25b24d149f Fixed #3910 (False positive: Variable is not assigned a value (pointerArray alias)) 2012-06-24 16:54:37 +02:00
Daniel Marjamäki 951da02f89 Reviewed handling of unknown types in C files in checkunusedvar 2012-06-22 15:59:41 +02:00
Edoardo Prezioso eacf74be8d Changed the order of some structures in order to improve, even if for a bit, their padding. 2012-05-14 20:49:03 +02:00
Daniel Marjamäki 082e6d506b #3744 (Unexpected unused value warning for char ptr types set in switch) 2012-04-28 15:43:42 +02:00
PKEuS dd5e9aa454 Make use of recently implemented Token::type() functionality 2012-04-25 09:56:07 +02:00
PKEuS 782cd5d228 Fixed #3687: Don't treat catched variables as local ones. 2012-03-26 21:19:42 +02:00
Daniel Marjamäki d6c8de104c Revert "Fixed #3648 (Internal error: Token::Match called with varid 0)"
This reverts commit 1fa1ddccba.
2012-03-20 19:00:16 +01:00
Daniel Marjamäki 1fa1ddccba Fixed #3648 (Internal error: Token::Match called with varid 0) 2012-03-20 18:58:27 +01:00
PKEuS 7055526f4a Fixed #3672: bitwise and operator in if/while does no longer confuse setVarId code
Improvements to CheckUnusedVar:
- Improved handling of arrays of struct/class instances
- Differ between addressof and bitwise-and operator
- Made some members private to improve encapsulation
- Replaced some simple patterns by direct function calls
- Removed an unnecessary condition
2012-03-19 17:41:16 +01:00
PKEuS c61762f454 Refactorized doAssignement:
- Enhanced performance by directly iterating through the token list instead of index access
- Added more allocation functions
- Simplified code
Replaced avoidable strlen call in cppcheckexecutor.cpp
2012-02-29 20:57:48 +01:00
Daniel Marjamäki 385c9d341d Fixed #3633 (False positive: struct array not assigned a value) 2012-02-26 08:29:02 +01:00
Daniel Marjamäki bbfae8e3ae Fixed #3583 (False positive Variable X is assigned a value that is never used) 2012-02-25 12:56:33 +01:00
Daniel Marjamäki 69d03bac34 Fixed #3603 (False Positive: Variable is assigned a value that is never used) 2012-02-19 15:25:46 +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 9f139cf414 Fixed #3509 (FP: Variable 'itemList' is not assigned a value, when << operator is used) 2012-01-23 08:02:59 +01:00
PKEuS 96ae010e48 - Correctly set Scope::function variable in symboldatabase
- Refactorizations
- Fixed some cppcheck warnings
2012-01-21 10:08:09 +01:00
Edoardo Prezioso 57fcde8090 Fixed ticket #3481 (segmentation fault of cppcheck) 2012-01-09 13:39:02 +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 8cae17fda8 Update year to 2012 2012-01-01 01:05:37 +02:00
Daniel Marjamäki 2ae48c7aef Fixed #3454 (false positive: (style) Variable 'iFaktor' is assigned a value that is never used) 2011-12-30 09:47:15 +01:00
Daniel Marjamäki fd4bc12ed3 Fixed #3438 (false positive: (style) Variable 'dBuf' is not assigned a value) 2011-12-26 08:12:23 +01:00
PKEuS 6dc2a6e7ab Refactorized CheckUnusedVar 2011-12-18 20:15:41 +01:00
PKEuS c9f5117cf5 Fixed #3407 (False positive: (inconclusive) Found duplicate branches for if and else. (inline assembler)) 2011-12-13 21:42:38 +01:00
PKEuS 167a7e3e51 Various code cleanups 2011-12-08 21:28:34 +01:00
Edoardo Prezioso 42e369a4b4 Change every 'tokAt(..)->link()' to 'linkAt(..)'. 2011-11-20 14:24:27 +01:00
Edoardo Prezioso 2c64d299ca Change every 'tokAt(...)->str()' to 'strAt(...)'. 2011-11-13 13:10:59 +01:00
Edoardo Prezioso b28a44dc3b Change: 'next()->next()'->'tokAt(2)', 'previous()->previous()'->'tokAt(-2)'. 2011-11-12 22:33:03 +01:00
Thomas Jarosch dee03a09e4 Fix logic glitch
Reported by Pc-Lint 9.x :o)

The code was working before as the AND operation
also matched in that specific case.

I verified that code is in use by commenting
it out and checked how many tests failed.
2011-10-28 23:36:30 +02:00
Thomas Jarosch 54adb910ec Use Token::simpleMatch instead of Token::Match for simple patterns 2011-10-27 15:59:22 +02:00
Daniel Marjamäki 6f8e42a5af changed the astyle formatting flags 2011-10-13 20:53:06 +02:00
Daniel Marjamäki d93354a974 unused var: use 'else if' instead of 'if' 2011-09-11 08:18:32 +02:00
Daniel Marjamäki 8240422a09 Fixed #3078 (vector::at using int causes false positive) 2011-09-04 20:48:05 +02:00
Robert Reif 477d1e92c9 add new (nothrow) support to CheckUnusedVar::checkFunctionVariableUsage 2011-08-31 06:39:39 -04:00
Robert Reif 2dd93dff75 move unused variable checks from checkother to checkunusedvar 2011-08-19 14:35:25 -04:00