Commit Graph

72 Commits

Author SHA1 Message Date
Tyson Nottingham d6a70d27c7 Fix false negatives in checkAssignBoolToFloat and minor related improvements (#2198)
* Fix false negatives in checkAssignBoolToFloat

Detect assignments to expressions involving pointer dereferences, array
element accesses, etc.

* Pass assignment token to assignBoolToFloatError

Pass assignment token rather than boolean token to make error reporting
consistent between checkAssignBoolToFloat and checkAssignBoolToPointer,
as well as with other assignment checks in the code base.

* Make checkAssignBoolToPointer check consistent with checkAssignBoolToFloat
2019-09-21 08:24:54 +02:00
Daniel Marjamäki 84cc09d17c Update Copyright 2019-06-29 07:49:14 +02:00
Carlo Marcelo Arenas Belón ec4e43767e minor improvements (#1929)
* lib: isNonBoolStdType no longer needed

lib/checkbool.cpp:50:13: warning: unused function 'isNonBoolStdType'
      [-Wunused-function]
static bool isNonBoolStdType(const Variable* var)

* cmake: C++11 is required

also change instructions to a more common syntax
2019-06-28 06:57:05 +02:00
Ken-Patrick 927d139488 Fix FP #9165 (#1928)
Properly check the type of the expressions, instead of using the type
of the tokens
2019-06-27 07:48:44 +02:00
Rikard Falkeborn dc0e8c214e Fix #9128 (FP in return non bool with class declared in function) (#1830)
Also break up the tests to smaller tests.
2019-05-14 08:56:28 +02:00
Rikard Falkeborn 4edc248dae Fix 8840: Don't warn when returning a bitmask as bool (#1818)
A common pattern is to have a function like similar to this:

	bool isFlagSet(uint32_t f) {
		return f & 0x4;
	}

Warning that the function returns a non-boolean in this case is too
noisy, it would be better suited for a Misra check, so remove the
warnings in the most obvious cases.
2019-05-02 07:00:27 +02:00
Daniel Marjamäki ac42382cd9 Rewrite CheckBool::checkAssignBoolToPointer to use ValueType 2019-03-09 19:15:06 +01:00
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