Skip to content

Commit ddfb44e

Browse files
committed
diff: check range before dereferencing an array element
Before accessing an array element at a given index, we should make sure that the index is within the desired bounds, not afterwards, otherwise it may not make sense to even access the array element in the first place. Pointed out by CodeQL's `cpp/offset-use-before-range-check` rule. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 683c54c commit ddfb44e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

diff.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ static void fill_es_indent_data(struct emitted_diff_symbol *es)
892892

893893
/* skip any \v \f \r at start of indentation */
894894
while (s[off] == '\f' || s[off] == '\v' ||
895-
(s[off] == '\r' && off < len - 1))
895+
(off < len - 1 && s[off] == '\r'))
896896
off++;
897897

898898
/* calculate the visual width of indentation */

0 commit comments

Comments
 (0)