Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b249777

Browse files
committed
C++: Respond to review comments.
1 parent 5e1f36e commit b249777

2 files changed

Lines changed: 30 additions & 30 deletions

File tree

cpp/ql/src/Likely Bugs/OO/UnsafeUseOfThis.ql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ predicate isSource(InitializeParameterInstruction init, string msg, Class c) {
9898
* Holds if `instr` flows to a sink (which is a use of the value of `instr` as a `this` pointer
9999
* of type `sinkClass`).
100100
*/
101-
predicate flowsToSink(Instruction instr, Instruction sink, Class sinkClass) {
101+
predicate flowsToSink(Instruction instr, Instruction sink) {
102102
flowsFromSource(instr) and
103103
(
104-
isSink(instr, _, sinkClass) and instr = sink
104+
isSink(instr, _, _) and instr = sink
105105
or
106106
exists(Instruction mid |
107107
successor(instr, mid) and
108-
flowsToSink(mid, sink, sinkClass)
108+
flowsToSink(mid, sink)
109109
)
110110
)
111111
}
@@ -193,14 +193,14 @@ predicate flows(
193193
Class sinkClass
194194
) {
195195
isSource(source, msg, sourceClass) and
196-
flowsToSink(source, sink, sinkClass) and
196+
flowsToSink(source, sink) and
197197
isSink(sink, call, sinkClass)
198198
}
199199

200-
query predicate edges(Instruction a, Instruction b) { successor(a, b) and flowsToSink(b, _, _) }
200+
query predicate edges(Instruction a, Instruction b) { successor(a, b) and flowsToSink(b, _) }
201201

202202
query predicate nodes(Instruction n, string key, string val) {
203-
flowsToSink(n, _, _) and
203+
flowsToSink(n, _) and
204204
key = "semmle.label" and
205205
val = n.toString()
206206
}

cpp/ql/test/query-tests/Critical/UnsafeUseOfThis/test.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,47 @@ struct B;
44
void call_f(B*);
55

66
struct B : public A {
7-
B() {
8-
call_f(this);
9-
}
7+
B() {
8+
call_f(this);
9+
}
1010

11-
B(B& b) {
12-
b.f(); // BAD: undefined behavior
13-
}
11+
B(B& b) {
12+
b.f(); // BAD: undefined behavior
13+
}
1414

15-
~B() {
16-
f(); // BAD: undefined behavior
17-
}
15+
~B() {
16+
f(); // BAD: undefined behavior
17+
}
1818
};
1919

2020
struct C : public B {
21-
C(bool b) {
22-
call_f(this);
21+
C(bool b) {
22+
call_f(this);
2323

24-
if(b) {
25-
this->f(); // GOOD: Not a 'must' flow
26-
}
27-
}
24+
if(b) {
25+
this->f(); // GOOD: Not a 'must' flow
26+
}
27+
}
2828
};
2929

3030
struct D : public B {
31-
D() : B(*this) {}
31+
D() : B(*this) {}
3232
};
3333

3434
void call_f(B* x) {
35-
x->f(); // 2 x BAD: Undefined behavior
35+
x->f(); // 2 x BAD: Undefined behavior
3636
}
3737

3838
struct E : public A {
39-
E() {
40-
f(); // GOOD: Will call `E::f`
41-
}
39+
E() {
40+
f(); // GOOD: Will call `E::f`
41+
}
4242

43-
void f() override {}
43+
void f() override {}
4444
};
4545

4646
struct F : public E {
47-
F() {
48-
((A*)this)->f(); // BAD: undefined behavior
49-
}
47+
F() {
48+
((A*)this)->f(); // BAD: undefined behavior
49+
}
5050
};

0 commit comments

Comments
 (0)