Skip to content

Commit 58f0602

Browse files
author
Alvaro Muñoz
committed
fix: count(text.splitAt()) does not account for all lines, use max(text.splitAt(,i)) instead
1 parent 8711930 commit 58f0602

File tree

1 file changed

+7
-3
lines changed
  • ql/lib/codeql/actions/ast/internal

1 file changed

+7
-3
lines changed

ql/lib/codeql/actions/ast/internal/Ast.qll

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@ private import codeql.actions.Helper
44
private import codeql.actions.config.Config
55
private import codeql.actions.DataFlow
66

7+
bindingset[text]
8+
int numberOfLines(string text) { result = max(int i | exists(text.splitAt("\n", i))) }
9+
710
/**
811
* Gets the length of each line in the StringValue .
912
*/
1013
bindingset[text]
11-
int lineLength(string text, int idx) {
12-
exists(string line | line = text.splitAt("\n", idx) and result = line.length() + 1)
14+
int lineLength(string text, int i) {
15+
i in [0 .. numberOfLines(text)] and
16+
result = text.splitAt("\n", i).length() + 1
1317
}
1418

1519
/**
1620
* Gets the sum of the length of the lines up to the given index.
1721
*/
1822
bindingset[text]
1923
int partialLineLengthSum(string text, int i) {
20-
i in [0 .. count(text.splitAt("\n"))] and
24+
i in [0 .. numberOfLines(text)] and
2125
result = sum(int j, int length | j in [0 .. i] and length = lineLength(text, j) | length)
2226
}
2327

0 commit comments

Comments
 (0)