Skip to content

Commit cc7bfab

Browse files
committed
Fix result node and remove SPURIOUS test result
1 parent 32aeae8 commit cc7bfab

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

go/ql/lib/semmle/go/dataflow/internal/DataFlowNodes.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,10 @@ module Public {
932932

933933
ResultNode() {
934934
exists(FuncDef fd |
935+
// When a function has any (named) result variables, then the
936+
// `ReadResultInstruction`s at the end of the function are the correct
937+
// result nodes.
938+
not exists(fd.getAResultVar()) and
935939
exists(IR::ReturnInstruction ret | ret.getRoot() = fd | insn = ret.getResult(i))
936940
or
937941
insn.(IR::ReadResultInstruction).reads(fd.getResultVar(i))

go/ql/test/library-tests/semmle/go/dataflow/Nodes/ResultNode.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66
| resultParameters.go:13:9:13:9 | 3 | Result node with index 0 |
77
| resultParameters.go:16:26:16:26 | implicit read of r | Result node with index 0 |
88
| resultParameters.go:21:38:21:38 | implicit read of r | Result node with index 0 |
9-
| resultParameters.go:24:10:24:10 | 1 | Result node with index 0 |

go/ql/test/library-tests/semmle/go/dataflow/Nodes/resultParameters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func resultParameter1() (r int) { // $ Alert[result-node] // implicit reads of r
2121
func resultParameter2(selector int) (r int) { // $ Alert[result-node] // implicit reads of result parameters are located at the result parameter declaration
2222
r = 0
2323
if selector == 1 {
24-
return 1 // $ SPURIOUS: Alert[result-node]
24+
return 1
2525
}
2626
return
2727
}

0 commit comments

Comments
 (0)