Skip to content

Commit 721b8c4

Browse files
authored
Merge pull request #18826 from owen-mc/go/join-order-fixes
Go: Fix bad join order in `comparesFirstCharacter`
2 parents c93fb4c + 44c5df5 commit 721b8c4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

go/ql/lib/semmle/go/StringOps.qll

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,22 @@ module StringOps {
102102
override boolean getPolarity() { result = expr.getPolarity() }
103103
}
104104

105+
pragma[noinline]
106+
private DataFlow::ElementReadNode getReadOfFirstChar(DataFlow::Node str) {
107+
pragma[only_bind_into](result).getIndex().getIntValue() = 0 and
108+
str = result.getBase() and
109+
str.getType().getUnderlyingType() instanceof StringType
110+
}
111+
105112
/**
106113
* Holds if `eq` is of the form `str[0] == rhs` or `str[0] != rhs`.
107114
*/
108115
pragma[noinline]
109116
private predicate comparesFirstCharacter(
110117
DataFlow::EqualityTestNode eq, DataFlow::Node str, DataFlow::Node rhs
111118
) {
112-
exists(DataFlow::ElementReadNode read |
113-
eq.hasOperands(globalValueNumber(read).getANode(), rhs) and
114-
str = read.getBase() and
115-
str.getType().getUnderlyingType() instanceof StringType and
116-
read.getIndex().getIntValue() = 0
117-
)
119+
eq.hasOperands(globalValueNumber(pragma[only_bind_out](getReadOfFirstChar(str))).getANode(),
120+
rhs)
118121
}
119122

120123
/**

0 commit comments

Comments
 (0)