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

Commit bbce7d1

Browse files
committed
Simplify existing code
1 parent 1c5a460 commit bbce7d1

2 files changed

Lines changed: 8 additions & 26 deletions

File tree

ql/src/semmle/go/dataflow/internal/DataFlowPrivate.qll

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ private import DataFlowUtil
33
private import DataFlowImplCommon
44

55
private newtype TReturnKind =
6-
TSingleReturn() or
7-
TMultiReturn(int i) { exists(SignatureType st | exists(st.getResultType(i))) }
6+
MkReturnKind(int i) { exists(SignatureType st | exists(st.getResultType(i))) }
87

98
/**
109
* A return kind. A return kind describes how a value can be returned
@@ -13,23 +12,14 @@ private newtype TReturnKind =
1312
*/
1413
class ReturnKind extends TReturnKind {
1514
/** Gets a textual representation of this return kind. */
16-
string toString() {
17-
this = TSingleReturn() and
18-
result = "return"
19-
or
20-
exists(int i | this = TMultiReturn(i) | result = "return[" + i + "]")
21-
}
15+
string toString() { exists(int i | this = MkReturnKind(i) | result = "return[" + i + "]") }
2216
}
2317

2418
/** A data flow node that represents returning a value from a function. */
2519
class ReturnNode extends ResultNode {
2620
ReturnKind kind;
2721

28-
ReturnNode() {
29-
exists(int nr | nr = fd.getType().getNumResult() |
30-
if nr = 1 then kind = TSingleReturn() else kind = TMultiReturn(i)
31-
)
32-
}
22+
ReturnNode() { exists(int nr | nr = fd.getType().getNumResult() | kind = MkReturnKind(i)) }
3323

3424
/** Gets the kind of this returned value. */
3525
ReturnKind getKind() { result = kind }
@@ -40,12 +30,7 @@ class OutNode extends DataFlow::Node {
4030
DataFlow::CallNode call;
4131
int i;
4232

43-
OutNode() {
44-
this = call.getResult() and
45-
i = -1
46-
or
47-
this = call.getResult(i)
48-
}
33+
OutNode() { this = call.getResult(i) }
4934

5035
/** Gets the underlying call. */
5136
DataFlowCall getCall() { result = call.asExpr() }
@@ -56,11 +41,8 @@ class OutNode extends DataFlow::Node {
5641
* `kind`.
5742
*/
5843
OutNode getAnOutNode(DataFlowCall call, ReturnKind kind) {
59-
exists(DataFlow::CallNode c | c.asExpr() = call |
60-
kind = TSingleReturn() and
61-
result = c.getResult()
62-
or
63-
exists(int i | kind = TMultiReturn(i) | result = c.getResult(i))
44+
exists(DataFlow::CallNode c, int i | c.asExpr() = call and kind = MkReturnKind(i) |
45+
result = c.getResult(i)
6446
)
6547
}
6648

ql/src/semmle/go/frameworks/Stdlib.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module PathFilePath {
6262

6363
override predicate hasTaintFlow(DataFlow::FunctionInput inp, DataFlow::FunctionOutput outp) {
6464
inp.isParameter(_) and
65-
(outp.isResult() or outp.isResult(_))
65+
outp.isResult(_)
6666
}
6767
}
6868
}
@@ -472,7 +472,7 @@ module Path {
472472

473473
override predicate hasTaintFlow(DataFlow::FunctionInput inp, DataFlow::FunctionOutput outp) {
474474
inp.isParameter(_) and
475-
(outp.isResult() or outp.isResult(_))
475+
outp.isResult(_)
476476
}
477477
}
478478
}

0 commit comments

Comments
 (0)