remove redundant cast where the type is enforced by an equality comparison

This commit is contained in:
Erik Krogh Kristensen
2021-10-28 18:08:20 +02:00
parent e75448ebb0
commit 15c90adec5
19 changed files with 26 additions and 30 deletions

View File

@@ -31,7 +31,7 @@ class Expr extends StmtParent, @expr {
override Stmt getEnclosingStmt() {
result = this.getParent().(Expr).getEnclosingStmt()
or
result = this.getParent().(Stmt)
result = this.getParent()
or
exists(Expr other | result = other.getEnclosingStmt() and other.getConversion() = this)
or

View File

@@ -63,14 +63,14 @@ predicate cannotContainString(Type t) {
predicate isNonConst(DataFlow::Node node) {
exists(Expr e | e = node.asExpr() |
exists(FunctionCall fc | fc = e.(FunctionCall) |
exists(FunctionCall fc | fc = e |
not (
whitelistFunction(fc.getTarget(), _) or
fc.getTarget().hasDefinition()
)
)
or
exists(Parameter p | p = e.(VariableAccess).getTarget().(Parameter) |
exists(Parameter p | p = e.(VariableAccess).getTarget() |
p.getFunction().getName() = "main" and p.getType() instanceof PointerType
)
or

View File

@@ -10,7 +10,7 @@ import semmle.code.cpp.commons.DateTime
* Get the top-level `BinaryOperation` enclosing the expression e.
*/
private BinaryOperation getATopLevelBinaryOperationExpression(Expr e) {
result = e.getEnclosingElement().(BinaryOperation)
result = e.getEnclosingElement()
or
result = getATopLevelBinaryOperationExpression(e.getEnclosingElement())
}

View File

@@ -15,7 +15,7 @@ import cpp
from File f, float complexity, float loc
where
f.fromSource() and
loc = sum(FunctionDeclarationEntry fde | fde.getFile() = f | fde.getNumberOfLines()).(float) and
loc = sum(FunctionDeclarationEntry fde | fde.getFile() = f | fde.getNumberOfLines()) and
if loc > 0
then
// Weighted average of complexity by function length

View File

@@ -26,7 +26,7 @@ import cpp
from Assignment a, Variable global, Variable local
where
a.fromSource() and
global.getAnAccess() = a.getLValue().(VariableAccess) and
global.getAnAccess() = a.getLValue() and
local.getAnAccess() = a.getRValue().(AddressOfExpr).getOperand() and
local.hasSpecifier("auto") and
(

View File

@@ -49,11 +49,11 @@ class ExposingIntegralUnion extends Union {
exists(MemberVariable mv1, MemberVariable mv2, IntegralType mv1tp, IntegralType mv2tp |
mv1 = this.getAMemberVariable() and
mv2 = this.getAMemberVariable() and
mv1tp = mv1.getUnderlyingType().(IntegralType) and
mv1tp = mv1.getUnderlyingType() and
(
mv2tp = mv2.getUnderlyingType().(IntegralType)
mv2tp = mv2.getUnderlyingType()
or
mv2tp = mv2.getUnderlyingType().(ArrayType).getBaseType().getUnderlyingType().(IntegralType)
mv2tp = mv2.getUnderlyingType().(ArrayType).getBaseType().getUnderlyingType()
) and
mv1tp.getSize() > mv2tp.getSize()
)