Skip to content

Commit 371b9b8

Browse files
committed
C#: Remove redundant ConstantComparison.ql query.
1 parent 1da3831 commit 371b9b8

File tree

14 files changed

+54
-145
lines changed

14 files changed

+54
-145
lines changed

csharp/ql/integration-tests/posix/query-suite/csharp-code-quality-extended.qls.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ ql/csharp/ql/src/Likely Bugs/Collections/ContainerLengthCmpOffByOne.ql
6565
ql/csharp/ql/src/Likely Bugs/Collections/ContainerSizeCmpZero.ql
6666
ql/csharp/ql/src/Likely Bugs/Collections/ReadOnlyContainer.ql
6767
ql/csharp/ql/src/Likely Bugs/Collections/WriteOnlyContainer.ql
68-
ql/csharp/ql/src/Likely Bugs/ConstantComparison.ql
6968
ql/csharp/ql/src/Likely Bugs/DangerousNonShortCircuitLogic.ql
7069
ql/csharp/ql/src/Likely Bugs/Dynamic/BadDynamicCall.ql
7170
ql/csharp/ql/src/Likely Bugs/EqualityCheckOnFloats.ql

csharp/ql/integration-tests/posix/query-suite/csharp-code-quality.qls.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ ql/csharp/ql/src/Likely Bugs/Collections/ContainerLengthCmpOffByOne.ql
3838
ql/csharp/ql/src/Likely Bugs/Collections/ContainerSizeCmpZero.ql
3939
ql/csharp/ql/src/Likely Bugs/Collections/ReadOnlyContainer.ql
4040
ql/csharp/ql/src/Likely Bugs/Collections/WriteOnlyContainer.ql
41-
ql/csharp/ql/src/Likely Bugs/ConstantComparison.ql
4241
ql/csharp/ql/src/Likely Bugs/DangerousNonShortCircuitLogic.ql
4342
ql/csharp/ql/src/Likely Bugs/EqualityCheckOnFloats.ql
4443
ql/csharp/ql/src/Likely Bugs/EqualsArray.ql

csharp/ql/integration-tests/posix/query-suite/csharp-security-and-quality.qls.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ ql/csharp/ql/src/Likely Bugs/Collections/ContainerLengthCmpOffByOne.ql
6969
ql/csharp/ql/src/Likely Bugs/Collections/ContainerSizeCmpZero.ql
7070
ql/csharp/ql/src/Likely Bugs/Collections/ReadOnlyContainer.ql
7171
ql/csharp/ql/src/Likely Bugs/Collections/WriteOnlyContainer.ql
72-
ql/csharp/ql/src/Likely Bugs/ConstantComparison.ql
7372
ql/csharp/ql/src/Likely Bugs/DangerousNonShortCircuitLogic.ql
7473
ql/csharp/ql/src/Likely Bugs/Dynamic/BadDynamicCall.ql
7574
ql/csharp/ql/src/Likely Bugs/EqualityCheckOnFloats.ql

csharp/ql/lib/semmle/code/csharp/commons/Constants.qll

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,6 @@ import csharp
44
private import semmle.code.csharp.commons.ComparisonTest
55
private import semmle.code.csharp.commons.StructuralComparison as StructuralComparison
66

7-
pragma[noinline]
8-
private predicate isConstantCondition0(ControlFlow::Node cfn, boolean b) {
9-
exists(cfn.getASuccessorByType(any(ControlFlow::BooleanSuccessor t | t.getValue() = b))) and
10-
strictcount(ControlFlow::SuccessorType t | exists(cfn.getASuccessorByType(t))) = 1
11-
}
12-
13-
/**
14-
* Holds if `e` is a condition that always evaluates to Boolean value `b`.
15-
*/
16-
predicate isConstantCondition(Expr e, boolean b) {
17-
forex(ControlFlow::Node cfn | cfn = e.getAControlFlowNode() | isConstantCondition0(cfn, b))
18-
}
19-
207
/**
218
* Holds if comparison operation `co` is constant with the Boolean value `b`.
229
* For example, the comparison `x > x` is constantly `false` in

csharp/ql/src/CSI/CompareIdenticalValues.ql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ where
4747
not comparesIdenticalValuesNan(ct, _) and msg = "Comparison of identical values."
4848
) and
4949
not isMutatingOperation(ct.getAnArgument().getAChild*()) and
50-
not isConstantCondition(e, _) and // Avoid overlap with cs/constant-condition
51-
not isConstantComparison(e, _) and // Avoid overlap with cs/constant-comparison
50+
not isConstantComparison(e, _) and // Avoid overlap with cs/constant-condition
5251
not isExprInAssertion(e)
5352
select ct, msg

csharp/ql/src/Likely Bugs/ConstantComparison.cs

Lines changed: 0 additions & 2 deletions
This file was deleted.

csharp/ql/src/Likely Bugs/ConstantComparison.qhelp

Lines changed: 0 additions & 46 deletions
This file was deleted.

csharp/ql/src/Likely Bugs/ConstantComparison.ql

Lines changed: 0 additions & 22 deletions
This file was deleted.

csharp/ql/src/codeql-suites/csharp-security-and-quality.qls

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
- cs/comparison-of-identical-expressions
2323
- cs/complex-block
2424
- cs/complex-condition
25-
- cs/constant-comparison
2625
- cs/constant-condition
2726
- cs/coupled-types
2827
- cs/dereferenced-value-is-always-null

csharp/ql/test/query-tests/Likely Bugs/ConstantComparison/ConstantComparison.cs renamed to csharp/ql/test/query-tests/Bad Practices/Control-Flow/ConstantCondition/ConstantComparison.cs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ void f()
1616
{
1717
bool good, bad;
1818

19-
bad = uintValue < 0;
20-
bad = 0 > uintValue;
21-
bad = 0 <= uintValue;
22-
bad = uintValue >= 0;
19+
bad = uintValue < 0; // $ Alert
20+
bad = 0 > uintValue; // $ Alert
21+
bad = 0 <= uintValue; // $ Alert
22+
bad = uintValue >= 0; // $ Alert
2323

24-
bad = uintValue == -1;
25-
bad = uintValue != -1;
26-
bad = 256 == byteValue;
27-
bad = 256 != byteValue;
28-
bad = 1 != 0;
24+
bad = uintValue == -1; // $ Alert
25+
bad = uintValue != -1; // $ Alert
26+
bad = 256 == byteValue; // $ Alert
27+
bad = 256 != byteValue; // $ Alert
28+
bad = 1 != 0; // $ Alert
2929

3030
good = byteValue == 50;
3131
good = 50 != byteValue;
@@ -35,61 +35,61 @@ void f()
3535
good = intValue <= 1u;
3636
good = 1u >= intValue;
3737

38-
good = charValue >= '0'; // Regression
38+
good = charValue >= '0';
3939
good = charValue < '0';
4040

4141
// Test ranges
42-
bad = charValue <= 65535;
43-
bad = charValue >= 0;
42+
bad = charValue <= 65535; // $ Alert
43+
bad = charValue >= 0; // $ Alert
4444

4545
good = charValue < 255;
4646
good = charValue > 0;
4747

48-
bad = byteValue >= byte.MinValue;
49-
bad = byteValue <= byte.MaxValue;
48+
bad = byteValue >= byte.MinValue; // $ Alert
49+
bad = byteValue <= byte.MaxValue; // $ Alert
5050

5151
good = byteValue > byte.MinValue;
5252
good = byteValue < byte.MaxValue;
5353

54-
bad = sbyteValue >= sbyte.MinValue;
55-
bad = sbyteValue <= sbyte.MaxValue;
54+
bad = sbyteValue >= sbyte.MinValue; // $ Alert
55+
bad = sbyteValue <= sbyte.MaxValue; // $ Alert
5656

5757
good = sbyteValue < sbyte.MaxValue;
5858
good = sbyteValue > sbyte.MinValue;
5959

60-
bad = shortValue >= short.MinValue;
61-
bad = shortValue <= short.MaxValue;
60+
bad = shortValue >= short.MinValue; // $ Alert
61+
bad = shortValue <= short.MaxValue; // $ Alert
6262

6363
good = shortValue > short.MinValue;
6464
good = shortValue < short.MaxValue;
6565

66-
bad = ushortValue >= ushort.MinValue;
67-
bad = ushortValue <= ushort.MaxValue;
66+
bad = ushortValue >= ushort.MinValue; // $ Alert
67+
bad = ushortValue <= ushort.MaxValue; // $ Alert
6868

6969
good = ushortValue > ushort.MinValue;
7070
good = ushortValue < ushort.MaxValue;
7171

72-
bad = intValue >= int.MinValue;
73-
bad = intValue <= int.MaxValue;
72+
bad = intValue >= int.MinValue; // $ Alert
73+
bad = intValue <= int.MaxValue; // $ Alert
7474

7575
good = intValue > int.MinValue;
7676
good = intValue < int.MaxValue;
7777

78-
bad = uintValue >= uint.MinValue;
78+
bad = uintValue >= uint.MinValue; // $ Alert
7979
good = uintValue > uint.MinValue;
8080

81-
bad = ulongValue >= ulong.MinValue;
81+
bad = ulongValue >= ulong.MinValue; // $ Alert
8282
good = ulongValue > ulong.MinValue;
8383

8484
// Explicit casts can cause large values to be truncated or
8585
// to wrap into negative values.
8686
good = (sbyte)byteValue >= 0;
8787
good = (sbyte)byteValue == -1;
88-
bad = (sbyte)byteValue > 127;
89-
bad = (sbyte)byteValue > (sbyte)127;
88+
bad = (sbyte)byteValue > 127; // $ Alert
89+
bad = (sbyte)byteValue > (sbyte)127; // $ Alert
9090
good = (int)uintValue == -1;
9191
good = (sbyte)uintValue == -1;
92-
bad = (sbyte)uintValue == 256;
92+
bad = (sbyte)uintValue == 256; // $ Alert
9393

9494
System.Diagnostics.Debug.Assert(ulongValue >= ulong.MinValue); // GOOD
9595
}

0 commit comments

Comments
 (0)