rikardfalkeborn
a3e717bea9
Use functions instead of comparing with enum ( #1471 )
...
* Use isComparisonOp() instead of enum
* Use isAssignmentOp() instead of enum
2018-11-09 06:30:41 +01:00
rikardfalkeborn
869e4ba6ab
Add check for return value of boolean function ( #1451 )
...
* Add check for return value of boolean function
The rule for converting an integer to a boolean is that 0 is mapped to
false and everything else is mapped to true. There is nothing wrong with
the following code (according to the standards):
bool f()
{
return -1;
}
and neither gcc nor clang will warn about it. However, it's a bit
confusing. This commit adds a check that warns when a value other than 0
or 1 is returned from a boolean function (similar to the existing check
that functions with boolean arguments are only passed 0 or 1). Since the
code is perfectly legal, set the severity to "Style".
* Use early continue and remove some braces
* Add testcase with multiple returns
* Avoid null pointer dereference in case of return without operand
* Skip lambdas
Add TODO-test cases that shows FPs when the return type of lambdas are
specified explicitly (this is a problem with findLambdaEndToken).
* Enable testcases
2018-11-01 11:08:16 +01:00
Daniel Marjamäki
2c90a83695
Refactoring; Use Token::isBinaryOp() to clarify code, use early continue in loop
2018-07-13 23:06:45 +02:00
Daniel Marjamäki
79ffe1d4fc
Rename _tokenizer, _settings, _errorLogger
2018-06-16 16:10:28 +02:00
Daniel Marjamäki
45379a3aa6
Updated copyright year for modified files
...
[ci skip]
2018-06-10 22:07:21 +02:00
Daniel Marjamäki
f336c2efe7
Refactoring; Renamed Scope::classStart and Scope::classEnd
2018-04-27 22:36:30 +02:00
Daniel Marjamäki
b0b08a3bb0
Refactoring: Use range for loop
2018-04-24 18:17:47 +02:00
Daniel Marjamäki
c6d834ae17
Refactoring: Use range for loops in CheckBool
2018-04-23 07:46:37 +02:00
Daniel Marjamäki
c4caee6b18
Updated copyright year
2018-01-14 15:37:52 +01:00
orbitcowboy
0e575ce12c
Modernize: make use of 'nullptr' and added a rule-file for finding non-nullptr (zero) initializations.
2017-07-28 15:20:43 +02:00
Ayaz Salikhov
28aa939d69
iwyu - include what you use
2017-05-27 04:33:47 +02:00
PKEuS
b1f4bd7504
Refactorization: Reimplemented Settings::_enabled as a bitfeld instead of std::set ( #7995 )
2017-04-11 11:49:26 +02:00
Daniel Marjamäki
ecc59859e1
Don't simplify _Bool in TokenList
2017-03-04 11:13:28 +01:00
Daniel Marjamäki
499e52c976
astyle formatting
...
[ci skip]
2016-08-15 18:04:55 +02:00
Roberto Martelloni
41dee04e90
CWE mapping of assignBoolToFloat, strncatUsage, sizeArgumentAsChar, terminateStrncpy, bufferNotZeroTerminated, negativeArraySize, noExplicitConstructor, virtualDestructor
2016-08-14 18:23:41 +01:00
Roberto Martelloni
d3645d874e
Mapped toomanyconfigs ,AssignmentAddressToInteger
...
,AssignmentIntegerToAddress ,CastIntegerToAddressAtReturn
,CastAddressToIntegerAtReturn ,assertWithSideEffect ,assignmentInAssert
,uselessAssignmentArg ,uselessAssignmentPtrArg
,comparisonOfFuncReturningBoolError
,comparisonOfTwoFuncsReturningBoolError ,comparisonOfBoolWithBoolError
,incrementboolean ,comparisonOfBoolWithInt ,compareBoolExpressionWithInt
,negativeIndex ,pointerOutOfBounds ,arrayIndexThenCheck
,possibleBufferAccessOutOfBounds ,argumentSize
,arrayIndexOutOfBoundsCond ,noConstructor ,copyCtorPointerCopying
,noCopyConstructor ,uninitMemberVar ,operatorEqVarError
,unusedPrivateFunction ,memsetClassFloat ,mallocOnClassWarning
,operatorEq ,thisSubtraction ,operatorEqRetRefThis ,operatorEqToSelf
,useInitializationList ,duplInheritedMember ,assignIfError
,comparisonError ,multiCondition ,mismatchingBitAnd
,oppositeInnerCondition ,incorrectLogicOperator ,redundantCondition
,moduloAlwaysTrueFalse to their CWEs ids.
2016-02-26 23:53:52 +00:00
Alexander Mai
5c2960713f
Correct false positives compareBoolExpressionWithInt (0U)
2016-02-19 21:38:54 +01:00
PKEuS
6215a48dc9
Support member variables in CheckBool::checkAssignBoolToFloat()
2016-02-05 20:28:42 +01:00
PKEuS
e71e9bd538
CheckBool: Rely on ValueType, removed a redundant check
2016-02-05 15:48:51 +01:00
Daniel Marjamäki
5e10e680da
CWE: refactoring. use constants instead of magic numbers.
2016-01-25 20:01:48 +01:00
Roberto Martelloni
bb6880919c
CWE mapping
2016-01-15 17:07:14 +01:00
Lauri Nurmi
996c9244d8
Update copyright year to 2007-2016.
2016-01-01 15:34:45 +02:00
Daniel Marjamäki
0f9d90d2be
Changed Copyrights. Removed my name.
2015-11-18 20:04:50 +01:00
PKEuS
7d624f2e21
Fixed crash on garbage code #7033
2015-10-09 13:06:52 +02:00
PKEuS
4d80df2f4a
Added pointer to Type to Token (similar to Token::Variable() and Token::function()):
...
- Accessible via Token::type()
- Renamed former Token::type() to Token::tokType()
- Removed SymbolDatabase::isClassOrStruct()
2015-08-15 11:19:21 +02:00
Daniel Marjamäki
88f59ad7e8
Partial fix for #6656 (Allow that CWE is mapped for error message)
2015-04-25 17:48:11 +02:00
Alexander Mai
9876cf2312
#6626 crash: Token::astOperand2() const ( do while ). Fix two segmentation faults on invalid code.
2015-04-06 17:23:48 +02:00
PKEuS
6e0302fd56
Refactorized CheckBool::checkComparisonOfBoolWithInt(), CheckBool::checkComparisonOfBoolExpressionWithInt() and CheckBool::pointerArithBool():
...
- Support more patterns in CheckBool::pointerArithBool()
- Use AST and SymbolDatabase
- Removed redundant skipping over template arguments
2015-03-12 20:07:48 +01:00
PKEuS
b2835051df
Refactorization: Renamed Token::Match pattern %var% to %name%, implement new pattern %var% which is true if varId > 0.
2015-01-31 12:32:04 +01:00
Thomas Jarosch
332254e0af
Make patterns compilable (mini refactoring)
2015-01-09 23:43:45 +01:00
Daniel Marjamäki
ff11ba9847
Updated copyright year to 2015
2015-01-03 12:14:58 +01:00
Dmitry-Me
cf3f8c2f38
Refactoring: Replace names with underscores with camelCase names
2014-12-01 16:22:56 +01:00
PKEuS
c1b0bfe4ee
Simplified code
2014-09-11 20:27:01 +02:00
Dmitry-Me
d72b98bbaa
Reduce code duplication, cleanup variable names
2014-08-25 11:49:17 +04:00
PKEuS
69b7f91034
Support :: in some more places
2014-08-19 11:36:32 +02:00
PKEuS
5d302716e7
Refactorized Variable::isIntegralType() and Variable::isFloatType():
...
- Cached property
- Make use of it in several checks
- float* is flagged as floating point type
2014-08-09 11:45:13 +02:00
Dmitry-Me
6e1568a6db
Simplify code - bail out early, vreak loops early, reorder checks and declarations.
2014-06-09 13:35:30 +04:00
PKEuS
d42275c5f1
Fixed TODO in checkAssignBoolToFloat
2014-05-24 20:06:45 +02:00
Alexander Mai
e6a394d514
CheckBool::checkAssignBoolToFloat() - don't crash on unknown variables
2014-05-24 19:15:43 +02:00
Alexander Mai
2c8087e34f
#4375 New check: add style warning about 'double d=false;' Add a new check to CheckBool. Also implement Variable::isFloatingType()
2014-05-24 18:35:49 +02:00
Daniel Marjamäki
225fb96554
Fixed #5627 (False positive assignBoolToPointer)
2014-03-31 15:55:54 +02:00
Daniel Marjamäki
581886636d
CheckBool::checkComparisonOfBoolExpressionWithInt: Rewrite the check using AST instead of token list
2014-03-27 16:10:43 +01:00
Daniel Marjamäki
2248cdfea0
CheckBool::checkAssignBoolToPointer: Refactor to use AST.
2014-03-27 05:39:48 +01:00
Daniel Marjamäki
23efc68dd7
use nullptr
2014-02-16 10:32:10 +01:00
Daniel Marjamäki
fd3a8a2a18
Update copyright
2014-02-15 07:45:39 +01:00
Daniel Marjamäki
aa65799c19
pointerArithBool: Updated error message
2013-12-25 19:56:00 +01:00
Daniel Marjamäki
a3dd65caee
Fixed #5126 (new check: missing pointer dereference or pointer overflow 'if (p+1)')
2013-12-23 18:39:05 +01:00
Daniel Marjamäki
5c072993e3
CheckBool: Fixed false negative when assigning bool to pointer '; s.p = true; '
2013-10-29 16:16:52 +01:00
Daniel Marjamäki
682e68b1b6
Fixed #5077 (False positive: Comparison of boolean result with relational operator ((X + (Y < 0)) <= b))
2013-10-09 05:43:50 +02:00
Daniel Marjamäki
f9cf148012
CheckBool: Skip 'bool' type checking in C code
2013-10-07 18:41:07 +02:00