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
Reijo Tomperi
bf2759118b
Added support for C++11's cend/crend/cbegin/crbegin functions in some STL checks
...
Patch from: PKEuS <philipp.kloke@web.de>
2011-10-22 23:38:03 +03:00
Reijo Tomperi
3568b5a841
Improved memset with 0 bytes check. TODO done (unit test).
...
Patch from: PKEuS <philipp.kloke@web.de>
2011-10-22 23:34:10 +03:00
Edoardo Prezioso
91c6608175
Improve fix of #934 (be careful of macros code).
2011-10-22 20:43:42 +02:00
PKEuS
20179673ce
Fixed #934 (new check: missuse of std::cout)
2011-10-22 17:12:52 +02:00
Edoardo Prezioso
12f6ce46f8
Add more warnings and fix the ones reported by them.
2011-10-22 15:05:43 +02:00
Johan Samuelson
3d8fa2f76e
Fixed #3123 ([False Positive] Shadowed enum)
2011-10-22 13:43:53 +02:00
Daniel Marjamäki
32e20d4e31
made 'variableHidingTypedef' inconclusive. See ticket #3199
2011-10-22 13:26:33 +02:00
Erik Lax
2b54f00c87
Fixed #3238 (Crash in obsolete functions check.)
2011-10-22 12:36:45 +02:00
PKEuS
ccf087d2ea
checkMathFunctions: Refactoring the check
2011-10-22 12:31:47 +02:00
Thomas Jarosch
55d9f0873a
Fix #3243 (Improve non reentrant function check)
...
- Use std::map instead of linear std::list walk
and run fast tests like tok->isName() first.
Global speed up is 4.8% (profiled with google-perftools)
- Catch function invocations in global namespace
and ignore other namespaces except "std".
std::localtime() and others are also non-thread safe on POSIX.
Note: The check matches f.e. also on "std::getrpcbyname()",
but that would result in a compile error anyway.
No need to have an extra "std::xxxxx" whitelist.
- Remove double listed "rand" and "getrpcbyname" function names
2011-10-22 11:54:52 +02:00
Daniel Marjamäki
a9d2d45fbc
astyle formatting
2011-10-22 11:11:54 +02:00
Marek Zmysłowski
8157799e10
Fixed #3204 (Refactor standards support in Settings)
2011-10-22 10:34:04 +02:00
Daniel Marjamäki
cde95d09a3
Merge pull request #41 from gansb/master
...
std::istream used but not declared.
2011-10-22 00:54:04 -07:00
Daniel Marjamäki
ab827e3631
Merge pull request #40 from joshbeck/master
...
Added option to set #ifdef configuration check limit
2011-10-22 00:51:05 -07:00
Marek Zmysłowski
b332ea8222
Fixed #3204 (Refactor standards support in Settings)
2011-10-22 09:45:48 +02:00
Benjamin Goose
3f25bd9530
Qualify fill_n properly.
...
Relying on ADL isn't a good idea as it's not always well implemented.
2011-10-20 09:02:20 +02:00
Benjamin Goose
463b105d98
Add condition for HP-UX.
2011-10-20 09:01:58 +02:00
Benjamin Goose
7d6b76e1d1
Include <iosfwd> for std::istream.
2011-10-20 08:46:29 +02:00
seb777
41d9daa03d
Fixed ticket #3133 (Improve Check: Found obsolete function)
...
- add check for std::gets
- improve check when multiple obsolete functions are used
- remove false positive (declared functions)
2011-10-19 20:21:50 +02:00
Edoardo Prezioso
9257e82475
Improve tokenizer: don't confuse between a label and the case/default statements.
2011-10-19 18:49:02 +02:00
Edoardo Prezioso
882b0c15a0
Improve tokenizing of "do{ ... } while(0)".
...
The simplification will be the same for every combination, except for the 'continue' and the 'break'. In that case, keep the block braces.
2011-10-19 18:20:29 +02:00
Edoardo Prezioso
c9ee19c654
Complete 'disable the rules by default' for other platforms.
2011-10-19 15:14:39 +02:00
Edoardo Prezioso
4f256ef314
Runastyle + removal of useless conditions after previous commit.
2011-10-19 14:48:08 +02:00
Edoardo Prezioso
73f0e2c5b9
Fixed ticket #3227 (Improve tokenizer: labels are not handled correctly after a case or another label instruction)
...
Moved the labels simplification after combining the tokens and moved the case/default simplification inside the labels.
2011-10-19 14:20:09 +02:00
Joshua Beck
56561835f8
Add option to set #ifdef configuration check limit
2011-10-18 19:52:55 -05:00
Edoardo Prezioso
f4cdf57955
Fixed ticket #3229 (Segfault with goto):
...
Don't handle labels, gotos, returns and indentations inside the round braces. This is applied not only for simplifyGoto, but also to simplifyFlowControl.
Rewrite enum badly handled by astyle inside mathlib.cpp and move simplifyFlowControl at the end of the simplifyTokenList in order to catch more dead code, not related to the ticket.
2011-10-18 23:56:35 +02:00
PKEuS
dc15641954
Fixed #3223 (Improve check: Check more STL algorithms for missmatching containers check)
2011-10-18 21:55:41 +02:00
PKEuS
ea02bd905a
Fixed #3225 (Boolean comparison with string literals)
2011-10-18 21:37:03 +02:00
Daniel Marjamäki
3d18fdfa3f
Fixed #3220 (False positive: possible null pointer dereference: 'SwDoc *pDoc = NULL; pDoc->do_something();')
2011-10-18 19:34:14 +02:00