File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
lib/semmle/code/cpp/ir/dataflow/internal
test/library-tests/dataflow/dataflow-tests Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments