From 4be805966f697c0b1db94e65e1c620d6e9901cbf Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Wed, 27 May 2020 09:57:19 +0100 Subject: [PATCH] Make FunctionOutput.isResult(0) match single results --- .../semmle/go/dataflow/FunctionInputsAndOutputs.qll | 12 ++++++++++-- .../FunctionOutput_isResult_int.expected | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ql/src/semmle/go/dataflow/FunctionInputsAndOutputs.qll b/ql/src/semmle/go/dataflow/FunctionInputsAndOutputs.qll index 922aee5298c..b2a8176906a 100644 --- a/ql/src/semmle/go/dataflow/FunctionInputsAndOutputs.qll +++ b/ql/src/semmle/go/dataflow/FunctionInputsAndOutputs.qll @@ -100,7 +100,11 @@ private class ResultInput extends FunctionInput, TInResult { override predicate isResult() { index = -1 } - override predicate isResult(int i) { i = index and i >= 0 } + override predicate isResult(int i) { + index = -1 and i = 0 + or + i = index and i >= 0 + } override DataFlow::Node getEntryNode(DataFlow::CallNode c) { exists(DataFlow::PostUpdateNode pun, DataFlow::Node init | @@ -181,7 +185,11 @@ private class OutResult extends FunctionOutput, TOutResult { override predicate isResult() { index = -1 } - override predicate isResult(int i) { i = index and i >= 0 } + override predicate isResult(int i) { + index = -1 and i = 0 + or + i = index and i >= 0 + } override DataFlow::Node getEntryNode(FuncDef f) { // return expressions diff --git a/ql/test/library-tests/semmle/go/dataflow/FunctionInputsAndOutputs/FunctionOutput_isResult_int.expected b/ql/test/library-tests/semmle/go/dataflow/FunctionInputsAndOutputs/FunctionOutput_isResult_int.expected index f36f1b8a84b..4a2bec6dda3 100644 --- a/ql/test/library-tests/semmle/go/dataflow/FunctionInputsAndOutputs/FunctionOutput_isResult_int.expected +++ b/ql/test/library-tests/semmle/go/dataflow/FunctionInputsAndOutputs/FunctionOutput_isResult_int.expected @@ -1,4 +1,8 @@ +| main.go:51:2:51:14 | call to op | main.go:51:2:51:14 | call to op | 0 | result | +| main.go:53:2:53:22 | call to op2 | main.go:53:2:53:22 | call to op2 | 0 | result | +| main.go:53:14:53:21 | call to bump | main.go:53:14:53:21 | call to bump | 0 | result | | main.go:54:10:54:15 | call to test | main.go:54:2:54:15 | ... := ...[0] | 0 | result 0 | | main.go:54:10:54:15 | call to test | main.go:54:2:54:15 | ... := ...[1] | 1 | result 1 | | main.go:56:9:56:15 | call to test2 | main.go:56:2:56:15 | ... = ...[0] | 0 | result 0 | | main.go:56:9:56:15 | call to test2 | main.go:56:2:56:15 | ... = ...[1] | 1 | result 1 | +| tst.go:9:17:9:33 | call to new | tst.go:9:17:9:33 | call to new | 0 | result |