Skip to content

Commit 16ba465

Browse files
committed
C++: Allocate an additional indirection for void pointers.
1 parent f6b9ca3 commit 16ba465

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,18 @@ private class PointerOrArrayOrReferenceType extends Cpp::DerivedType {
103103
* (i.e., `countIndirections(e.getUnspecifiedType())`).
104104
*/
105105
private int countIndirections(Type t) {
106-
result = any(Indirection ind | ind.getType() = t).getNumberOfIndirections()
107-
or
108-
not exists(Indirection ind | ind.getType() = t) and
109-
result = 0
106+
// We special case void pointers because we don't know how many indirections
107+
// they really have. In a Glorious Future we could do a pre-analysis to figure out
108+
// which kinds of values flows into the type and use the maximum number of
109+
// indirections flowinginto the type.
110+
if t instanceof Cpp::VoidPointerType
111+
then result = 2
112+
else (
113+
result = any(Indirection ind | ind.getType() = t).getNumberOfIndirections()
114+
or
115+
not exists(Indirection ind | ind.getType() = t) and
116+
result = 0
117+
)
110118
}
111119

112120
/**

0 commit comments

Comments
 (0)