Skip to content

Commit c19ed4c

Browse files
authored
Merge pull request github#15626 from MathiasVP/fix-constness-checking
C++: Don't strip specifiers away in `TFinalParameterUse`
2 parents a95f412 + 532e8da commit c19ed4c

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternals.qll

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ private newtype TDefOrUseImpl =
142142
exists(SsaInternals0::Def def |
143143
def.getSourceVariable().getBaseVariable().(BaseIRVariable).getIRVariable().getAst() = p and
144144
not def.getValue().asInstruction() instanceof InitializeParameterInstruction and
145-
unspecifiedTypeIsModifiableAt(p.getUnspecifiedType(), indirectionIndex)
145+
underlyingTypeIsModifiableAt(p.getUnderlyingType(), indirectionIndex)
146146
)
147147
}
148148

@@ -172,11 +172,13 @@ private predicate isGlobalDefImpl(
172172
)
173173
}
174174

175-
private predicate unspecifiedTypeIsModifiableAt(Type unspecified, int indirectionIndex) {
176-
indirectionIndex = [1 .. getIndirectionForUnspecifiedType(unspecified).getNumberOfIndirections()] and
175+
private predicate underlyingTypeIsModifiableAt(Type underlying, int indirectionIndex) {
176+
indirectionIndex =
177+
[1 .. getIndirectionForUnspecifiedType(underlying.getUnspecifiedType())
178+
.getNumberOfIndirections()] and
177179
exists(CppType cppType |
178-
cppType.hasUnspecifiedType(unspecified, _) and
179-
isModifiableAt(cppType, indirectionIndex + 1)
180+
cppType.hasUnderlyingType(underlying, false) and
181+
isModifiableAt(cppType, indirectionIndex)
180182
)
181183
}
182184

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternalsCommon.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ private module IsModifiableAtImpl {
452452
private predicate impl(CppType cppType, int indirectionIndex) {
453453
exists(Type pointerType, Type base |
454454
isUnderlyingIndirectionType(pointerType) and
455-
cppType.hasUnderlyingType(pointerType, _) and
455+
cppType.hasUnderlyingType(pointerType, false) and
456456
base = getTypeImpl(pointerType, indirectionIndex)
457457
|
458458
// The value cannot be modified if it has a const specifier,

0 commit comments

Comments
 (0)