Merge pull request #20326 from michaelnebel/csharp/ql4ql

C#: Fix some Ql4Ql violations.
This commit is contained in:
Michael Nebel
2025-09-02 11:44:22 +02:00
committed by GitHub
13 changed files with 30 additions and 28 deletions

View File

@@ -18,8 +18,8 @@ external string selectedSourceFile();
class PrintAstConfigurationOverride extends PrintAstConfiguration {
/**
* Holds if the location matches the selected file in the VS Code extension and
* the element is `fromSource`.
* Holds if the location `l` matches the selected file in the VS Code extension and
* the element is `e` is `fromSource`.
*/
override predicate shouldPrint(Element e, Location l) {
super.shouldPrint(e, l) and

View File

@@ -583,7 +583,7 @@ module AssignableDefinitions {
}
/**
* Holds if the `ref` assignment to `aa` via call `c` is uncertain.
* Holds if the `ref` assignment to `arg` via call `c` is uncertain.
*/
// Not in the cached module `Cached`, as that would introduce a dependency
// on the CFG construction, and effectively collapse too many stages into one

View File

@@ -708,7 +708,7 @@ class TrueOperator extends UnaryOperator {
*
* Either an addition operator (`AddOperator`), a checked addition operator
* (`CheckedAddOperator`) a subtraction operator (`SubOperator`), a checked
* substraction operator (`CheckedSubOperator`), a multiplication operator
* subtraction operator (`CheckedSubOperator`), a multiplication operator
* (`MulOperator`), a checked multiplication operator (`CheckedMulOperator`),
* a division operator (`DivOperator`), a checked division operator
* (`CheckedDivOperator`), a remainder operator (`RemOperator`), an and

View File

@@ -491,7 +491,7 @@ class Parameterizable extends Declaration, @parameterizable {
final Parameter getARawParameter() { result = this.getRawParameter(_) }
/**
* Gets the type of the parameter, possibly prefixed
* Gets the type of the `i`th parameter, possibly prefixed
* with `out`, `ref`, or `params`, where appropriate.
*/
private string parameterTypeToString(int i) {

View File

@@ -523,11 +523,9 @@ final class AttributeNode extends ElementNode {
* A node representing a `TypeParameter`.
*/
final class TypeParameterNode extends ElementNode {
TypeParameter typeParameter;
TypeParameterNode() {
typeParameter = element and
not isNotNeeded(typeParameter.getDeclaringGeneric())
element =
any(TypeParameter typeParameter | not isNotNeeded(typeParameter.getDeclaringGeneric()))
}
override ElementNode getChild(int childIndex) { none() }

View File

@@ -310,10 +310,8 @@ private class Overflowable extends UnaryOperation {
/** A control flow element that is inside a `try` block. */
private class TriedControlFlowElement extends ControlFlowElement {
TryStmt try;
TriedControlFlowElement() {
this = try.getATriedElement() and
this = any(TryStmt try).getATriedElement() and
not this instanceof NonReturningCall
}

View File

@@ -451,10 +451,9 @@ module Ssa {
* An SSA definition that corresponds to an explicit assignable definition.
*/
class ExplicitDefinition extends Definition, SsaImpl::WriteDefinition {
SourceVariable sv;
AssignableDefinition ad;
ExplicitDefinition() { SsaImpl::explicitDefinition(this, sv, ad) }
ExplicitDefinition() { SsaImpl::explicitDefinition(this, _, ad) }
/**
* Gets an underlying assignable definition. The result is always unique,

View File

@@ -143,7 +143,7 @@ private module SourceVariableImpl {
}
/**
* Gets an `out`/`ref` definition of the same source variable as the `out`/`ref`
* Gets an `out`/`ref` definition of the same source variable `v` as the `out`/`ref`
* definition `def`, belonging to the same call, at a position after `def`.
*/
OutRefDefinition getASameOutRefDefAfter(Ssa::SourceVariable v, OutRefDefinition def) {

View File

@@ -874,7 +874,7 @@ private predicate isStrongTypeFsPicklerCall(MethodCall mc, Method m) {
(
m instanceof FsPicklerSerializerClassDeserializeMethod or
m instanceof FsPicklerSerializerClassDeserializeSequenceMethod or
m instanceof FsPicklerSerializerClasDeserializeSiftedMethod or
m instanceof FsPicklerSerializerClassDeserializeSiftedMethod or
m instanceof FsPicklerSerializerClassUnPickleMethod or
m instanceof FsPicklerSerializerClassUnPickleSiftedMethod or
m instanceof CsPicklerSerializerClassDeserializeMethod or

View File

@@ -560,9 +560,15 @@ class FsPicklerSerializerClassDeserializeSequenceMethod extends Method, UnsafeDe
}
}
/**
* DEPRECATED: Use `FsPicklerSerializerClassDeserializeSiftedMethod` instead.
*/
deprecated class FsPicklerSerializerClasDeserializeSiftedMethod =
FsPicklerSerializerClassDeserializeSiftedMethod;
/** `MBrace.FsPickler.FsPicklerSerializer.DeserializeSifted` method */
class FsPicklerSerializerClasDeserializeSiftedMethod extends Method, UnsafeDeserializer {
FsPicklerSerializerClasDeserializeSiftedMethod() {
class FsPicklerSerializerClassDeserializeSiftedMethod extends Method, UnsafeDeserializer {
FsPicklerSerializerClassDeserializeSiftedMethod() {
this.getDeclaringType().getBaseClass*() instanceof FsPicklerSerializerClass and
this.hasUndecoratedName("DeserializeSifted")
}

View File

@@ -113,7 +113,7 @@ private predicate valueOccurrenceCount(string value, int n) {
n > 20
}
private predicate occurenceCount(Literal lit, string value, int n) {
private predicate occurrenceCount(Literal lit, string value, int n) {
valueOccurrenceCount(value, n) and
value = lit.getValue() and
relevantLiteral(lit, value)
@@ -127,7 +127,7 @@ private predicate check(Literal lit, string value, int n, File f) {
// Check that the literal is nontrivial
not trivial(lit) and
// Check that it is repeated a number of times
occurenceCount(lit, value, n) and
occurrenceCount(lit, value, n) and
n > 20 and
f = lit.getFile()
}

View File

@@ -75,15 +75,16 @@ private class ConstructorCall extends Call {
/** An explicit upcast. */
class ExplicitUpcast extends ExplicitCast {
ValueOrRefType src;
ValueOrRefType dest;
ExplicitUpcast() {
src = this.getSourceType() and
dest = this.getTargetType() and
(src instanceof RefType or src instanceof Struct) and
src.isImplicitlyConvertibleTo(dest) and
src != dest // Handled by `cs/useless-cast-to-self`
exists(ValueOrRefType src |
src = this.getSourceType() and
dest = this.getTargetType() and
(src instanceof RefType or src instanceof Struct) and
src.isImplicitlyConvertibleTo(dest) and
src != dest // Handled by `cs/useless-cast-to-self`
)
}
pragma[nomagic]

View File

@@ -12,7 +12,7 @@ module CallTargetStats implements StatsSig {
private predicate isNoSetterPropertyCallInConstructor(PropertyCall c) {
exists(Property p, Constructor ctor |
p = c.getProperty() and
not exists(Setter a | a = p.getAnAccessor()) and
not p.getAnAccessor() instanceof Setter and
c.getEnclosingCallable() = ctor and
(
c.hasThisQualifier()
@@ -25,7 +25,7 @@ module CallTargetStats implements StatsSig {
private predicate isNoSetterPropertyInitialization(PropertyCall c) {
exists(Property p, AssignExpr assign |
p = c.getProperty() and
not exists(Setter a | a = p.getAnAccessor()) and
not p.getAnAccessor() instanceof Setter and
assign = c.getParent() and
assign.getLValue() = c and
assign.getParent() instanceof Property