Skip to content

Commit 90c027f

Browse files
authored
Merge pull request #4532 from geoffw0/wrongtypeformaterr
C++: Harden queries against ErroneousType
2 parents 7544bc8 + 678e769 commit 90c027f

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* The `cpp/wrong-type-format-argument` and `cpp/non-portable-printf` queries have been hardened so that they do not produce nonsensical results on databases that contain errors (specifically the `ErroneousType`).

cpp/ql/src/Likely Bugs/Format/WrongTypeFormatArguments.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ where
155155
not actual.getUnspecifiedType().(IntegralType).getSize() = sizeof_IntType()
156156
) and
157157
not arg.isAffectedByMacro() and
158-
not arg.isFromUninstantiatedTemplate(_)
158+
not arg.isFromUninstantiatedTemplate(_) and
159+
not actual.getUnspecifiedType() instanceof ErroneousType
159160
select arg,
160161
"This argument should be of type '" + expected.getName() + "' but is of type '" +
161162
actual.getUnspecifiedType().getName() + "'"

cpp/ql/src/Likely Bugs/Memory Management/Padding/NonPortablePrintf.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ where
8888
not arg.isAffectedByMacro() and
8989
size32 = ilp32.paddedSize(actual) and
9090
size64 = lp64.paddedSize(actual) and
91-
size64 != size32
91+
size64 != size32 and
92+
not actual instanceof ErroneousType
9293
select arg,
9394
"This argument should be of type '" + expected.getName() + "' but is of type '" + actual.getName()
9495
+ "' (which changes size from " + size32 + " to " + size64 + " on 64-bit systems)."

0 commit comments

Comments
 (0)