Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 4be8059

Browse files
committed
Make FunctionOutput.isResult(0) match single results
1 parent ae2ed87 commit 4be8059

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

ql/src/semmle/go/dataflow/FunctionInputsAndOutputs.qll

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ private class ResultInput extends FunctionInput, TInResult {
100100

101101
override predicate isResult() { index = -1 }
102102

103-
override predicate isResult(int i) { i = index and i >= 0 }
103+
override predicate isResult(int i) {
104+
index = -1 and i = 0
105+
or
106+
i = index and i >= 0
107+
}
104108

105109
override DataFlow::Node getEntryNode(DataFlow::CallNode c) {
106110
exists(DataFlow::PostUpdateNode pun, DataFlow::Node init |
@@ -181,7 +185,11 @@ private class OutResult extends FunctionOutput, TOutResult {
181185

182186
override predicate isResult() { index = -1 }
183187

184-
override predicate isResult(int i) { i = index and i >= 0 }
188+
override predicate isResult(int i) {
189+
index = -1 and i = 0
190+
or
191+
i = index and i >= 0
192+
}
185193

186194
override DataFlow::Node getEntryNode(FuncDef f) {
187195
// return expressions
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
| main.go:51:2:51:14 | call to op | main.go:51:2:51:14 | call to op | 0 | result |
2+
| main.go:53:2:53:22 | call to op2 | main.go:53:2:53:22 | call to op2 | 0 | result |
3+
| main.go:53:14:53:21 | call to bump | main.go:53:14:53:21 | call to bump | 0 | result |
14
| main.go:54:10:54:15 | call to test | main.go:54:2:54:15 | ... := ...[0] | 0 | result 0 |
25
| main.go:54:10:54:15 | call to test | main.go:54:2:54:15 | ... := ...[1] | 1 | result 1 |
36
| main.go:56:9:56:15 | call to test2 | main.go:56:2:56:15 | ... = ...[0] | 0 | result 0 |
47
| main.go:56:9:56:15 | call to test2 | main.go:56:2:56:15 | ... = ...[1] | 1 | result 1 |
8+
| tst.go:9:17:9:33 | call to new | tst.go:9:17:9:33 | call to new | 0 | result |

0 commit comments

Comments
 (0)