Commit Graph

2863 Commits

Author SHA1 Message Date
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 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