Commit Graph

2954 Commits

Author SHA1 Message Date
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
Daniel Marjamaki b96ab6ba26 Fixed #3188 (Function parser false positive) 2011-11-05 12:23:05 +01:00
Daniel Marjamäki 085a6285fa Fixed #3117 (Tokenizer::simplifyKnownVariables : Don't simplify static variable that is changed) 2011-11-05 08:30:11 +01:00
Daniel Marjamäki d3b27c40fc fixed --doc output 2011-11-05 07:45:30 +01:00
PKEuS 0c469bae41 Fixed #3089 (New Check: Detect wrong usage of printf/scanf) 2011-11-05 07:29:53 +01:00
Thomas Jarosch 4342fd254c Fixed #3266 (False positive on dangerous usage of .c_str()) 2011-11-04 19:21:19 +01:00
Reijo Tomperi 682aae3196 Improve internal error print out, print line number with the error message. 2011-11-03 22:43:13 +02:00
Daniel Marjamäki 9b8ffe7219 Fixed #3248 (Tokenizer: better handling of char constants that are compared with numeric constants) 2011-11-03 20:03:31 +01:00
Daniel Marjamäki 73f3b2074b Fixed #3285 (wrong #elif behaviour) 2011-11-03 19:05:48 +01:00
Daniel Marjamaki b6b5416b42 Tokenizer: Fixed failed unit test 2011-11-02 20:42:38 +01:00
Daniel Marjamaki dfcbc38466 Preprocessor: Don't warn about missing system headers during 'normal' preprocessing 2011-11-02 18:40:56 +01:00
Daniel Marjamaki 0884204c2f Fixed #3279 (Token::Match called with varid 0) 2011-11-02 18:31:13 +01:00
Daniel Marjamäki af7bf5c805 removed 'explicit constructors' check. see comments in pull request #51 for the reasons. 2011-11-02 17:12:46 +01:00
Daniel Marjamaki 937a4497ca Fixed #3272 (Internal error) 2011-11-01 18:03:32 +01:00
Edoardo Prezioso 9dd3360cd6 Fix some complainted choices made in my older commits.
Note: probably you should do 'make clean' before using 'make' to rebuild it again. Maybe it's me but 'make' reports various errors when linking.
2011-11-01 13:23:47 +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
Daniel Marjamäki 7d7a54d89c Merge pull request #53 from gansb/master
Add missing newline
2011-10-31 11:53:33 -07:00
Daniel Marjamäki a7f27a83a7 Fixed #3271 (Regression: something related to symbol database / varid) 2011-10-31 18:33:15 +01:00
Benjamin Goose f22f9fcc0e Add newline at end of file! 2011-10-31 15:12:29 +01:00
Edoardo Prezioso 4295439e53 Fixed ticket #3269 (Regression, I think it's somehow related to symbol database) 2011-10-31 15:05:52 +01:00
Edoardo Prezioso ba5909ef1d General code tweaking, nothing strange. 2011-10-31 02:24:59 +01:00
Daniel Marjamaki f2199adc3f Preprocessor: Bailout #include if it is recursive 2011-10-30 19:00:11 +01:00
Daniel Marjamäki 278ba0ab3a Preprocessor: Enable 'normal' preprocessing whenever any defines are given. The special define CPPCHECK-TEST isn't needed anymore. 2011-10-30 18:40:59 +01:00
Edoardo Prezioso 433f4640a9 Fix some GCC warnings regarding the sign conversion. 2011-10-30 18:34:49 +01:00
Daniel Marjamäki f7fe665b00 Fixed #3231 (False positive: uninitialized variable '({...})') 2011-10-30 18:19:09 +01:00
Daniel Marjamäki 63937f592e Fixed #3228 (false positive: possible null pointer dereference) 2011-10-30 17:59:38 +01:00
Daniel Marjamäki 7035d4cdd2 astyle formatting 2011-10-30 17:41:05 +01:00
Daniel Marjamaki 71f08d0a66 Fixed #3222 (false positive: Uninitialized variable with function pointer) 2011-10-30 17:22:30 +01:00
Edoardo Prezioso 4fc7e86d7d Fixed: with checkConst and checkVariableScope wanted still required "information" settings instead of "style". 2011-10-30 10:58:15 +01:00
Daniel Marjamaki 132f0e12d1 CheckClass: Added classInfo about explicit checking 2011-10-30 09:54:02 +01:00
Daniel Marjamaki 8514466c68 Visual Studio: Fixed compiler error 2011-10-30 09:53:14 +01:00
Daniel Marjamäki 0d1046eeeb Merge pull request #51 from richq/explicit
Explicit constructors
2011-10-30 01:38:26 -07:00
Edoardo Prezioso 42fd4e2f52 Tokenizer: Change 'var++|--;' into '++|--var;' and remove redundant 'tokAt(0)'. 2011-10-29 22:25:49 +02:00
Daniel Marjamäki 92333b585a Fixed #3092 (Tokenizer::setVarId : shadow variable in member function gets the wrong varid) 2011-10-29 21:25:58 +02:00
Daniel Marjamäki d7be62a6f9 Fixed #3221 (FP: Array 'arr[2147483648]' index 0 out of bounds in loop when size unknown to cppcheck) 2011-10-29 20:26:24 +02:00
Daniel Marjamäki 24a2b6e6ba Fixed #3195 (operator() from a functor-struct is never used) 2011-10-29 20:04:43 +02:00
Daniel Marjamäki a809bb3471 astyle formatting 2011-10-29 19:51:11 +02:00
Daniel Marjamäki acaa9c456f Fixed #3152 (Tokenizer: template constructor is removed) 2011-10-29 19:45:47 +02:00
Daniel Marjamäki 316aa920eb Fixed #3245 (False positive: Dangerous usage of 'string' (strncpy doesn't always 0-terminate it)) 2011-10-29 19:11:42 +02:00
Richard Quirk a0a5b36667 Ensure single-argument constructors are explicit 2011-10-29 18:24:30 +02:00
Richard Quirk 2ca932a3ae Add checks for explicit constructors
Single-argument constructors should be explicit. Constructors with
multiple arguments should not be marked explicit.
2011-10-29 18:24:16 +02:00
Daniel Marjamäki 8f49eb6a7e Tokenizer: Make sure that friend classes don't get varid. Ticket: #2962 2011-10-29 18:22:58 +02:00
Daniel Marjamäki d75ef01d2b Null pointer: Added inconclusive error message when calling member function of NULL object. 2011-10-29 15:48:54 +02:00
Daniel Marjamäki 3c509589b5 use reportInconclusiveError instead of reportError if checking is inconclusive 2011-10-29 15:16:27 +02:00
Reijo Tomperi 12a10a7297 Fix related to previously fixed #3256 (Null pointer dereference not detected)
Use reportInconclusiveError() instead of reportError().
2011-10-29 15:55:52 +03:00
Daniel Marjamäki a79b5a5c36 astyle formatting 2011-10-29 12:53:08 +02:00
Daniel Marjamäki f04210ad9f updated comment. removed a inconclusive condition, I don't think it's needed. 2011-10-29 12:52:46 +02:00
Thomas Jarosch ad40586e96 Disable internal checks if NDEBUG is defined (release build) 2011-10-29 12:47:12 +02:00
Daniel Marjamäki 6c02de151f strncmp sizeof: tweaked the check. 2011-10-29 12:27:19 +02:00
Thomas Jarosch 3d438003ff Add internal check that searches Token::Match() patterns for missing % end charaters
Example: "%type" or "foo %var bar"
2011-10-29 12:22:26 +02:00
Daniel Marjamäki 8416768e03 Merge pull request #50 from richq/strncmp
Improved strncmp checks
 * strings are always the same
 * inconclusive: using sizeof(char *) as size parameter
2011-10-29 03:13:21 -07:00
Thomas Jarosch 2b8da1241b Add missing percent end character 2011-10-29 12:08:36 +02:00
Richard Quirk 45d0709ed5 Only run sizeof(char*) check if inconclusive is set 2011-10-29 11:59:24 +02:00
Richard Quirk c2d7824130 Move string comparison out of the report function 2011-10-29 11:52:19 +02:00
Reijo Tomperi 5e0e2c4782 Fix #3256 (Null pointer dereference not detected)
http://sourceforge.net/apps/trac/cppcheck/ticket/3256
It is now detected if --inconclusive command line argument is given (the argument is unofficial currently)
2011-10-29 11:35:31 +03: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
Edoardo Prezioso 5d868766c7 Tokenizer time improvements (time says real: -1 second)
1)change tokAt(1|-1) with next()|previous() with conditions where necessary;
2)change strAt(1|-1) with next()|previous()->str() with conditions where necessary;
3)change tokAt(n)->str(), with n != -1,1, to strat(n);
4)change simplifyFuncInWhile implementation because it was too slow and stupid.
2011-10-29 01:57:53 +02:00
Edoardo Prezioso dd719b41bf Definitely check correctly 'sizeof %num%' when '%num%' has '-' sign. 2011-10-29 00:11:38 +02: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 f6e68914ea Add check for cppcheck's internal API usage (#3263)
First checks:
- Simple pattern used inside Token::Match()
- Complex pattern used inside Token::simpleMatch()

The checks get enabled by passing "--enable=internal".
It's not included in "--enable=all".

If you see something that needs further tweaking, just go for it!
2011-10-28 22:46:07 +02:00
Richard Quirk 665cdfabdc Warn when sizeof is used in strncmp ticket #2095
This checks for the case where the user thought sizeof(buf) gave the
size in bytes of 'buf' in code like the following:

  const char *buf = "Hello World";
  strncmp(buf, other, sizeof(buf));
2011-10-28 22:14:55 +02:00
Richard Quirk 90c7db15a0 Add check for comparison of identical string variables 2011-10-28 22:12:51 +02:00
Richard Quirk 4ba6ac7332 Add strncmp to the list of static string comparison functions 2011-10-28 22:12:51 +02:00
Edoardo Prezioso 979f3b051c Improve nextArgument by returning 0 if there's an unexpected ';'. 2011-10-28 18:57:10 +02:00
Thomas Jarosch ef8f49bbf3 Use new findsimplematch API for simple patterns 2011-10-28 12:49:03 +02:00
Edoardo Prezioso bab740289c Complete todo: convert 'for' into 'while'.
It's not possible to enable this code because of the disaster it will be created for all the checks with the 'for' pattern.
2011-10-28 00:50:54 +02:00
PKEuS 49fd057e17 Tokenizer: Simplify 'foo(void)' to 'foo()' 2011-10-27 19:56:59 +02:00
PKEuS 845e5d259a Improved isJavaOrCSharp, isC and isCPP. Fixed isC for files with includes. 2011-10-27 19:18:54 +02:00
Thomas Jarosch 22251d50bb Bugfix: Use Token::Match instead of Token::simpleMatch because it's a complex pattern
This bug was in here before my recent refactoring.

(And yes, I wrote a check for cppcheck's Token::Match invocation ;))
2011-10-27 16:43:04 +02:00
Thomas Jarosch 434fb933a8 Implement Token::findsimplematch und use it for simple patterns 2011-10-27 15:59:22 +02:00
Thomas Jarosch 54adb910ec Use Token::simpleMatch instead of Token::Match for simple patterns 2011-10-27 15:59:22 +02:00
Daniel Marjamaki 5f4c882b08 minor formatting updates of --doc output 2011-10-27 10:50:40 +02:00
Edoardo Prezioso 9bb1a1b7a5 Added code for simplification of 'for ( a; b; c;); -> '{ a; for (; b; c;) ; }'.
It's not enabled because it fails many tests with testrunner.
2011-10-27 02:59:50 +02:00
Edoardo Prezioso 1be1af4afb Move the simplification of 'strlen' in simplifyTokenList.
This way it's possible to omit the call to simplifyKnownVariables before 'strlen'.
2011-10-27 01:24:35 +02:00
seb777 aa74761e8d fix isC method (.C files are C code files) 2011-10-26 22:54:00 +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 84a763d3b0 Run astyle 2011-10-26 21:15:44 +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
seb777 de71c41379 Fixed Ticket 2144 (false negatives: Old Style Pointer Cast apply only on .cpp files) 2011-10-26 21:17:27 +02:00
Daniel Marjamaki 4b57a146fb Preprocessor: Unit test #error and missing includes. Ticket: #2131 2011-10-25 19:55:47 +02:00
Daniel Marjamaki 40dcab0b6b Preprocessor: Report missing includes during 'normal' preprocessing. Ticket: #2131 2011-10-25 18:16:03 +02:00
Marek Zmysłowski 190139f441 Fixed #3174 (New check: Useless calls of STL functions) 2011-10-24 23:25:23 +02:00
Daniel Marjamäki a076b24dc6 astyle formatting 2011-10-24 21:57:49 +02:00
Thomas Jarosch 3413ffef3e Refactor readlink() buffer check to also handle readlinkat() 2011-10-24 21:23:18 +02:00
Daniel Marjamaki 7fa58b455b Preprocessor: Make it possible to use the 'normal' preprocessor by using special command -DCPPCHECK-TEST. Ticket: #2131 2011-10-24 20:59:46 +02:00
Daniel Marjamaki 0eb4e3032a Preprocessor: handle '#undef' better. Ticket: #2131 2011-10-24 19:51:00 +02:00
Daniel Marjamaki 08ba378730 Preprocessor: Improved 'normal' preprocessing. better handling of multiple #elif and #else blocks 2011-10-24 08:11:44 +02:00
Daniel Marjamaki 3de70a7244 Preprocessor: Better 'normal' preprocessing. Simple handling of '#elif' 2011-10-24 07:37:47 +02:00
Edoardo Prezioso df5d26901c Add new warning option to check for dead code and change the order of some struct members to reduce structure padding. 2011-10-24 03:02:00 +02:00
Thomas Jarosch 55a079a7c4 Clarify Token::concatStr() documentation 2011-10-23 22:47:49 +02:00
Thomas Jarosch 1ccb57e595 Document and test Token::concatStr() 2011-10-23 21:21:42 +02:00
Thomas Jarosch 5b97cc1440 Bugfix: Update token properties on string changes 2011-10-23 21:06:56 +02:00
Daniel Marjamaki 9e50b7cb68 Preprocessor: updates to 'normal' preprocessing 2011-10-23 19:17:29 +02:00
PKEuS cdfe0d74e4 Make checkSprintfCall using nextArguments() 2011-10-23 17:47:48 +02:00
PKEuS dfedeeb5c1 Bugfix: checknullpointer worked incorrect for complex first 2011-10-23 15:23:36 +02:00
Thomas Jarosch db8c7deb30 Fixed #3232 (Check if container is modified inside BOOST_FOREACH) 2011-10-23 13:07:43 +02:00
Thomas Jarosch 6047a28902 Fixed #3185 (Add three more exit functions) 2011-10-23 12:23:53 +02:00
PKEuS 54b3d72ee3 Added Token::nextArgument() 2011-10-23 11:23:48 +02:00
Erik Lax b7ab1e7d7e Fixed #3237 (Bug in parser of class operator functions) 2011-10-23 10:25:14 +02:00