Skip to content

Commit

Permalink
Merge pull request github#18826 from owen-mc/go/join-order-fixes
Browse files Browse the repository at this point in the history
Go: Fix bad join order in `comparesFirstCharacter`
  • Loading branch information
owen-mc authored Feb 21, 2025
2 parents c93fb4c + 44c5df5 commit 721b8c4
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions go/ql/lib/semmle/go/StringOps.qll
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,22 @@ module StringOps {
override boolean getPolarity() { result = expr.getPolarity() }
}

pragma[noinline]
private DataFlow::ElementReadNode getReadOfFirstChar(DataFlow::Node str) {
pragma[only_bind_into](result).getIndex().getIntValue() = 0 and
str = result.getBase() and
str.getType().getUnderlyingType() instanceof StringType
}

/**
* Holds if `eq` is of the form `str[0] == rhs` or `str[0] != rhs`.
*/
pragma[noinline]
private predicate comparesFirstCharacter(
DataFlow::EqualityTestNode eq, DataFlow::Node str, DataFlow::Node rhs
) {
exists(DataFlow::ElementReadNode read |
eq.hasOperands(globalValueNumber(read).getANode(), rhs) and
str = read.getBase() and
str.getType().getUnderlyingType() instanceof StringType and
read.getIndex().getIntValue() = 0
)
eq.hasOperands(globalValueNumber(pragma[only_bind_out](getReadOfFirstChar(str))).getANode(),
rhs)
}

/**
Expand Down

0 comments on commit 721b8c4

Please sign in to comment.