Skip to content

Commit 449e377

Browse files
committed
UnboundList: Use ASCII encoding instead of Unicode
1 parent bdbe039 commit 449e377

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

shared/util/codeql/util/UnboundList.qll

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ overlay[local?]
1010
module;
1111

1212
private import Location
13+
private import Strings
1314

1415
/** Provides the input to `Make`. */
1516
signature module InputSig<LocationSig Location> {
@@ -53,30 +54,33 @@ module Make<LocationSig Location, InputSig<Location> Input> {
5354
int getRank(Element e) { e = DenseRank<DenseRankInput>::denseRank(result) }
5455

5556
pragma[nomagic]
56-
private string interpretUnicodeCodePoint(int codePoint) {
57-
codePoint = [0, getRank(_)] and
58-
codePoint.toUnicode() = result and
59-
result != "." // used as element separator
57+
private string interpretAsciiCode(int code) {
58+
exists(int dot, int c |
59+
c = code + 1 and
60+
// `.` is used as element separator, so cannot be used to encode elements
61+
dot = asciiPrintable(".") and
62+
if c < dot then c = asciiPrintable(result) else c + 1 = asciiPrintable(result)
63+
)
6064
}
6165

62-
private int unicodeCodePoints() { result = strictcount(interpretUnicodeCodePoint(_)) }
66+
private int asciiCodes() { result = strictcount(interpretAsciiCode(_)) }
6367

64-
private int getUnicodeCodePointPart(Element e, int i) {
68+
private int getAsciiCodePart(Element e, int i) {
6569
result = getRank(e) and
6670
i = 0
6771
or
6872
exists(int mid |
69-
mid = getUnicodeCodePointPart(e, i - 1) and
73+
mid = getAsciiCodePart(e, i - 1) and
7074
mid > 0 and
71-
result = mid / unicodeCodePoints()
75+
result = mid / asciiCodes()
7276
)
7377
}
7478

7579
pragma[nomagic]
7680
private string encode(Element e) {
7781
result =
7882
strictconcat(string s, int i |
79-
s = interpretUnicodeCodePoint(getUnicodeCodePointPart(e, i) % unicodeCodePoints())
83+
s = interpretAsciiCode(getAsciiCodePart(e, i) % asciiCodes())
8084
|
8185
s order by i
8286
)

0 commit comments

Comments
 (0)