Skip to content

Commit 16508b1

Browse files
committed
C++: Fix off-by-one error in getType on 'FinalGlobalValue' nodes and accept test changes.
1 parent 302d35b commit 16508b1

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ class FinalGlobalValue extends Node, TFinalGlobalValue {
795795
override DataFlowType getType() {
796796
exists(int indirectionIndex |
797797
indirectionIndex = globalUse.getIndirectionIndex() and
798-
result = getTypeImpl(globalUse.getUnderlyingType(), indirectionIndex - 1)
798+
result = getTypeImpl(globalUse.getUnderlyingType(), indirectionIndex)
799799
)
800800
}
801801

cpp/ql/test/library-tests/dataflow/dataflow-tests/dispatch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ Top *readGlobalBottom() {
5252
}
5353

5454
void DispatchThroughGlobal() {
55-
sink(globalBottom->isSource1()); // $ MISSING: ast,ir
55+
sink(globalBottom->isSource1()); // $ ir MISSING: ast
5656
sink(globalMiddle->isSource1()); // no flow
5757

58-
sink(readGlobalBottom()->isSource1()); // $ MISSING: ast,ir
58+
sink(readGlobalBottom()->isSource1()); // $ ir MISSING: ast
5959

6060
globalBottom = new Bottom();
6161
globalMiddle = new Middle();

cpp/ql/test/library-tests/dataflow/dataflow-tests/test-source-sink.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ irFlow
173173
| dispatch.cpp:16:37:16:42 | call to source | dispatch.cpp:40:15:40:23 | call to isSource2 |
174174
| dispatch.cpp:22:37:22:42 | call to source | dispatch.cpp:31:16:31:24 | call to isSource1 |
175175
| dispatch.cpp:22:37:22:42 | call to source | dispatch.cpp:39:15:39:23 | call to isSource1 |
176+
| dispatch.cpp:22:37:22:42 | call to source | dispatch.cpp:55:22:55:30 | call to isSource1 |
177+
| dispatch.cpp:22:37:22:42 | call to source | dispatch.cpp:58:28:58:36 | call to isSource1 |
176178
| dispatch.cpp:33:18:33:23 | call to source | dispatch.cpp:23:38:23:38 | x |
177179
| dispatch.cpp:41:17:41:22 | call to source | dispatch.cpp:23:38:23:38 | x |
178180
| dispatch.cpp:69:15:69:20 | call to source | dispatch.cpp:23:38:23:38 | x |

cpp/ql/test/library-tests/dataflow/dispatch/test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void set_global_to_derived() {
109109
}
110110

111111
void read_global() {
112-
global_derived->virtual_f(); // $ SPURIOUS: target=3 MISSING: target=8
112+
global_derived->virtual_f(); // $ target=8
113113
}
114114

115115
Base* global_base_or_derived;
@@ -123,5 +123,5 @@ void set_global_base_or_derived_2() {
123123
}
124124

125125
void read_global_base_or_derived() {
126-
global_base_or_derived->virtual_f(); // $ target=3 MISSING: target=8
126+
global_base_or_derived->virtual_f(); // $ target=3 target=8
127127
}

0 commit comments

Comments
 (0)