Skip to content

Commit e94dbe9

Browse files
committed
C++: Add forgotten toString override
This makes `PostConstructorCallNode`s show up in the test output.
1 parent 38ec693 commit e94dbe9

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowUtil.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,20 @@ class PartialDefinitionNode extends PostUpdateNode, TPartialDefinitionNode {
242242
override string toString() { result = getPreUpdateNode().toString() + " [post update]" }
243243
}
244244

245+
/**
246+
* A node representing the object that was just constructed and is identified
247+
* with the "return value" of the constructor call.
248+
*/
245249
private class PostConstructorCallNode extends PostUpdateNode, TExprNode {
246250
PostConstructorCallNode() { this = TExprNode(any(ConstructorCall c)) }
247251

248252
override PreConstructorCallNode getPreUpdateNode() {
249253
TExprNode(result.getConstructorCall()) = this
250254
}
255+
256+
override string toString() {
257+
result = getPreUpdateNode().getConstructorCall().toString() + " [post constructor]"
258+
}
251259
}
252260

253261
/**
@@ -257,8 +265,6 @@ private class PostConstructorCallNode extends PostUpdateNode, TExprNode {
257265
* `this`-argument) to a constructor call.
258266
*/
259267
class PreConstructorCallNode extends Node, TPreConstructorCallNode {
260-
PreConstructorCallNode() { this = TPreConstructorCallNode(_) }
261-
262268
ConstructorCall getConstructorCall() { this = TPreConstructorCallNode(result) }
263269

264270
override Function getFunction() { result = getConstructorCall().getEnclosingFunction() }

cpp/ql/test/library-tests/dataflow/fields/flow.expected

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ edges
88
| A.cpp:55:12:55:19 | new [void] | A.cpp:55:5:55:5 | b [post update] [c, ... (1)] |
99
| A.cpp:56:10:56:10 | b [c, ... (1)] | A.cpp:56:13:56:15 | call to get |
1010
| A.cpp:57:11:57:24 | call to B [c, ... (1)] | A.cpp:57:11:57:24 | new [c, ... (1)] |
11+
| A.cpp:57:11:57:24 | call to B [post constructor] [c, ... (1)] | A.cpp:57:11:57:24 | new [c, ... (1)] |
1112
| A.cpp:57:11:57:24 | new [c, ... (1)] | A.cpp:57:28:57:30 | call to get |
1213
| A.cpp:57:17:57:23 | new [void] | A.cpp:57:11:57:24 | call to B [c, ... (1)] |
14+
| A.cpp:57:17:57:23 | new [void] | A.cpp:57:11:57:24 | call to B [post constructor] [c, ... (1)] |
1315
| A.cpp:64:10:64:15 | call to setOnB [c, ... (1)] | A.cpp:66:10:66:11 | b2 [c, ... (1)] |
1416
| A.cpp:64:21:64:28 | new [void] | A.cpp:64:10:64:15 | call to setOnB [c, ... (1)] |
1517
| A.cpp:66:10:66:11 | b2 [c, ... (1)] | A.cpp:66:14:66:14 | c |
@@ -28,25 +30,37 @@ edges
2830
| A.cpp:142:7:142:20 | ... = ... [void] | A.cpp:142:7:142:7 | b [post update] [c, ... (1)] |
2931
| A.cpp:142:14:142:20 | new [void] | A.cpp:142:7:142:20 | ... = ... [void] |
3032
| A.cpp:143:7:143:10 | this [post update] [b, ... (1)] | A.cpp:151:12:151:24 | call to D [b, ... (1)] |
33+
| A.cpp:143:7:143:10 | this [post update] [b, ... (1)] | A.cpp:151:12:151:24 | call to D [post constructor] [b, ... (1)] |
3134
| A.cpp:143:7:143:10 | this [post update] [b, ... (2)] | A.cpp:151:12:151:24 | call to D [b, ... (2)] |
35+
| A.cpp:143:7:143:10 | this [post update] [b, ... (2)] | A.cpp:151:12:151:24 | call to D [post constructor] [b, ... (2)] |
3236
| A.cpp:143:7:143:31 | ... = ... [c, ... (1)] | A.cpp:143:7:143:10 | this [post update] [b, ... (2)] |
3337
| A.cpp:143:7:143:31 | ... = ... [void] | A.cpp:143:7:143:10 | this [post update] [b, ... (1)] |
3438
| A.cpp:143:25:143:31 | new [void] | A.cpp:143:7:143:31 | ... = ... [void] |
3539
| A.cpp:150:12:150:18 | new [void] | A.cpp:151:18:151:18 | b [void] |
3640
| A.cpp:151:12:151:24 | call to D [b, ... (1)] | A.cpp:152:10:152:10 | d [b, ... (1)] |
3741
| A.cpp:151:12:151:24 | call to D [b, ... (2)] | A.cpp:153:10:153:10 | d [b, ... (2)] |
42+
| A.cpp:151:12:151:24 | call to D [post constructor] [b, ... (1)] | A.cpp:152:10:152:10 | d [b, ... (1)] |
43+
| A.cpp:151:12:151:24 | call to D [post constructor] [b, ... (2)] | A.cpp:153:10:153:10 | d [b, ... (2)] |
3844
| A.cpp:151:18:151:18 | b [void] | A.cpp:151:12:151:24 | call to D [b, ... (1)] |
45+
| A.cpp:151:18:151:18 | b [void] | A.cpp:151:12:151:24 | call to D [post constructor] [b, ... (1)] |
3946
| A.cpp:152:10:152:10 | d [b, ... (1)] | A.cpp:152:13:152:13 | b |
4047
| A.cpp:153:10:153:10 | d [b, ... (2)] | A.cpp:153:13:153:13 | b [c, ... (1)] |
4148
| A.cpp:153:13:153:13 | b [c, ... (1)] | A.cpp:153:16:153:16 | c |
4249
| A.cpp:159:12:159:18 | new [void] | A.cpp:160:29:160:29 | b [void] |
4350
| A.cpp:160:18:160:60 | call to MyList [head, ... (1)] | A.cpp:161:38:161:39 | l1 [head, ... (1)] |
51+
| A.cpp:160:18:160:60 | call to MyList [post constructor] [head, ... (1)] | A.cpp:161:38:161:39 | l1 [head, ... (1)] |
4452
| A.cpp:160:29:160:29 | b [void] | A.cpp:160:18:160:60 | call to MyList [head, ... (1)] |
53+
| A.cpp:160:29:160:29 | b [void] | A.cpp:160:18:160:60 | call to MyList [post constructor] [head, ... (1)] |
4554
| A.cpp:161:18:161:40 | call to MyList [next, ... (2)] | A.cpp:162:38:162:39 | l2 [next, ... (2)] |
55+
| A.cpp:161:18:161:40 | call to MyList [post constructor] [next, ... (2)] | A.cpp:162:38:162:39 | l2 [next, ... (2)] |
4656
| A.cpp:161:38:161:39 | l1 [head, ... (1)] | A.cpp:161:18:161:40 | call to MyList [next, ... (2)] |
57+
| A.cpp:161:38:161:39 | l1 [head, ... (1)] | A.cpp:161:18:161:40 | call to MyList [post constructor] [next, ... (2)] |
4758
| A.cpp:162:18:162:40 | call to MyList [next, ... (3)] | A.cpp:165:10:165:11 | l3 [next, ... (3)] |
4859
| A.cpp:162:18:162:40 | call to MyList [next, ... (3)] | A.cpp:167:44:167:44 | l [next, ... (3)] |
60+
| A.cpp:162:18:162:40 | call to MyList [post constructor] [next, ... (3)] | A.cpp:165:10:165:11 | l3 [next, ... (3)] |
61+
| A.cpp:162:18:162:40 | call to MyList [post constructor] [next, ... (3)] | A.cpp:167:44:167:44 | l [next, ... (3)] |
4962
| A.cpp:162:38:162:39 | l2 [next, ... (2)] | A.cpp:162:18:162:40 | call to MyList [next, ... (3)] |
63+
| A.cpp:162:38:162:39 | l2 [next, ... (2)] | A.cpp:162:18:162:40 | call to MyList [post constructor] [next, ... (3)] |
5064
| A.cpp:165:10:165:11 | l3 [next, ... (3)] | A.cpp:165:14:165:17 | next [next, ... (2)] |
5165
| A.cpp:165:14:165:17 | next [next, ... (2)] | A.cpp:165:20:165:23 | next [head, ... (1)] |
5266
| A.cpp:165:20:165:23 | next [head, ... (1)] | A.cpp:165:26:165:29 | head |
@@ -57,26 +71,38 @@ edges
5771
| A.cpp:169:12:169:12 | l [head, ... (1)] | A.cpp:169:15:169:18 | head |
5872
| B.cpp:6:15:6:24 | new [void] | B.cpp:7:25:7:25 | e [void] |
5973
| B.cpp:7:16:7:35 | call to Box1 [elem1, ... (1)] | B.cpp:8:25:8:26 | b1 [elem1, ... (1)] |
74+
| B.cpp:7:16:7:35 | call to Box1 [post constructor] [elem1, ... (1)] | B.cpp:8:25:8:26 | b1 [elem1, ... (1)] |
6075
| B.cpp:7:25:7:25 | e [void] | B.cpp:7:16:7:35 | call to Box1 [elem1, ... (1)] |
76+
| B.cpp:7:25:7:25 | e [void] | B.cpp:7:16:7:35 | call to Box1 [post constructor] [elem1, ... (1)] |
6177
| B.cpp:8:16:8:27 | call to Box2 [box1, ... (2)] | B.cpp:9:10:9:11 | b2 [box1, ... (2)] |
6278
| B.cpp:8:16:8:27 | call to Box2 [box1, ... (2)] | B.cpp:10:10:10:11 | b2 [box1, ... (2)] |
79+
| B.cpp:8:16:8:27 | call to Box2 [post constructor] [box1, ... (2)] | B.cpp:9:10:9:11 | b2 [box1, ... (2)] |
80+
| B.cpp:8:16:8:27 | call to Box2 [post constructor] [box1, ... (2)] | B.cpp:10:10:10:11 | b2 [box1, ... (2)] |
6381
| B.cpp:8:25:8:26 | b1 [elem1, ... (1)] | B.cpp:8:16:8:27 | call to Box2 [box1, ... (2)] |
82+
| B.cpp:8:25:8:26 | b1 [elem1, ... (1)] | B.cpp:8:16:8:27 | call to Box2 [post constructor] [box1, ... (2)] |
6483
| B.cpp:9:10:9:11 | b2 [box1, ... (2)] | B.cpp:9:14:9:17 | box1 [elem1, ... (1)] |
6584
| B.cpp:9:14:9:17 | box1 [elem1, ... (1)] | B.cpp:9:20:9:24 | elem1 |
6685
| B.cpp:10:10:10:11 | b2 [box1, ... (2)] | B.cpp:10:14:10:17 | box1 [elem2, ... (1)] |
6786
| B.cpp:10:14:10:17 | box1 [elem2, ... (1)] | B.cpp:10:20:10:24 | elem2 |
6887
| B.cpp:15:15:15:27 | new [void] | B.cpp:16:37:16:37 | e [void] |
6988
| B.cpp:16:16:16:38 | call to Box1 [elem2, ... (1)] | B.cpp:17:25:17:26 | b1 [elem2, ... (1)] |
89+
| B.cpp:16:16:16:38 | call to Box1 [post constructor] [elem2, ... (1)] | B.cpp:17:25:17:26 | b1 [elem2, ... (1)] |
7090
| B.cpp:16:37:16:37 | e [void] | B.cpp:16:16:16:38 | call to Box1 [elem2, ... (1)] |
91+
| B.cpp:16:37:16:37 | e [void] | B.cpp:16:16:16:38 | call to Box1 [post constructor] [elem2, ... (1)] |
7192
| B.cpp:17:16:17:27 | call to Box2 [box1, ... (2)] | B.cpp:18:10:18:11 | b2 [box1, ... (2)] |
7293
| B.cpp:17:16:17:27 | call to Box2 [box1, ... (2)] | B.cpp:19:10:19:11 | b2 [box1, ... (2)] |
94+
| B.cpp:17:16:17:27 | call to Box2 [post constructor] [box1, ... (2)] | B.cpp:18:10:18:11 | b2 [box1, ... (2)] |
95+
| B.cpp:17:16:17:27 | call to Box2 [post constructor] [box1, ... (2)] | B.cpp:19:10:19:11 | b2 [box1, ... (2)] |
7396
| B.cpp:17:25:17:26 | b1 [elem2, ... (1)] | B.cpp:17:16:17:27 | call to Box2 [box1, ... (2)] |
97+
| B.cpp:17:25:17:26 | b1 [elem2, ... (1)] | B.cpp:17:16:17:27 | call to Box2 [post constructor] [box1, ... (2)] |
7498
| B.cpp:18:10:18:11 | b2 [box1, ... (2)] | B.cpp:18:14:18:17 | box1 [elem1, ... (1)] |
7599
| B.cpp:18:14:18:17 | box1 [elem1, ... (1)] | B.cpp:18:20:18:24 | elem1 |
76100
| B.cpp:19:10:19:11 | b2 [box1, ... (2)] | B.cpp:19:14:19:17 | box1 [elem2, ... (1)] |
77101
| B.cpp:19:14:19:17 | box1 [elem2, ... (1)] | B.cpp:19:20:19:24 | elem2 |
102+
| C.cpp:18:12:18:18 | call to C [post constructor] [s3, ... (1)] | C.cpp:19:5:19:5 | c [s3, ... (1)] |
78103
| C.cpp:18:12:18:18 | call to C [s3, ... (1)] | C.cpp:19:5:19:5 | c [s3, ... (1)] |
79104
| C.cpp:19:5:19:5 | c [s3, ... (1)] | C.cpp:27:8:27:11 | `this` parameter in func [s3, ... (1)] |
105+
| C.cpp:24:5:24:8 | this [post update] [s3, ... (1)] | C.cpp:18:12:18:18 | call to C [post constructor] [s3, ... (1)] |
80106
| C.cpp:24:5:24:8 | this [post update] [s3, ... (1)] | C.cpp:18:12:18:18 | call to C [s3, ... (1)] |
81107
| C.cpp:24:5:24:25 | ... = ... [void] | C.cpp:24:5:24:8 | this [post update] [s3, ... (1)] |
82108
| C.cpp:24:16:24:25 | new [void] | C.cpp:24:5:24:25 | ... = ... [void] |

cpp/ql/test/library-tests/dataflow/taint-tests/localTaint.expected

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,19 @@
5757
| taint.cpp:84:10:84:12 | call to MyClass | taint.cpp:89:7:89:9 | mc1 | |
5858
| taint.cpp:84:10:84:12 | call to MyClass | taint.cpp:90:7:90:9 | mc1 | |
5959
| taint.cpp:84:10:84:12 | call to MyClass | taint.cpp:91:7:91:9 | mc1 | |
60+
| taint.cpp:84:10:84:12 | call to MyClass [post constructor] | taint.cpp:86:2:86:4 | mc1 | |
61+
| taint.cpp:84:10:84:12 | call to MyClass [post constructor] | taint.cpp:88:7:88:9 | mc1 | |
62+
| taint.cpp:84:10:84:12 | call to MyClass [post constructor] | taint.cpp:89:7:89:9 | mc1 | |
63+
| taint.cpp:84:10:84:12 | call to MyClass [post constructor] | taint.cpp:90:7:90:9 | mc1 | |
64+
| taint.cpp:84:10:84:12 | call to MyClass [post constructor] | taint.cpp:91:7:91:9 | mc1 | |
6065
| taint.cpp:84:15:84:17 | call to MyClass | taint.cpp:92:7:92:9 | mc2 | |
6166
| taint.cpp:84:15:84:17 | call to MyClass | taint.cpp:93:7:93:9 | mc2 | |
6267
| taint.cpp:84:15:84:17 | call to MyClass | taint.cpp:94:7:94:9 | mc2 | |
6368
| taint.cpp:84:15:84:17 | call to MyClass | taint.cpp:95:7:95:9 | mc2 | |
69+
| taint.cpp:84:15:84:17 | call to MyClass [post constructor] | taint.cpp:92:7:92:9 | mc2 | |
70+
| taint.cpp:84:15:84:17 | call to MyClass [post constructor] | taint.cpp:93:7:93:9 | mc2 | |
71+
| taint.cpp:84:15:84:17 | call to MyClass [post constructor] | taint.cpp:94:7:94:9 | mc2 | |
72+
| taint.cpp:84:15:84:17 | call to MyClass [post constructor] | taint.cpp:95:7:95:9 | mc2 | |
6473
| taint.cpp:86:2:86:4 | mc1 [post update] | taint.cpp:88:7:88:9 | mc1 | |
6574
| taint.cpp:86:2:86:4 | mc1 [post update] | taint.cpp:89:7:89:9 | mc1 | |
6675
| taint.cpp:86:2:86:4 | mc1 [post update] | taint.cpp:90:7:90:9 | mc1 | |

0 commit comments

Comments
 (0)