mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
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:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user