Merge pull request #7239 from smowton/smowton/fix/useless-comparison-surrogates

Range analysis and useless-comparison query: don't treat all unicode surrogates as if they are U+FFFD
This commit is contained in:
Anders Schack-Mulligen
2021-11-26 09:00:36 +01:00
committed by GitHub
5 changed files with 102 additions and 3 deletions

View File

@@ -713,6 +713,17 @@ class DoubleLiteral extends Literal, @doubleliteral {
override string getAPrimaryQlClass() { result = "DoubleLiteral" }
}
bindingset[s]
private int fromHex(string s) {
exists(string digits | s.toUpperCase() = digits |
result =
sum(int i |
|
"0123456789ABCDEF".indexOf(digits.charAt(i)).bitShiftLeft((digits.length() - i - 1) * 4)
)
)
}
/** A character literal. For example, `'\n'`. */
class CharacterLiteral extends Literal, @characterliteral {
override string getAPrimaryQlClass() { result = "CharacterLiteral" }
@@ -731,7 +742,11 @@ class CharacterLiteral extends Literal, @characterliteral {
* this literal. The result is the same as if the Java code had cast
* the character to an `int`.
*/
int getCodePointValue() { result.toUnicode() = this.getValue() }
int getCodePointValue() {
if this.getLiteral().matches("'\\u____'")
then result = fromHex(this.getLiteral().substring(3, 7))
else result.toUnicode() = this.getValue()
}
}
/**