forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructors.cpp
More file actions
51 lines (41 loc) · 767 Bytes
/
constructors.cpp
File metadata and controls
51 lines (41 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
namespace Constructors
{
int user_input()
{
return 42;
}
void sink(int x)
{
}
class Foo
{
int a_;
int b_;
public:
int a() { return a_; }
int b() { return b_; }
void setA(int a) { a_ = a; }
void setB(int b) { b_ = b; }
Foo(int a, int b) : a_(a), b_(b){};
};
void bar(Foo &f)
{
sink(f.a()); // $ ast=34:11 ast=36:11 ir=34:11 ir=36:11
sink(f.b()); // $ ast=35:14 ast=36:25 ir=35:14 ir=36:25
}
void foo()
{
Foo f(user_input(), 0);
Foo g(0, user_input());
Foo h(user_input(), user_input());
Foo i(0, 0);
// Only a() should alert
bar(f);
// Only b() should alert
bar(g);
// Both a() and b() should alert
bar(h);
// Nothing should alert
bar(i);
}
}; // namespace Constructors