C++: Prevent non-termination in 'getTypeImpl' when a iterator defines itself as 'value_type'.

This commit is contained in:
Mathias Vorreiter Pedersen
2022-12-14 12:33:17 +00:00
parent 526b913f7d
commit 73b93be313

View File

@@ -670,7 +670,15 @@ private Type getTypeImpl(Type t, int indirectionIndex) {
result = t
or
indirectionIndex > 0 and
result = getTypeImpl(stripPointer(t), indirectionIndex - 1)
exists(Type stripped |
stripped = stripPointer(t) and
// We need to avoid the case where `stripPointer(t) = t` (which can happen on
// iterators that specify a `value_type` that is the iterator itself). Such a type
// would create an infinite loop otherwise. For these cases we simply don't produce
// a result for `getType`.
stripped.getUnspecifiedType() != t.getUnspecifiedType() and
result = getTypeImpl(stripPointer(t), indirectionIndex - 1)
)
}
/**