Commit Graph

359 Commits

Author SHA1 Message Date
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
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
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 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 40b493e621 Improve check: Clarify condition (using boolean result in bitwise operation) 2011-08-19 13:40:54 +02:00
Daniel Marjamäki a7728fef48 New check: warn about such suspicious conditions: '(a & b == c)' 2011-08-19 00:15:20 +02:00
Robert Reif 85b2bd21dc fix #2968 (new check: testing if unsigned variable is less than 0) 2011-08-06 19:23:09 -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 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 7826b5e22d add support for detecting unused function variables of type class or struct 2011-06-30 21:58:11 -04:00
seb777 287840e6bc fix #2786 2011-05-25 01:45:58 +08:00
Zachary Blair 46645ab327 Fixed #2722 (new check: statement that is always true (strcmp)) 2011-04-25 22:45:27 -07:00
Robert Reif 56212370d1 add check for same expression on both sides of an operator (part of #2700) 2011-04-10 10:25:02 -04:00
Robert Reif 66de41b313 partial fix for #2700 (common logic or cut and paste errors) 2011-04-09 17:05:27 -04:00
Robert Reif 7e403ae210 fix #311 (add detection of duplicated if else-cases) 2011-04-09 15:14:01 -04:00
Daniel Marjamäki 63acd9bb3e Clarify calculation: Added warnings for << and >> 2011-04-03 22:12:22 +02:00
Daniel Marjamäki 855b01cd5a Clarify precedence 'a*b?c:d' : warn for addition, subtraction and division also. tried to clarify the message more 2011-04-02 11:43:20 +02:00
Stefan Weil 0e4cf7a2d6 Spell checks 2011-03-30 16:44:16 +02:00
Daniel Marjamäki 3e1df1b463 Clarify condition: re-enabled check 2011-03-13 12:16:55 +01:00
Daniel Marjamäki e94ebd829d suspicious condition: commented out the check temporarily - there are some false positives I'll need to fix 2011-03-09 22:29:50 +01:00
Daniel Marjamäki db48158b28 Suspicious condition: Added new check for conditions that contains assignment+comparison 2011-03-09 22:20:14 +01:00
Greg Hewgill a532a9690e full implementation of switch case fall through 2011-03-05 00:45:57 +13:00
Greg Hewgill 93ea774484 initial simplistic implementation of switchCaseFallThrough 2011-03-05 00:45:57 +13:00
Zachary Blair e1b2569b81 Fixed #432 (New check: wrong usage of ! operator in conditions) 2011-02-27 12:30:22 -08:00
Sébastien Debrard f5ed52b84b fix #2569 check postfix increment on boolean 2011-02-11 23:38:23 +01:00
Erik Lax aeae5a867d Fixed #2550 (Bad substr/strncmp comparison) 2011-02-08 19:49:29 +01:00
Daniel Marjamäki d06fde77ff Fixed #2531 (False positive: Redudant assignment to itself) 2011-02-04 20:55:38 +01:00
Greg Hewgill be195a72c9 initialise Check::_name in constructor rather than relying on virtual Check::name() 2011-02-02 22:58:25 +13:00
Daniel Marjamäki a596a7a8fe Fixed #2494 (New check: clarify calculation when using ?: operator) 2011-01-24 21:40:49 +01:00
Debrard Sébastien 27dce075e0 Fixed #155 (check size of a variable whose type is a sized array) 2011-01-22 19:21:56 +01:00
Daniel Marjamäki 94ebb24d3d Optimising: about 5% improvement with Visual Studio executable 2011-01-15 20:55:51 +01:00
Reijo Tomperi 226b605774 Change year 2010 -> 2011 in license texts. 2011-01-09 21:33:36 +02:00
Raphael Geissert 6ec4497919 [PATCH] Check for calls to memset() where 0 bytes are to be filled
Inspired by Silvio Cesare's work
2011-01-06 11:31:58 +01:00
Zachary Blair d11b5163b7 Fixed #2382 (Catching exceptions by value instead of reference) 2010-12-31 03:01:38 -08:00
Daniel Marjamäki 38e7209d26 Fixed #2373 (Using XML2 in --errorlist output) 2010-12-29 12:43:29 +01:00
Zachary Blair 215cb5ac8d Fixed #2162 (false positive: Mutual exclusion over ||) 2010-11-21 00:06:43 -08:00
Daniel Marjamäki fd64a7e683 Mutual exclusion: Disable this check until #2162 is fixed. 2010-11-20 07:43:07 +01:00
Zachary Blair 36d80d6eaa Fixed #2058 (Warn for unused variable when only doing malloc/free) 2010-11-14 17:37:36 -08:00
Daniel Marjamäki 14803643ca empty string test: Removed this check 2010-11-03 17:56:14 +01:00
Daniel Marjamäki bc283d8b99 Uninitialized variables: Broke out the checking into separate file 2010-10-31 12:31:11 +01:00
Daniel Marjamäki df8a93bf97 Null pointers: Broke out the checking into separate file 2010-10-31 11:51:25 +01:00
Daniel Marjamäki 1ef09147f3 CheckOther: updated CheckOther::getErrorMessages 2010-10-31 10:07:35 +01:00
Daniel Marjamäki 995e39200b Fixed #2130 (Invalid possible NULL pointer dereference, etc.) 2010-10-27 20:20:10 +02:00
Daniel Marjamäki bdd6d6d53d null pointer: use simplified token list in the 'check and deref' checking 2010-10-25 21:05:43 +02:00
Daniel Marjamäki 026514db1a Fixed #2127 (null pointer dereference after condition (SRD nr 522)) 2010-10-25 19:43:54 +02:00
Zachary Blair 26afb04dc5 Fixed #2105 (Incorrect operator: mutual exclusion over ||) 2010-10-24 18:14:21 -07:00
Debrard Sebastien 1a4e3dcc44 increment check 2010-10-12 19:54:39 +02:00
Zachary Blair d9967d4fd2 Fixed #2079 (detect side effects in assert) 2010-10-10 13:05:06 -07:00
Pete Johns 4e11e71a21 Fixed 2072 (object destroyed immediately: add --doc info) 2010-10-04 08:54:19 +11:00
Pete Johns 0017655f55 Added test for functor false-positive [passing]
Also removed typedef's following danmar's review and renamed isClassresults -> isClassResults to make more clear.
2010-10-02 18:45:24 +10:00
Pete Johns 6e0ef3eda2 Fixed #1132 (Detection of misused scope objects in functions)
Emits error in the form:

    [useless_lock.cpp:18]: (error) instance of "Lock" object destroyed immediately

    ...if an instance of a class or struct is unnamed and therefore destroyed
    straight after creation.

    Only checks for misused scope objects within functions.

    Optimised isIdentifierObjectType() by memoizing.
2010-10-02 14:22:26 +10:00
Pete Johns 50c2fa9ab0 Revert "Fixed #1132 (Detection of misused scope objects)"
This reverts commit c6acdccfa0.
2010-10-01 20:52:16 +10:00
Pete Johns c6acdccfa0 Fixed #1132 (Detection of misused scope objects)
Emits error in the form:

    [useless_lock.cpp:18]: (error) instance of "Lock" object destroyed immediately

...if an instance of a class or struct is unnamed and therefore destroyed
straight after creation.

Removed "internal error" from token.cpp, since in this case varid would be NULL.
2010-10-01 20:30:21 +10:00
Daniel Marjamäki f843678a07 Redundant conditions: some refactorings
* removed the 'redundant null pointer' check. sometimes it's unsafe to delete NULL pointer. and this check doesn't point out errors anyway.
 * moved the 'redundant condition' check for set::remove. Moved it to CheckStl.
2010-09-16 18:49:23 +02:00
Daniel Marjamäki cfbc06c8b6 removed 'empty catch block' check. to avoid false positives we'll need to check if it is bad with an empty catch block (dead pointer/undefined behaviour/etc) 2010-09-05 13:27:58 +02:00
Daniel Marjamäki 72916caee6 Reverted 7398453cb0 2010-08-15 21:25:14 +02:00
Sbastien Debrard 7398453cb0 Refactoring of obsolete functions checks. Ticket: #1940 2010-08-15 21:22:33 +02:00
Zachary Blair c8087d3389 Fixed #162 (Initialisation of a variable by itself) 2010-08-14 21:34:04 -07:00
Daniel Marjamäki 5846630fa9 Added scanf check. Modified patch submitted by Eric Sesterhenn 2010-08-14 15:15:12 +02:00
Daniel Marjamäki c395e51389 New check: look for calculation inside sizeof 2010-08-06 22:57:10 +02:00
Daniel Marjamäki faa713e7b5 gcc: Fixed some compiler warnings when using -Wsign-conversion. Ticket: #1487 2010-08-06 19:40:54 +02:00
Zachary Blair 5ea28ccbba Fixed #157 (Forgetting to put a break in a switch statement) 2010-06-30 00:10:30 -07:00
Zachary Blair efefceabae Fixed #920 (new style check: find empty catch blocks) 2010-06-14 23:45:46 -07:00
Daniel Marjamäki b5d0955d11 doxygen: fixed error messages given by doxygen 2010-06-14 07:54:41 +02:00
firewave 62093d764d Fixed Visual Studio 2010 warning 2010-05-30 10:44:03 +02:00
Daniel Marjamäki 88e9a4ade6 Fixed #1704 (false negative: null pointer dereference) 2010-05-26 19:16:42 +02:00
Daniel Marjamäki 75c9355e9a Added some multipass checking for the uninitialized variables. It is still experimental. You can activate it with the '--test-2-pass' switch. Some more refactorings are needed to make it truly usable, the main thing is to make it thread safe. 2010-05-21 19:35:18 +02:00
Daniel Marjamäki 6edb2e77b4 Refactoring: Removed Severity::possibleStyle 2010-05-16 14:43:42 +02:00
Daniel Marjamki 972046c4bd Added test CheckOther::sizeofsizeof. Inspired by #1682 2010-05-15 14:06:45 +02:00
Zachary Blair 21b7eb61f5 Fixed #959: (new check: wrong usage of fflush()) Simplified and set severity to error 2010-05-06 23:08:10 -07:00
Zachary Blair 707d27f3d8 Fixed #959 (new check: wrong usage of fflush()) 2010-05-03 23:14:45 -07:00
Daniel Marjamäki 9430089532 Fixed #1626 ('Unusual pointer arithmetic' false positive) 2010-04-26 21:43:01 +02:00
Daniel Marjamäki f3bea249ac Removed the check for unreachable code. The g++ warning -Wunreachable-code is recommended instead. This closes #1603 (break after a return or goto should not be an error in a switch statement). 2010-04-24 14:30:45 +02:00
Zachary Blair 680a470741 Fixed #1564 (CppCheck does not recognise redundant IF) 2010-04-22 01:21:54 -07:00
Zachary Blair c26e619b23 Fixed #855 (Refactoring: move conditions into checks) 2010-04-20 23:38:25 -07:00
Daniel Marjamäki c718a7c595 astyle: Update to astyle 1.24 2010-04-15 20:08:51 +02:00
Reijo Tomperi 35d2a27b9c Update copyright year in all source files 2010-04-13 22:23:17 +03:00
Zachary Blair bd7dc9946e Fixed #1530 (possible new check: strlen return value versus zero.) 2010-04-13 19:30:25 +02:00
Daniel Marjamäki e9b4ea44a2 Refactoring: Disable inconclusive checks. They can still be activated for debugging/testing purposes 2010-04-10 14:05:33 +02:00
Reijo Tomperi 04b38e5428 astyle fix 2010-04-05 20:57:54 +03:00
Martin Ettl d4923e2a92 added atan2() check to ticket #1513 2010-04-05 19:35:56 +02:00
Daniel Marjamäki 78852b08ab Fixed #1566 (false negative: uninitialized variable) 2010-04-04 09:17:53 +02:00
Daniel Marjamäki 8b5aae9adb astyle formatting 2010-04-02 07:32:03 +02:00
Daniel Marjamäki 0cad22314e Reverted 'astyle fix'. Those changes are not in sync with my astyle configuration/setup. 2010-04-02 07:30:58 +02:00
Martin Ettl 193aa7d1d3 astyle fix 2010-04-02 02:21:53 +02:00
Martin Ettl b5fb01c202 ticket #1513 new check: Detecting obviously wrong math call arguments passed to math functions) 2010-04-02 02:19:38 +02:00
Daniel Marjamäki c7bd437d7d astyle formatting 2010-03-19 16:12:51 +01:00
Daniel Marjamäki 45987e5e9f doxygen: some updates to the lib/checkother 2010-03-18 18:59:55 +01:00
Daniel Marjamäki e911d1f1df doxygen updates 2010-03-17 22:16:18 +01:00
Daniel Marjamäki 9d822c77aa doxygen: Some comments for CheckOther, added @todo to Token::Match 2010-03-14 19:11:03 +01:00
Daniel Marjamäki 375d2b1fcd astyle formatting 2010-02-18 19:55:47 +01:00
Daniel Marjamäki b59d79c303 readded checks for unused variables and unreachable code that were removed in 42c608b6f0 2010-02-18 18:45:13 +01:00
Daniel Marjamäki 9394816fcf Refactoring: Use std::string instead of const char * 2010-02-14 19:58:17 +01:00
Daniel Marjamäki 0d18050b55 Fixed #984 (improve output if strncpy is followed by strncat) 2010-02-05 17:35:18 +01:00
Daniel Marjamäki 25bf50755e Reformatting the --doc output to work better in the wiki 2010-01-17 14:56:56 +01:00
Daniel Marjamäki d3b7f5931f Fixed #1174 (improve check: Unintialized variable not detected in subfunction) 2010-01-11 22:28:07 +01:00
Daniel Marjamäki d83131ca92 Fixed #1041 (passing a nullpointer to a reference) 2009-12-30 17:42:41 +01:00
Daniel Marjamäki 2d180ab918 newcheck: added the 'newcheck' functionality. It's still in early state so it needs refactoring 2009-12-06 18:41:28 +01:00
Daniel Marjamäki 60caefe069 uninitialized data: added more checking for allocated data 2009-11-07 09:10:15 +01:00
Daniel Marjamäki c6d7fad84f uninitialized variables: added check 2009-10-29 21:34:43 +01:00
Daniel Marjamäki 09859c1019 refactoring the folder structure 2009-10-25 12:49:06 +01:00