Skip to content

Commit 69ee615

Browse files
authored
Merge pull request github#13515 from MathiasVP/dataflow-fix-for-self-iterators
C++: Dataflow fix for the self-iterators issue
2 parents ca71d48 + 2b0282c commit 69ee615

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ private int countIndirections(Type t) {
117117
else (
118118
result = any(Indirection ind | ind.getType() = t).getNumberOfIndirections()
119119
or
120+
// If there is an indirection for the type, but we cannot count the number of indirections
121+
// it means we couldn't reach a non-indirection type by stripping off indirections. This
122+
// can occur if an iterator specifies itself as the value type. In this case we default to
123+
// 1 indirection fore the type.
124+
exists(Indirection ind |
125+
ind.getType() = t and
126+
not exists(ind.getNumberOfIndirections()) and
127+
result = 1
128+
)
129+
or
120130
not exists(Indirection ind | ind.getType() = t) and
121131
result = 0
122132
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "../../../include/iterator.h"
2+
int source();
3+
4+
template<typename T>
5+
void sink(T);
6+
7+
template<> struct std::iterator_traits<unsigned long>
8+
{ // get traits from integer type
9+
typedef std::input_iterator_tag iterator_category;
10+
typedef unsigned long value_type;
11+
typedef unsigned long difference_type;
12+
typedef unsigned long distance_type;
13+
typedef unsigned long * pointer;
14+
typedef unsigned long& reference;
15+
};
16+
17+
18+
int test() {
19+
unsigned long x = source();
20+
sink(x); // $ ast ir
21+
}

0 commit comments

Comments
 (0)