mirror of
https://github.com/github/codeql.git
synced 2026-05-04 13:15:21 +02:00
Add extra test cases
This commit is contained in:
committed by
Jonas Jensen
parent
835e495e7c
commit
79d75d7d18
51
cpp/ql/test/library-tests/dataflow/fields/constructors.cpp
Normal file
51
cpp/ql/test/library-tests/dataflow/fields/constructors.cpp
Normal file
@@ -0,0 +1,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());
|
||||
sink(f.b());
|
||||
}
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user