Commit Graph

274 Commits

Author SHA1 Message Date
Steve Duan cf0c666d79 Fixed #5041 (Improve check: support 'auto' for 'Iterator used after element has been erased') 2013-09-28 11:50:45 +02:00
PKEuS a9a5dc0354 Updated to AStyle 2.03, require this version 2013-08-07 16:27:37 +02:00
Daniel Marjamäki 287782a679 Fixed #4390 (False alarm 'Object pointed by an auto_ptr is destroyed using operator delete. You should not use auto_ptr for pointers obtained with operator new[].') 2013-05-01 11:11:57 +02:00
PKEuS 6f9886a1b9 Removed more duplicate unit tests 2013-04-13 02:07:18 -07:00
zblair ecfe4eb5be Fixed #3372 (New check: dereference iterator and then checking it) 2013-04-04 21:14:59 -07:00
Alexander Mai b9c27699b3 Fixed #4684 (cppcheck crash in template function call.) 2013-03-29 19:29:23 +01:00
Ettl Martin 1b9c1c03fa unittests: removed not needed '\n' at the end of testcases. 2013-03-20 15:36:16 +01:00
PKEuS 641ac5c02a Fixed #4352: Ensure that class provides an iterator interface. 2013-03-14 09:00:22 -07:00
PKEuS 0f03995995 Added support for different containers, while-loops and if to CheckStl::stlOutOfBounds() 2013-03-04 10:59:46 -08:00
PKEuS 34b1d75a10 Fixed handling of std::vector::insert() in CheckStl::pushback() 2013-03-04 02:57:09 -08:00
PKEuS d78c06dc3f Replaced _settings->isEnabled("style") by _settings->isEnabled("warning") wherever warnings are issued 2013-03-03 02:41:59 -08:00
PKEuS 0d316af4f2 Fixed false positive stlSize for code like "foo + 1 > bar.size()" (#4584) 2013-02-16 02:50:25 -08:00
Daniel Marjamki 452dc23742 Fixed #4480 (False positive : Inefficient usage of string::find) 2013-02-14 19:14:20 +01:00
Daniel Marjamäki 08ada4cc63 Fixed #2652 (container .size() check too strict) 2013-02-14 16:59:58 +01:00
Andrew C. Martin bd0d9b9639 fix misspellings & gcc v3.4.6 warnings
1.  fix typos / misspellings
 - Fix misspelling within comments, variable/function names, stdout messages
 - changes the name of an error code: ```stlBoundries``` changed to ```stlBoundaries```.  Alias old name (```stlBoundries```) to the new one.

2.  fix gcc v3.4.6 32bit & 64bit warnings

 - fixes gcc v3.4.6 warnings, except for those in tinyxml and "-Wmissing-declarations" makefile warnings
 - in Preprocessor::handleIncludes(), replace a ```vector <bool>``` with ```stack<bool>``` (see ```vector<bool>``` warning below).
   - this is the only ```vector<bool>``` in the codebase
 - ```vector <bool>``` is actually a case of template specialization, and is not recommended, according to the following links:

http://stackoverflow.com/q/6461487
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2160.html
http://stackoverflow.com/q/670308

 - in the codebase before and after this change, testrunner SEGVs in a number of places on gcc v3.4.6, including ```Check::~Check()```, among others
   - fc42fc95 fixes this particular runtime issue for DJGPP & __sun
2013-02-09 23:43:09 -07: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 db123c2c9b Fixed #4431 (FP: Erroneous 'Ineffective call of function empty()' in ?: test) 2012-12-25 12:50:38 +01:00
Robert Reif bb2a15c140 Symbol database: Better handling of 'using namespace N;'. Ticket: #4412 2012-12-20 06:53:04 +01:00
PKEuS 4737966caf Unit test cleanup: Removed some empty lines and whitespaces before \n. 2012-12-06 10:19:22 -08:00
Daniel Marjamäki ba3833c692 Fixed #3678 (stlcstrReturn for classes which don't provide a std::string) 2012-11-29 07:10:56 +01:00
Daniel Marjamäki 40719c56db Fixed #4183 (false positive with method named c_str()) 2012-11-28 08:48:48 +01:00
Robert Reif ffe657128f Fixed #4364 (Segfault in CheckStl::stlBoundries) 2012-11-20 06:12:14 +01:00
PKEuS 704f285c90 Refactorized CheckStl::pushback():
- insert(), reserve() and clear() also invalidate iterators
- Properly support return and throw statements: Bailout after semicolon
- "." is also bad usage of invalid iterator.
2012-11-11 13:03:58 +01:00
Jose Roquette e8d3a4300d Fixed #4197 - False negative: invalidIterator2 not detected 2012-11-11 12:01:52 +01:00
Andrew Martin 7c370ec873 Fixed #4305 (improve check: 'vector.size() < 1' should result in 'inefficient checking for '...' emptiness.') 2012-11-04 16:15:26 +01:00
PKEuS 2aae8381cc Message refactorization: checkstl.cpp 2012-10-14 11:16:48 +02:00
Daniel Marjamäki 0115bb8d24 Fixed #4102 (False positive: 'find('=') + 1U' can't be replaced with compare) 2012-10-07 12:43:14 +02:00
PKEuS 1e5d082251 Moved remaining part of c_str() checking to checkstl.cpp. Fixed false positive #4157. 2012-09-10 15:20:38 +02:00
PKEuS e87ebcc602 Added support for std::unique and std::remove_if to CheckStl::uselessCalls(). 2012-09-07 14:23:32 +02:00
PKEuS a8cdd15738 Fixed false positive #4077. 2012-09-06 16:30:10 +02:00
PKEuS 6edec7bdce Fixed false positive #4123. 2012-09-06 16:10:51 +02:00
Daniel Marjamäki 3032ded9aa replaced tabs with spaces 2012-09-05 19:46:44 +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
PKEuS 4b1075b34b Fixed #3729: Don't suggest recursive call to optimize away c_str() 2012-08-26 10:56:46 +02:00
PKEuS bb068d2f78 Fixed false positive #4039: Handle operator precedence in CheckStl::size() 2012-08-25 12:36:13 +02:00
PKEuS a5bca705a5 New check: Ensure that the return value of std::remove() is used. 2012-08-21 02:30:27 -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
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
PKEuS 70de691551 Fixed false positive #4032 2012-08-10 06:26:07 -07:00
PKEuS 7d33181fba Refactorizations in testrunner:
- Avoid creation of std::string instances of static strings where possible in testrunner.
- Removed unnecessary include of tinyxml.h in testcppcheck.cpp
2012-07-16 04:17:14 -07:00
PKEuS 4ed15d87b6 Properly fixed test failure and line numbers in uselessCallsEmpty error 2012-07-13 05:15:58 -07:00
Daniel Marjamäki aa4fe3a1e2 fixed unit test 2012-07-13 08:38:27 +02:00
PKEuS 5a91d6a0f5 Check for useless calls of .empty() (#3816)
Messages from CheckStl::uselessCalls() only shown when correct severity is enabled.
2012-07-12 03:23:52 -07:00
PKEuS 43c060b630 Removed preprocessor directives from tests that aren't preprocessed before being tokenized. 2012-07-07 11:21:08 -07:00
Daniel Marjamäki 2b3e5abef8 Fixed #3865 (Suspicious condition. The result of find is an iterator, but it is not properly checked.) 2012-06-07 19:33:18 +02:00
Daniel Marjamäki 2fbd77c5a1 Fixed #3715 (false positive checking a map bounds) 2012-05-07 12:03:33 -07:00
PKEuS 1793bf8928 Fixed false positive in stlBoundries check (#3740) 2012-04-18 10:08:59 +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 82cd022646 Refactorized CheckStl::mismatchingContainersError:
- Improved error message
- Made patterns more generic by using Token::nextArgument()
2012-04-17 12:21:41 +02:00
Daniel Marjamäki c6ba3ba3ca Fixed #3714 (segmentation fault of cppcheck checking libtiff) 2012-04-14 18:36:19 +02:00
Daniel Marjamäki b8d233f1a2 false poitive - invalid iterator after break 2012-04-09 07:19:39 +02:00
PKEuS d6cfbc6483 Improved checks in CheckStl:
- Generalized check for inefficient emptiness check to detect !%var%.size() calls also outside of if and while; detect it also for %var%.size() when linked with && or ||.
Refactorizations in CheckStl:
- Removed an indendation counter and an offset variable
- Reduced distance given to tokAt calls in CheckStl::redundantCondition
- Rearranged code in CheckStl::missingComparison to use more efficient comparision of varIds instead of variable names. Use varId in pattern instead of variable name.
2012-04-04 19:44:57 +02:00
PKEuS bef2caf489 Improved checks in CheckStl:
- Improved message of stlIfStrFind according to discussion on github (77d9ed1877)
- Generalized pattern for substr in CheckStl::uselessCalls; added check for substr calls like ".substr(%any%,0)" which result in an empty string.
2012-04-04 19:40:28 +02:00
PKEuS 77d9ed1877 Fixed #3162: Check whole condition for suspicious find calls. 2012-04-03 20:59:45 +02:00
PKEuS 8492685531 Fixed #3697. 2012-04-02 11:02:41 +02:00
PKEuS 1ef99e2f21 Improved checkautovariables:
- Added support for checking a few more code patterns
- Simplified code by using more information from the symboldatabase
- Moved redundant part of c_str-check to checkstl
Two fixes according to output of pvs studio in testsimplifytokens.cpp
2012-03-01 18:38:20 +01:00
PKEuS 9431fb1b7e Improved STL checks:
- Added performance checking for .c_str() for return values and function parameters (#1079)
- Added more containers (basic_string, C++11 containers) and more functions to checking (.at, .resize, .reserve, ...)
- Make use of symboldatabase in missingComparision check
2012-02-25 12:43:27 +01:00
Edoardo Prezioso c76f06c01b Fixed ticket #3447 (Improve void CheckStl::if_find()) 2012-01-02 23:12:59 +01:00
Reijo Tomperi 8cae17fda8 Update year to 2012 2012-01-01 01:05:37 +02:00
Daniel Marjamäki 0bf8e6206c STL: Fixed false positive when using string::find 2011-12-27 11:02:43 +01:00
Daniel Marjamäki 2d05cae13b Fixed #3201 (Checking iterators from different objects) 2011-12-26 10:30:39 +01:00
PKEuS dca03c3ce2 Remove unnecessary includes
Also add a unit test related to #3427
Also improve the description text in checkclass and remove unused variable.
2011-12-23 23:31:48 +02:00
Daniel Marjamäki deccb1df06 Fixed #3433 (False positive: Same iterator is used with both myVector and myMap) 2011-12-21 06:16:06 +01:00
PKEuS 2fa0168e55 Patch that improves STL checking: Make use of SymbolDatabase, solved TODO (about returning .c_str() value), check for deleting iterators by value. 2011-12-17 11:21:34 +01:00
PKEuS 91a0a071d0 Take symbol database into use or improve its usage in some checks. 2011-12-09 23:28:10 +02:00
PKEuS 167a7e3e51 Various code cleanups 2011-12-08 21:28:34 +01:00
Marek Zmysłowski a8f2dc1fec Fixed #1841 (STL: false negative for invalidated iterator after erase) 2011-11-25 07:34:50 +01:00
Marek Zmysłowski 9a8c48b36e Fixed #3255 (Error message for std::string::c_str() is not descriptive) 2011-11-20 19:26:07 +01:00
Thomas Jarosch 7202a51065 Add negative test for .c_str() unit test and TODO_ASSERT_EQUALS (#3266) 2011-11-09 21:08:53 +01:00
Richard Quirk 7f88b66842 Fix namespaced types for auto_ptr new[] errors
This fixes false negatives for code such as:

    std::auto_ptr<foo::bar> p(new foo::bar[10]);

The idea is to find a "new", search for the end token ";", then see if
the declaration ends in a closing square bracket. Also fixes other cases
that checked for "new %type% [" so that they work with namespaces.
2011-11-06 21:20:24 +01:00
Richard Quirk 68202d8ffb Extra check for auto_ptr new[]
This fixes cases like this:

   auto_ptr<foo> bar(new foo[10]);

which previously did not work correctly.
2011-11-05 15:45:59 +01:00
Thomas Jarosch 4342fd254c Fixed #3266 (False positive on dangerous usage of .c_str()) 2011-11-04 19:21:19 +01:00
Daniel Marjamäki b18778129c STL: updated error messages for 'useless call to find/swap/substr'. Ticket: #3258 2011-10-31 21:32:30 +01:00
Marek Zmysłowski 950460c0a7 Fixed #3261 (Function 'find' useless call. The variable 'str' is using function 'find' against itself) 2011-10-29 09:24:05 +02:00
Thomas Jarosch 43e9c1f0bd STL check: Detect return of implict string conversion + .c_str()
Examples are:

    std::string msg;
    return ("ERROR: " + msg).c_str();

or

    return ("ERROR: " + std::string("crash me")).c_str();
2011-10-26 22:14:47 +02:00
Thomas Jarosch c4dabd61e9 STL check: Check if someone tries to return std::string(crash_me).c_str() 2011-10-26 21:45:27 +02:00
Thomas Jarosch 03fd308dbf STL check: Look for string.c_str() / stringstream.str().c_str() "return" usage (object is destroyed on return) 2011-10-26 21:12:06 +02:00
Marek Zmysłowski 190139f441 Fixed #3174 (New check: Useless calls of STL functions) 2011-10-24 23:25:23 +02:00
PKEuS dc15641954 Fixed #3223 (Improve check: Check more STL algorithms for missmatching containers check) 2011-10-18 21:55:41 +02:00
Thomas Jarosch 7824e5c0f5 Fixed #3210 (STL check: Add support for reverse iterator) 2011-10-14 19:54:20 +02:00
Daniel Marjamäki 6f8e42a5af changed the astyle formatting flags 2011-10-13 20:53:06 +02:00
Daniel Marjamäki d23c58d387 enable: break out 'performance' and 'portability' from the 'style' id. Ticket: #3074 2011-09-03 15:30:30 +02:00
Kimmo Varis cfcfa3f000 Use "enabled" list for the style checking.
Settings-class currently enables style checking via dedicated
boolean attribute. All other CLI's enable-options are handled
through the enable-list. This commit moves style-check enabling
to use the enable-list.

Main advantage is the consistency how options are handled/stored
in the Settings class. Which also unifies using them for the other
code. You need to enable certain type of checks? Use the
addEnabled()-method. You want to check if certain type of checks
are enabled? Use the isEnabled()-method.
2011-08-07 10:28:52 +03:00
Robert Reif fa82d43562 fix #2967 (segmentation fault of cppcheck ( auto_ptr< x >)) 2011-08-05 18:18:30 -04:00
Robert Reif 2516aad31d fix #2887 (infinit loop with ( A::A(std::auto_ptr<X> e){} )) 2011-08-04 19:50:18 -04:00
Benjamin Wolsey c983608d88 Test false auto_ptr positive.
Assignments after a function returning an auto_ptr is declared are
detected as auto_ptr assignments!
2011-07-20 08:22:35 +02:00
seb777 f1782799cb run astyle 2011-06-20 23:06:18 +02:00
seb777 172903cde4 fix 2846 (false positive for auto_ptr check with container element) 2011-06-20 23:02:05 +02:00
seb777 20de3f90ef fix 2838 (Token::Match called with varid 0 on auto_ptr check) cleanup code and better check varid 2011-06-17 21:09:27 +02:00
seb777 5b940c0c7f fix #747 and #748 (incorrect use of auto_ptr - new check) 2011-06-16 20:26:00 +02:00
Daniel Marjamäki 1c841535ee Fixed #2798 (False positive: Invalid iterator check doesn't respect code paths) 2011-05-22 17:17:24 +02:00
Daniel Marjamäki 9e97da8a57 Reverted fix for string::size. Ticket: #2756 2011-05-05 20:57:17 +02:00
Robert Reif a2938b7212 fix 2011-04-28 19:08:18 -04:00
Robert Reif 1aca09a8bf add support for checking struct/class member container in CheckStl::size() 2011-03-28 19:31:23 -04:00
Daniel Marjamäki 6bd56dbe20 Fixed #2643 (False positive: iterator increment and insert) 2011-03-12 20:29:54 +01:00
Robert Reif e305a155af convert CheckStl::size() to use symbol database, fix false positives, and remove inconclusive 2011-03-07 19:49:43 -05:00
Pete Johns 098f0bf3e6 Fixed #2526 (Make TODO_ASSERT_EQUALS take three arguments (value, to_be, as_is)?...
Removed replaced EXPECTED with...

WANTED (to-be):     The future expected value.
CURRENT (as-is):    Documenting how cppcheck behaves now.

This removes the need for an ASSERT_EQUALS but enforces the check for every TODO_ASSERT_EQUALS.
2011-01-30 23:20:11 +11:00
Daniel Marjamäki 87e3e9e703 Fixed #2488 (false positive with updating iterator in a for loop) 2011-01-20 20:48:35 +01:00
Daniel Marjamäki a21f8eec7c Fixed #2481 (false positive with break: After insert, the iterator '*' may be invalid) 2011-01-20 19:26:52 +01:00
Daniel Marjamäki 70eadb37bd Fixed #2481 (false positive with 'break;': After insert, the iterator '*' may be invalid) 2011-01-19 21:00:46 +01:00