mirror of
https://github.com/github/codeql.git
synced 2026-05-01 19:55:15 +02:00
Merge pull request #6865 from MathiasVP/fix-if-none
C++/C#/JS/Python: Replace 'if p() then q() else none()' with a conjunction
This commit is contained in:
@@ -275,9 +275,8 @@ class Declaration extends Locatable, @declaration {
|
||||
* `getTemplateArgumentKind(0)`.
|
||||
*/
|
||||
final Locatable getTemplateArgumentKind(int index) {
|
||||
if exists(getTemplateArgumentValue(index))
|
||||
then result = getTemplateArgumentType(index)
|
||||
else none()
|
||||
exists(getTemplateArgumentValue(index)) and
|
||||
result = getTemplateArgumentType(index)
|
||||
}
|
||||
|
||||
/** Gets the number of template arguments for this declaration. */
|
||||
|
||||
@@ -344,14 +344,13 @@ private int convertIntToType(int val, IntegralType t) {
|
||||
then if val = 0 then result = 0 else result = 1
|
||||
else
|
||||
if t.isUnsigned()
|
||||
then if val >= 0 and val.bitShiftRight(t.getSize() * 8) = 0 then result = val else none()
|
||||
then val >= 0 and val.bitShiftRight(t.getSize() * 8) = 0 and result = val
|
||||
else
|
||||
if val >= 0 and val.bitShiftRight(t.getSize() * 8 - 1) = 0
|
||||
then result = val
|
||||
else
|
||||
if (-(val + 1)).bitShiftRight(t.getSize() * 8 - 1) = 0
|
||||
then result = val
|
||||
else none()
|
||||
else (
|
||||
(-(val + 1)).bitShiftRight(t.getSize() * 8 - 1) = 0 and result = val
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,10 +18,11 @@ Overlap getOverlap(IntValue defStart, IntValue defEnd, IntValue useStart, IntVal
|
||||
else
|
||||
if isLE(defStart, useStart) and isGE(defEnd, useEnd)
|
||||
then result instanceof MustTotallyOverlap
|
||||
else
|
||||
if isLE(defEnd, useStart) or isGE(defStart, useEnd)
|
||||
then none()
|
||||
else result instanceof MayPartiallyOverlap
|
||||
else (
|
||||
not isLE(defEnd, useStart) and
|
||||
not isGE(defStart, useEnd) and
|
||||
result instanceof MayPartiallyOverlap
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -365,7 +365,7 @@ class GetsBW extends BufferWriteCall {
|
||||
/**
|
||||
* Gets the index of the parameter that is the maximum number of characters to be read.
|
||||
*/
|
||||
int getParamSize() { if exists(getArgument(1)) then result = 1 else none() }
|
||||
int getParamSize() { exists(getArgument(1)) and result = 1 }
|
||||
|
||||
override Type getBufferType() { result = this.getTarget().getParameter(0).getUnspecifiedType() }
|
||||
|
||||
|
||||
@@ -50,10 +50,7 @@ where
|
||||
// If either of the operands is constant, then don't include it.
|
||||
(
|
||||
if cmp.getLeftOperand().isConstant()
|
||||
then
|
||||
if cmp.getRightOperand().isConstant()
|
||||
then none() // Both operands are constant so don't create a message.
|
||||
else reason = rightReason
|
||||
then not cmp.getRightOperand().isConstant() and reason = rightReason
|
||||
else
|
||||
if cmp.getRightOperand().isConstant()
|
||||
then reason = leftReason
|
||||
|
||||
@@ -121,16 +121,14 @@ predicate exprSourceType(Expr use, Type sourceType, Location sourceLoc) {
|
||||
else
|
||||
if use instanceof CrementOperation
|
||||
then exprSourceType(use.(CrementOperation).getOperand(), sourceType, sourceLoc)
|
||||
else
|
||||
else (
|
||||
// Conversions are not in the AST, so ignore them.
|
||||
if use instanceof Conversion
|
||||
then none()
|
||||
else (
|
||||
// Source expressions
|
||||
sourceType = use.getUnspecifiedType() and
|
||||
isPointerType(sourceType) and
|
||||
sourceLoc = use.getLocation()
|
||||
)
|
||||
not use instanceof Conversion and
|
||||
// Source expressions
|
||||
sourceType = use.getUnspecifiedType() and
|
||||
isPointerType(sourceType) and
|
||||
sourceLoc = use.getLocation()
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user