Commit Graph

651 Commits

Author SHA1 Message Date
Daniel Marjamäki e9d697b636 Fixed #3419 (false positive: (style) Same expression on both sides of '&'.) 2011-12-23 16:08:53 +01:00
PKEuS 409364747c Fixed #3441 (segmentation fault of cppcheck (%: return ; ())) 2011-12-23 12:46:59 +01:00
Daniel Marjamäki df8504f0ea Clarify calculation: Fixed false positives when there are various function calls 2011-12-23 12:13:39 +01:00
Daniel Marjamäki fd0d9c8694 CheckOther: Added line break to make the code more readable 2011-12-20 20:54:14 +01:00
Daniel Marjamäki f8181df340 Fixed #3410 (Comparing bool against bool produces false positive) 2011-12-20 06:38:05 +01:00
PKEuS 6dc2a6e7ab Refactorized CheckUnusedVar 2011-12-18 20:15:41 +01:00
PKEuS 0205582161 Fixed #3327 (printf with std::string as parameter) 2011-12-18 19:41:21 +01:00
PKEuS f306246c7f Improved support for references and pointers in SymbolDatabase
Replaced several isPointer functions by Variable::isPointer function
Refactorizations & Make use of symbolDatabase more often
2011-12-17 19:04:03 +01:00
PKEuS 4abee3a345 Refactorings. Use reportError instead of reportInconclusiveError. 2011-12-17 11:39:20 +01:00
PKEuS a311904a0f Patch that fixes some bailouts for isEnabled('style') in both directions. Improved checkSizeofForNumericParameter's error message, made it 'warning', made it non-experimental. 2011-12-16 19:21:14 +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 91a0a071d0 Take symbol database into use or improve its usage in some checks. 2011-12-09 23:28:10 +02:00
PKEuS 97eecb78a7 Fixed #3381 (false positive: (style) Statements following return, break, continue, goto or throw will never be executed) 2011-12-07 18:20:52 +01:00
PKEuS 501d7ccb2d Optimize checkother.cpp by taking symbolDatabase into use. 2011-12-04 20:49:01 +02:00
PKEuS 1f438b0505 Fixed #3375 (Improve check: Detect unreachable code) 2011-12-03 11:43:23 +01:00
Daniel Marjamäki 69d3d4a17d Fixed gcc compiler warnings 2011-12-03 09:57:56 +01:00
Daniel Marjamäki 9a84c5845a Fixed #3373 (False posititive: incorrect %* handling in sscanf) 2011-12-02 17:09:32 +01:00
Richard Quirk d2c8b9be56 Fix possible null pointer dereference 2011-12-01 19:57:04 +01:00
Richard Quirk b2ea78543b Fix false positive with non-const function calls 2011-12-01 19:57:04 +01:00
Richard Quirk a880469c5a Refactor the same expression check
Work out if a function is inconclusive when creating the entry in the
Expressions class instead of when checking the counts at the end. Store
the result in a new bool flag in the ExpressionTokens helper struct.

The pointer to symbol database and ref to list of const functions are
temporarily stored in  the Expressions helper class to avoid passing
them in too on every endExpr(tok) call.

Use a const reference to ExpressionTokens in the check loop to avoid
repeating the it->second several times, which clarifies what that code
does.
2011-12-01 19:57:04 +01:00
PKEuS 5017646488 Coding fixes and refactorings 2011-12-01 19:43:51 +01:00
Daniel Marjamäki 93b21c6cc5 Fixed Visual Studio compiler warnings 2011-12-01 18:27:25 +01:00
Daniel Marjamäki 98480bf504 Fixed #3354 (Incorrect both sides of '||' expression match when using increment in expression.) 2011-12-01 17:46:33 +01:00
Daniel Marjamäki fddfd16758 checkDuplicateExpressions: validate tokens instead of string. Fix for my previous commit. 2011-12-01 17:43:29 +01:00
Daniel Marjamäki 31b576de3b Fixed #3334 (Test for same expression on both sides of '&' reports false positive) 2011-12-01 17:07:55 +01:00
Edoardo Prezioso 767413adad 1)internal check found a 'findmatch' with simple string argument;
2)Style: uniform 'while (...)' when inside it there's an assignment;
3)Replace '0' with 'NULL' where there's comparison with a pointer.
2011-12-01 12:04:47 +01:00
PKEuS ee3e10ea97 Fixed #3364 (Crash in printf parsing) 2011-11-30 20:23:29 +01:00
Daniel Marjamäki 0d48cd390b astyle formatting 2011-11-29 20:44:23 +01:00
Edoardo Prezioso 5c90c69ccf Fixed ticket #3366 (Build breakage) 2011-11-29 19:46:36 +01:00
Daniel Marjamäki b61c01c6a4 Fixed #3356 (false positive: (warning) Comparison of a boolean with integer that is neither 1 nor 0) 2011-11-29 18:14:57 +01:00
Daniel Marjamäki b538f49a6e Merge pull request #61 from richq/sameexpr
Fix for #3317 - same expression on both side of '&&' false positives
2011-11-29 08:50:02 -08:00
Daniel Marjamäki 522da8d258 sizeof for numeric constant : disabled check. see ticket #3179 2011-11-27 18:50:21 +01:00
PKEuS 71c8669261 Fixed #3311, #3313 and #3339 (printf format string false positives) 2011-11-27 07:29:09 +01:00
PKEuS 6b1594244e code cleanups and refactorings 2011-11-26 21:15:16 +01:00
Richard Quirk d28cf42d4c Fix ticket #3317 (same expression false positives)
Add a check for function calls that have no side effects. That means
known const methods and a list including strcmp, strlen, etc.

If the function is not known to be side effect-free then no style
warning is given.

Add test cases for the duplicate expressions.
2011-11-23 21:39:03 +01:00
Richard Quirk 511ac0ab1f Remove false positives for nested logic 2011-11-23 21:39:03 +01:00
Daniel Marjamäki 2e08c8c5b1 DJGPP: Fixed a few compiler errors by using std::size_t instead of size_t 2011-11-22 21:14:14 +01:00
Daniel Marjamäki 5b5ea29f23 Mismatching format string parameters. Made check experimental. See tickets #3311, #3313 and #3339 2011-11-21 07:31:06 +01:00
Richard Quirk 91713ffe84 Fix false positives for %[ in scanf 2011-11-20 16:48:54 +01:00
Edoardo Prezioso a32b05197d Change every 'tokAt(1)' to 'next()' and every 'tokAt(-1)' to 'previous()'.
Added a safety check to ensure that a 'previous()' call doesn't crash (not sure if it's needed or not).
2011-11-20 15:59:37 +01:00
Edoardo Prezioso 11dd3c09ce Change every 'tokAt(1)->' to 'next()->' because 'tokAt(1) == 0' is equivalent to 'next() == 0', hence the equivalent cppcheck crash. 2011-11-20 15:09:57 +01:00
Edoardo Prezioso 42e369a4b4 Change every 'tokAt(..)->link()' to 'linkAt(..)'. 2011-11-20 14:24:27 +01:00
Marek Zmysłowski 994f08fdf0 Fixed #886 (new check: wrong value passed to isgraph function) 2011-11-17 16:31:16 +01:00
Edoardo Prezioso 2c64d299ca Change every 'tokAt(...)->str()' to 'strAt(...)'. 2011-11-13 13:10:59 +01:00
Thomas Jarosch c010ca33a5 Run astyle 2011-11-09 20:34:58 +01:00
Daniel Marjamäki b7cc9779c4 Merge pull request #59 from richq/sameexpr
Improved same expression check for ticket #3274
2011-11-08 23:56:36 -08:00
Reijo Tomperi 7a294c1f79 Fix #3307 (Invalid format string/parameter mismatch warning)
http://sourceforge.net/apps/trac/cppcheck/ticket/3307
2011-11-09 00:16:37 +02:00
Richard Quirk d1bc8819f9 Fix for same expression separated by commas
The code branch tested by the previous check for && is now different, so
I've changed the test to use == instead. There was also a missing case
when the expression was followed by a comma instead of being preceded by
one.
2011-11-08 21:56:54 +01:00
Richard Quirk d5664dd6cf Improved %or% and & checks 2011-11-08 21:56:54 +01:00
Richard Quirk 4cb97edbaf Improved same expression check for ticket #3274
Expand the logic for the check for the same expression on both sides of
the || and && operators. Now expressions can be more complex, with the
"alt" variable helping to fudge operator precedence to avoid false
positives.
2011-11-08 21:54:42 +01:00
Daniel Marjamäki fa076598ad Fixed #3233 (false positive: (style) Checking if unsigned variable 'i' is less than zero.) 2011-11-06 18:24:37 +01:00
Edoardo Prezioso 6e2f2816de Improve same expression check: remove '%op%' pattern and add ',' for the same expressions as an argument inside a function.
Improve compound assignment simplification: use already defined 'isAssignmentOp' and extend the adding parenthesis to a generic operator, not only to the arithmetical ones. See: http://en.cppreference.com/w/cpp/language/operator_precedence
2011-11-06 14:35:53 +01:00
Daniel Marjamäki f092779a4d Fixed #3282 (Invalid report that an array index is of type char.) 2011-11-06 11:26:28 +01:00
Daniel Marjamäki e11c1f7975 Fixed #3265 (false positive: comparison of bool with nonzero integer) 2011-11-06 08:21:34 +01:00
Edoardo Prezioso 99463d3368 Improve same expression check: take count of operations and assignments before the same expression and add missing 'return' pattern to the struct member variable part of the check. 2011-11-05 22:25:01 +01:00
Daniel Marjamäki d4a8184339 Fixed #3251 (Redundant code: Found a statement that begins with numeric constant) 2011-11-05 20:28:52 +01:00
Richard Quirk a3f2c1e651 Improve for same expression on both sides of operator 2011-11-05 15:46:11 +01:00
PKEuS 0c469bae41 Fixed #3089 (New Check: Detect wrong usage of printf/scanf) 2011-11-05 07:29:53 +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
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 Marjamäki 3c509589b5 use reportInconclusiveError instead of reportError if checking is inconclusive 2011-10-29 15:16:27 +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
Daniel Marjamäki 6c02de151f strncmp sizeof: tweaked the check. 2011-10-29 12:27:19 +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
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
Edoardo Prezioso dd719b41bf Definitely check correctly 'sizeof %num%' when '%num%' has '-' sign. 2011-10-29 00:11:38 +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
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
seb777 de71c41379 Fixed Ticket 2144 (false negatives: Old Style Pointer Cast apply only on .cpp files) 2011-10-26 21:17:27 +02: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
PKEuS ccf087d2ea checkMathFunctions: Refactoring the check 2011-10-22 12:31:47 +02:00
PKEuS ea02bd905a Fixed #3225 (Boolean comparison with string literals) 2011-10-18 21:37:03 +02:00
Thomas Jarosch a52b73f9f9 Fix #3208 (Simplify pointer to standard type, C only)
The symbol database is unavailable during token simplification
and &data[0] might return something completely different for C++.

Moved code_is_c() from checkOther to Tokenizer.
2011-10-16 08:09:57 +02:00
Daniel Marjamäki 6f8e42a5af changed the astyle formatting flags 2011-10-13 20:53:06 +02:00
Zachary Blair 82366918ff Fixed #2627 (switch case fall through: redundant strcpy) 2011-10-13 01:27:22 -07:00
Robert Reif af6a6f9c2d run astyle 2011-10-12 09:08:54 -04:00
Thomas Jarosch 849bee8437 [PATCH] Detect suspicious use of semicolon after 'if/for/while'
statements if they are followed by a {..} block.

Examples are:

for (int i = 0; i < 10; ++i);
{
   printf("i)";
}

or

if (i == 100);
{
   die("Wrong argument");
}

This new check is active if you enable inconclusive checks.
2011-10-11 08:41:39 +02:00
Zachary Blair fcf360825a Fixed #2955 (New check: Using && instead of &) 2011-10-10 10:11:17 -07:00
PKEuS 5f9b916dcc Fixed #2115 (new check: endless loop (unsigned comparison that is always true)) 2011-10-09 20:35:46 +02:00
Daniel Marjamäki 73fb6725e6 Readded CheckOther::bitwiseOnBoolean as inconclusive check 2011-10-06 22:01:48 +02:00
Daniel Marjamäki 09109f19f8 Removed CheckOther::bitwiseOnBoolean check. The reasons can be seen in my comments in ticket #3062. 2011-10-05 20:46:07 +02:00
PKEuS 494d3af3d1 Fixed #1877 (Be more strict about int vs. bool, part II) 2011-10-05 20:30:36 +02:00
Kimmo Varis 3cfe7ca1a7 Move "information" errors to "style" errors.
"information" severity is documented in lib/errorlogger.h as:

  Checking information.
  Information message about the checking (process) itself. These
  messages inform about header files not found etc issues that are
  not errors in the code but something user needs to know.

It IS NOT for errors in the code. All the current "information"-
severity errors fit nicely into description of the "style"-
severity.

We definitely need to separate processing information and actual
errors in the code. It is highly confusing for users to mix these
two different things. Hence all current "information" code error
messages are moved to "style" category.

Ticket: #3165 (Stop misusing the 'information' error severity!)
2011-10-05 20:44:00 +03:00
Robert Reif 2d717d77cd reduce false negatives for checking for CheckOther::checkSignOfUnsignedVariable() 2011-09-26 21:24:34 -04:00
Robert Reif 735ff11469 fix #3110 (false positve: style) Boolean result is used in bitwise operation. Clarify expression with parentheses) 2011-09-12 07:32:55 -04:00
Daniel Marjamäki 55230baf78 Fixed #3086 (false positive: Boolean result is used in bitwise operation.) 2011-09-11 09:46:01 +02:00
Philipp Kloke 2f62d180fe Fixed #1740 (Undefined Behavior: Divide by zero) 2011-09-10 16:12:53 +02:00
seb777 074ad10a30 fix #195 Unusual shift operation - check this kind of code
return x >> ! y ? 8 : 2;
2011-09-06 22:37:19 +02:00
Robert Reif b27bbea44a really fix #3079 (Spelling error in unsigned variable check 'never alwayw') 2011-09-05 09:48:59 -04:00
Robert Reif 2250a2dfc3 fix #3079 (Spelling error in unsigned variable check 'never alwayw') 2011-09-05 09:04:27 -04:00
seb777 5c7ed46e0c Following the discussion XX, replace the keyword C99 '_Bool' with the 'bool' keyword in the process of tokenization\nSee f29b7f9f08 2011-09-03 23:15:33 +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
Robert Reif f29b7f9f08 fix #3062 (false negative: Boolean variable is used in bitwise operation) 2011-09-02 17:19:06 -04:00
Robert Reif 2dd93dff75 move unused variable checks from checkother to checkunusedvar 2011-08-19 14:35:25 -04:00
Robert Reif 9fbef3ca7b fix #3011 (new check: when first comparison is true, the 2nd comparison is always true) 2011-08-19 13:28:37 -04:00
Daniel Marjamäki a735790e77 using boolean result in bitwise operation. fix false positive for '.. != (char *) &x' 2011-08-19 18:55:20 +02:00
Daniel Marjamäki 2dd1e290eb fixed false positives for the 'bitwise operator / comparison operator' check 2011-08-19 18:06:28 +02:00
Robert Reif eda9ff6fc5 refactor checkother to move error messages to follow check and rename some error functions to end in Error 2011-08-19 11:53:43 -04:00
Daniel Marjamäki 314d5f1e79 fixed false positive for 'using bitwise operation on boolean result' 2011-08-19 17:07:26 +02:00
Daniel Marjamäki c107fdd2d4 Fixed #3018 (false positive: (style) Suspicious condition (assignment+comparison), it can be clarified with parentheses) 2011-08-19 13:54:06 +02:00
Daniel Marjamäki 40b493e621 Improve check: Clarify condition (using boolean result in bitwise operation) 2011-08-19 13:40:54 +02:00
Daniel Marjamäki 0d7c80ef21 improved comment of previous commit 2011-08-19 07:28:15 +02:00
Daniel Marjamäki 4606251ce8 Fixed #3001 (False Positive: Redundant assignment to itself) 2011-08-19 07:23:11 +02:00
Daniel Marjamäki e5ff920ea9 Suspicious condition: Better handling when rhs is non-numeric 2011-08-19 00:56:15 +02:00
Daniel Marjamäki a7728fef48 New check: warn about such suspicious conditions: '(a & b == c)' 2011-08-19 00:15:20 +02:00
Daniel Marjamäki 4f962acf16 Fixed #3009 (Using numeric constants in kernel space code) 2011-08-16 20:16:33 +02:00
Robert Reif ad45ba718c convert CheckOther::checkCharVariable() to use symbol database 2011-08-14 10:39:45 -04:00
Robert Reif cd2c0fd9c8 convert CheckOther::checkSizeofForNumericParameter() to use the symbol database 2011-08-14 10:21:07 -04:00
Robert Reif 741eabba16 convert CheckOther::checkIncrementBoolean() to use the symbol database 2011-08-14 10:16:39 -04:00
Daniel Marjamäki 003956e42e Fixed #2982 (false positive: using char type as array index (using string as key)) 2011-08-09 17:03:22 +02:00
Daniel Marjamäki 8a6a999f09 Fixed #2979 (Improve message: using char as array index) 2011-08-08 19:35:11 +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 85b2bd21dc fix #2968 (new check: testing if unsigned variable is less than 0) 2011-08-06 19:23:09 -04:00
Moritz Lipp 8d68981119 Fixed #2793 (SIGABRT on filenames without file extension) 2011-07-31 18:35:28 +02:00
Robert Reif 2f4aee2923 fix missing else in patch that added support for unused const local variables 2011-07-30 07:16:59 -04:00
Robert Reif cb4282d69a use simpleMatch where possible in checkother.cpp 2011-07-29 22:37:05 -04:00
Daniel Marjamäki dc629b4c39 Fixed 'possible null pointer dereference' warning messages 2011-07-28 08:12:21 +02:00
Daniel Marjamäki d2c0e5e7e6 Fixed #2821 (New Check : bool pointer null truth assignment) 2011-07-28 07:28:24 +02:00
Robert Reif 9a4447c835 add support for unused const local variables 2011-07-24 12:09:59 -04:00
Simon Martin 539c2e5acb Fixed #2932 (segmentation fault of cppcheck ( i / i )) 2011-07-24 09:06:38 +02:00
Robert Reif c3c3eb74e8 fix #2929 (Additional Unused variable check) 2011-07-21 18:37:37 -04:00
Robert Reif ed30edf9d3 simplify CheckOther::checkIncorrectLogicOperator() by using more pattern matching 2011-07-18 07:34:49 -04:00
Robert Reif 76d0872c0d made #2827 fix more generic by adding more ops and using pattern matching rather than string matching 2011-07-17 16:28:00 -04:00
Robert Reif 4149617978 fix #2827 to use numeric comparisons 2011-07-16 23:05:35 -04:00
Robert Reif 430d22032d fix #2827 condition always false or true) 2011-07-16 22:06:23 -04:00
Zachary Blair 997a3652d2 Fixed #2822 (New check: Duplicate break statements in switch) 2011-07-14 17:12:56 -07:00
Robert Reif 270b2b1772 fix #2904 (Memory leak not detected when creating a new class instance) 2011-07-14 19:15:59 -04:00
Daniel Marjamäki 0007351ef4 spell check of error message. contant => constant 2011-07-05 19:59:58 +02:00
Daniel Marjamäki 8cd2c3115e Fixed #2866 (Detect sign extension bugs) 2011-07-05 18:41:27 +02:00
Greg Hewgill 657b003dc8 Fix spelling error in warning identifier 2011-07-05 19:54:23 +12:00
Robert Reif b32b2c6d87 add support for checking unused std::string local variables 2011-07-02 19:25:10 -04:00
Robert Reif 301e59cea0 fix false positive for unused local class/struct variable 2011-07-01 08:45:29 -04:00
Robert Reif 18e6509c5d add support in CheckOther::functionVariableUsage() for checking structures that are declared with struct keyword 2011-07-01 07:42:20 -04:00
Robert Reif 3225c9dd9b cleanup isStatic in CheckOther::functionVariableUsage() 2011-07-01 07:15:59 -04:00
Robert Reif 7826b5e22d add support for detecting unused function variables of type class or struct 2011-06-30 21:58:11 -04:00
Daniel Marjamäki 97d47fa20e Fixed #2805 (false positive: [NotAssigned1.cpp:5]: (style) Variable 'y' is not assigned a value) 2011-06-08 19:54:01 +02:00
seb777 e06b2419a4 fix #2786 (new check: Using sizeof with numeric constant)
Add unit test and improve check with negative constant because in cppcheck %num%
means 'integer'
2011-05-28 16:40:01 +08:00
seb777 287840e6bc fix #2786 2011-05-25 01:45:58 +08:00
Daniel Marjamäki 144d811e54 Fixed #2780 (false positive: variable p is not assigned a value 'int p[2]; *p = 0;') 2011-05-11 18:58:25 +02:00
Robert Reif 2db67863a7 #2700 (common logic or cut and paste errors) make duplicate branches inclnclusive 2011-05-08 13:22:42 -04:00
Daniel Marjamäki 3629f953f0 Fixed #2770 (False positives (scope can be reduced / variable is assigned value that is never used)) 2011-05-06 21:16:01 +02:00
Zachary Blair 46645ab327 Fixed #2722 (new check: statement that is always true (strcmp)) 2011-04-25 22:45:27 -07:00
Daniel Marjamäki 46afc54c10 astyle formatting 2011-04-20 06:41:26 +02:00