Commit Graph

318 Commits

Author SHA1 Message Date
Daniel Marjamäki df6ae9f3b4 Fixed #7847 (Can't detect shift negative values when some op is executed) 2016-12-22 09:40:19 +01:00
Frank Zingsheim c8ff96fe8f Fixed #6180 (Usage of variable after std::move or std::forward) 2016-11-20 15:14:49 +01:00
PKEuS 452ecc7ceb Improved check: Detect passedByValue even for arguments that are not declared as "const" 2016-07-28 19:37:10 +02:00
Daniel Marjamäki 03d2829fb9 Merge simplecpp branch 2016-07-20 12:21:00 +02:00
amai2012 eba1b0881d Minor refactoring: use nullptr (instead of 0/NULL), change signature of Tokenizer::createTokens 2016-05-07 16:30:54 +02:00
Dmitry-Me c3399493ef Portability warning when 'char' type is used as array index 2016-02-08 10:08:35 +03:00
PKEuS 9d2258677d Improved CheckOther::checkUnusedLabel(): Write a warning instead of a style message if it happens inside a switch() 2016-01-31 12:07:24 +01:00
Matthias Krüger e9e496199c CheckOther::memsetZeroBytesError: remove now unused parameter.
was:
lib/checkother.cpp:1116:76: warning: unused parameter ‘varname’ [-Wunused-parameter]
 void CheckOther::memsetZeroBytesError(const Token *tok, const std::string &varname)
                                                                            ^
2016-01-12 23:55:02 +01:00
Lauri Nurmi 996c9244d8 Update copyright year to 2007-2016. 2016-01-01 15:34:45 +02:00
Daniel Marjamäki 32455e8441 Fixed #7214 (ValueType: does not handle static_cast) 2015-12-26 15:20:17 +01:00
Daniel Marjamäki 81f0597316 Fixed #3206 and #7226 (New check: Undefined execution order) 2015-12-24 09:13:20 +01:00
Daniel Marjamäki fb8cce647c invalidTestForOverflow: Refactor; move from checkother to checkcondition 2015-11-30 08:51:15 +01:00
Daniel Marjamäki 26a07265a8 Fixed #7184 (Invalid test for overflow 'p + x < p') 2015-11-29 20:59:50 +01:00
Daniel Marjamäki 4fa888ec44 Warn when shifting a negative value, it is UB. (#4931) 2015-11-29 16:28:55 +01:00
PKEuS f516de8633 Moved a few checks from CheckOther to CheckFunctions 2015-11-22 13:49:10 +01:00
Daniel Marjamäki 0f9d90d2be Changed Copyrights. Removed my name. 2015-11-18 20:04:50 +01:00
PKEuS c5a8ecb6f9 New check: Detect unused 'goto' labels (#5124) 2015-08-30 16:45:47 +02:00
PKEuS 1a266315f1 Removed some unused code 2015-08-15 19:17:25 +02:00
Dmitry-Me eec5e1722b Remove unimplemented method 2015-08-10 18:02:49 +03:00
Daniel Marjamäki ec3d76be5e astyle formatting 2015-08-07 20:27:32 +02:00
amai2012 53feb88614 Merge pull request #630 from Dmitry-Me/detectRaceInInterlockedAccess
Prototype for detecting non-interlocked check after InterlockedDecrement()
2015-08-06 15:43:10 +02:00
Dmitry-Me 43800a9419 Detect non-interlocked check after InterlockedDecrement() 2015-08-05 12:20:28 +03:00
Daniel Marjamäki e598b07a6d Moved functions to astutils 2015-08-03 09:20:50 +02:00
Alexander Mai 96c3c111fc Refactoring: Move some AST related functions to distinct source file 2015-08-02 21:57:32 +02:00
Daniel Marjamäki 389aec51ae Fixed #6598 (False positive zerodivcond - cast to double ignored) 2015-07-26 22:08:36 +02:00
amai2012 649a89d308 Refactoring: Expose some previously local functions to public and add Tokenizer as argument to distinguish between C and C++ code (e.g. in isSameExpression).
Refactoring: Improve type-safety for TestFixture::assertEquals to allow tests with types which were not handled correctly (e.g. unsigned long long)
2015-06-28 12:08:36 +02:00
Alexander Mai 0a6babea74 #6181 Drop redundantGetAndSetUserId. Ensure (style-) warnings are issued if setuid()/getuid() and some related functions are ignored. Move strdupa()/strndupa() from posix.cfg to gnu.cfg 2015-02-16 22:19:51 +01:00
PKEuS 0488f45a5f Removed standalone check CheckOther::checkDoubleFree(), integrated (most of) the functionality into CheckLeakAutoVar. Added support for new/delete to checkLeakAutoVar. 2015-01-28 17:38:43 +01:00
Daniel Marjamäki 3285f85ebf Fixed #6460 (Library: better function/type matching) 2015-01-27 17:55:18 +01:00
Thomas Jarosch 58cb6cc116 Add new "style" check to catch redundant pointer operations
Doing "&*some_ptr_var" is redundant and might be the remainder
of a refactoring. Warnings for expanded macros are excluded though:
They are often used with and without pointers and
do something like this: "func(&(*macroarg))".

The new check is fully AST based and was given
strong false positive testing on a large code base.
2015-01-18 00:34:07 +01:00
PKEuS 267552779d Improved check (#6391): Detect identical code in both branches of ternary operator 2015-01-03 18:01:49 +01:00
PKEuS bb9ce68354 Refactorization: Reduced chaos in CheckOther::classInfo() 2015-01-03 18:00:16 +01:00
Daniel Marjamäki ff11ba9847 Updated copyright year to 2015 2015-01-03 12:14:58 +01:00
Daniel Marjamäki 051d42ae6b astyle formatting 2014-11-20 14:20:09 +01:00
orbitcowboy f5d804f71a running astyle 2014-11-20 10:13:03 +01:00
PKEuS b5ea677180 Some fixes for CheckOther::checkIgnoredReturnValue():
- Fixed name of the function
- Fixed false positive for code like "class strcmp { strcmp() {} };"
- Fixed FP #6233 on checking side (no AST generated for function call)
2014-10-30 23:24:13 +01:00
Daniel Marjamäki fbc6323a9b doc: changed --doc output to Markdown syntax 2014-09-30 14:56:12 +02:00
PKEuS 210294443e New check: Check for unused return values (#653) 2014-09-27 21:31:04 +02:00
Daniel Marjamäki 0e55f12140 Fixed #6165 (Remove old checkUnsignedDivision checker that uses neither AST nor ValueFlow. The CheckType::checkSignConversion should be much more accurate) 2014-09-12 16:59:16 +02:00
Daniel Marjamäki 7847263451 Fixed #6158 (New check: dangerous sign conversion) 2014-09-11 18:10:19 +02:00
Daniel Marjamäki 974c8688c3 Fixed #1751 (Undefined Behavior: Signed integer overflow) 2014-09-10 17:02:18 +02:00
Daniel Marjamäki a36b0e55be CheckOther::checkTooBigBitwiseShift: improving error messages 2014-09-09 17:06:45 +02:00
Daniel Marjamäki f111a89639 Fixed #1757 (Undefined Behavior: Shift too many bits) 2014-09-09 07:24:59 +02:00
PKEuS ff4fc6a234 New check: Recommend expm1, log1p, erfc (#5392) 2014-09-07 11:38:49 +02:00
Alexander Mai a4ff30301a #5805 'Passing value -1.0 to sqrt() leads to undefined result' is incorrect. Degrade wrongmathcall from error to warning, since it deals with implementation-defined behaviour 2014-09-01 19:31:32 +02:00
PKEuS 06a92e8981 Moved several condition checks from checkOther to checkCondition (former checkAssignIf) 2014-08-29 17:06:46 +02:00
PKEuS eba8c6f6c5 Refactorization:
- Added missing separating comments between checks in checkother.cpp
- Moved checks related to strings into own file
2014-08-27 09:42:09 +02:00
PKEuS 8f79dc3ff8 Cleaned up includes and forward declarations in checkers:
- Removed definitely unnecessary forward declarations (e.g. "class Token"; token.h is already included by check.h, so a definition is unnecessary)
 - Removed unused includes
2014-05-24 12:50:03 +02:00
PKEuS d19eabde42 New Check: Compare pointer with '\0' (#4070) 2014-05-21 19:12:07 +02:00
PKEuS cdfed32500 Merged checkSelfAssignment() into checkDuplicateExpression():
- Fixed false negatives on self assignments of more complex expressions like "a.b"
- New false negative on self assignment in initialization
- Support this->... pattern in isSameExpression()
- Fixed #5819: Check type of operands
2014-05-21 18:19:42 +02:00
Massimo Paladin 5e996bc63b Fix redundantConditionError check description 2014-05-07 14:54:50 +02:00
Philipp Kloke dfd9d32c4b Refactorization: Removed whitespaces at the end of a token
Removed a redundant 'void'
2014-04-12 23:41:46 +02:00
Daniel Marjamäki 8dcb3bae47 Refactoring checks of overlapping conditions in if and else-if 2014-04-03 19:35:50 +02:00
PKEuS 50a94885ce Fixed oppositeInnerCondition check:
- Resolved false positives #4170 and #4186, as well as numerous other potential false positives
- Improved message to point to both locations
- Inner condition could also be a while loop; Outer if could also be 'else if'
- Made the check non-experimental again (#3645)
2014-03-28 14:55:17 +01:00
Daniel Marjamäki 54e7f34f4a Fixed #5584 (FP: Division by zero when function not declared) 2014-03-20 16:12:58 +01:00
Lucas Manuel Rodriguez 052840f8f5 Fixed #4818 (New check: Check memset() 2nd parameter) 2014-02-15 15:06:00 -03:00
Daniel Marjamäki fd3a8a2a18 Update copyright 2014-02-15 07:45:39 +01:00
Daniel Marjamäki 3facc06cb7 CheckOther: Removed non-valueflow check for division by possible zero before condition 2014-01-17 17:42:54 +01:00
Daniel Marjamäki ac30a84c3a Refactoring: Replaced CheckOther::checkCCTypeFunctions with configuration 2013-12-23 19:58:33 +01:00
Daniel Marjamäki 76b907fe65 Fixed #5252 (Improve check: use Library to validate function arguments in invalidFunctionUsage) 2013-12-23 10:06:45 +01:00
Daniel Marjamäki 83066edec0 Code cleanup 2013-12-10 06:29:06 +01:00
Martin Ettl babbee4e73 Fixed typos in comments, no functional changes. 2013-11-09 16:07:28 +01:00
orbitcowboy 677257f569 Fixed clang warning: lib/checkother.h:360:80: warning: implicit conversion turns string literal into. 2013-09-30 10:43:21 -07:00
Martin Ettl 5aaaff46ee Fixed #5049: new check: (warning) Comparison of two identical variables with isgreater(result,result) evaluates always to false. 2013-09-26 07:07:48 +02:00
Daniel Marjamäki 83c460fc56 Fixed #5017 (New check: division by zero, otherwise condition is redundant) 2013-09-07 07:40:10 +02:00
Ettl Martin 9ab6655d85 Fixed #5007 (Same include guard naming) 2013-09-04 20:59:49 +02:00
PKEuS a9a5dc0354 Updated to AStyle 2.03, require this version 2013-08-07 16:27:37 +02:00
Abhishek Bharadwaj d85c8e6782 Fixed #4104 (New check: comma separated statements in return statement from a function) 2013-06-15 17:49:10 +02:00
Zachary Blair 28c0045f36 Fixed #4173: New check: arithmetical usage of inf/nan result 2013-06-09 23:13:08 -07:00
Lena Herscheid e23038c4de Fixed #4775 (Check for assert() with side effects) 2013-05-07 21:35:16 +02:00
PKEuS 994c429b7d Moved checks related to sizeof usage from checkother into new file 2013-04-10 09:49:38 -07:00
PKEuS 42fcb04d0c Moved checks related to boolean type (not condition checking!) from checkother into new file 2013-04-10 09:25:50 -07:00
PKEuS 14feaa8d39 Refactorizations:
- Fixed lots of cppcheck messages about functions that can be const or static
- Fixed possible nullpointer dereference message in symboldatabase.cpp
- Replaced tokAt(+-1) by next()/previous()
2013-03-12 07:42:00 -07:00
Ettl Martin bb115573f7 #4645 implemented new check: (POSIX) argument of function usleep() too big. 2013-03-11 17:04:30 +01:00
PKEuS 8a18f9ec3b Rewrote CheckOther::checkVariableScope() 2013-03-03 10:35:33 -08:00
Alexander Mai 4ae65ea454 Fixed doxygen warnings 2013-02-27 21:05:18 +01:00
Ettl Martin 8d682233d0 Implemented new check (Ticket #160): Storing getc() retun value in char variable and comparing to EOF. 2013-02-27 21:02:12 +01:00
Ettl Martin 73e2a8fdb5 Merge branch 'master' of github.com:danmar/cppcheck 2013-02-17 17:34:44 +01:00
Ettl Martin f451dd1137 #3521 implemented new check: wrong buffersize to pipe() function provided. 2013-02-17 17:33:32 +01:00
PKEuS ccd95d1749 Make redundantAssignment message inconclusive when printed on global variables to avoid false warning on semaphores/mutexes (#4467) 2013-02-15 09:01:10 -08:00
Ettl Martin dade326a99 #4566 implemented new check: redundantGetAndSetUserId on posix systems 2013-02-11 20:26:27 +01:00
Andrew C. Martin bd0d9b9639 fix misspellings & gcc v3.4.6 warnings
1.  fix typos / misspellings
 - Fix misspelling within comments, variable/function names, stdout messages
 - changes the name of an error code: ```stlBoundries``` changed to ```stlBoundaries```.  Alias old name (```stlBoundries```) to the new one.

2.  fix gcc v3.4.6 32bit & 64bit warnings

 - fixes gcc v3.4.6 warnings, except for those in tinyxml and "-Wmissing-declarations" makefile warnings
 - in Preprocessor::handleIncludes(), replace a ```vector <bool>``` with ```stack<bool>``` (see ```vector<bool>``` warning below).
   - this is the only ```vector<bool>``` in the codebase
 - ```vector <bool>``` is actually a case of template specialization, and is not recommended, according to the following links:

http://stackoverflow.com/q/6461487
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2160.html
http://stackoverflow.com/q/670308

 - in the codebase before and after this change, testrunner SEGVs in a number of places on gcc v3.4.6, including ```Check::~Check()```, among others
   - fc42fc95 fixes this particular runtime issue for DJGPP & __sun
2013-02-09 23:43:09 -07:00
Daniel Marjamäki bc6d31c7c7 unsigned division: don't warn about 'unsigned char' because it is promoted to int. 2013-01-30 16:50:12 +01:00
Zachary Blair a1cbed3df8 Fixed #4109 (if (c == 1) c == 0; Isn't picked up) 2013-01-17 23:03:04 -08:00
Daniel Marjamäki 2e56928834 Fixed #4482 (add test for UB due to usage of NULL in variadic functions) 2013-01-13 12:02:10 +01:00
Reijo Tomperi 5d5f7085bf Updating year 2012 -> 2013 to .cpp and .h files and man page. 2013-01-01 18:29:08 +02:00
PKEuS 0ac4c3baf4 New check: Find suspicious case labels like 'case A||B:' 2012-12-07 12:27:32 -08:00
Daniel Marjamäki bf91454136 Fixed #4224 (False positive: Comparison of a boolean with an integer (neglecting a cast)) 2012-12-02 08:34:30 +01:00
PKEuS ce961578c2 New checks (inconclusive): Suspicious calculation with sizeof()
- Check for sizeof(ptr)/something: This indicates that programmer was trying to calculate array size, but sizeof(ptr) doesn't return the length of the memory area, but size of a pointer.
- Check for sizeof()*sizeof(): This indicates that programmer misunderstood what sizeof() does: It does return the length in bytes of the given variable, not e.g. the number of elements in an array.
2012-11-09 18:08:20 +01:00
Zachary Blair 51d128c918 Fixed #2029 (free invalid address) by reporting previously-unreported errors as "inconclusive" 2012-11-05 21:02:51 -08:00
Daniel Marjamäki e7483af028 Opposite inner conditions - made check 'experimental' because there are unsolved false positives. 2012-10-21 18:18:29 +02:00
Mohit Mate 9e297c95f2 Fixed #2617 (improve check: comparing boolean with '<') 2012-09-26 18:18:36 +02:00
XhmikosR 6e4e3dfbfb lib: tabs to spaces, remove trailing spaces and extra empty lines at the end of files 2012-09-17 13:51:23 +02:00
PKEuS 5237ed2de9 Message refactorization: checkother.cpp 2012-09-16 19:44:02 +02:00
PKEuS 9a624576f4 Revert "CheckOther::clarifyStatement: improved message to show what's the 'bad' and the 'good' expression."
This reverts commit f8591f9004.
2012-09-15 20:19:02 +02:00
Nilesh Kumar c7633fc73c Fixed #3645 2012-09-05 13:48:00 +02:00
Zachary Blair 8546bcc94e Fixed #2029 (new check: free invalid address) 2012-09-04 23:31:23 -07:00
Edoardo Prezioso f8591f9004 CheckOther::clarifyStatement: improved message to show what's the 'bad' and the 'good' expression. 2012-09-04 02:07:55 +02:00
PKEuS 2d64b69cf4 New check: Detect redundant assignment to a variable and redundant copying to a buffer
This check partially replaces the check for redundant assignments in switch
2012-09-02 13:09:32 +02:00
PKEuS 808c3468c9 New check: detect suspicious comparison of string literal with char* variable
Bugfix: Update Token type when varId is set
2012-08-24 14:25:17 +02:00