Skip to content

Commit dad6292

Browse files
committed
Make CodeQL happy
1 parent 547d09a commit dad6292

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

kitty/screen.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,16 +2871,18 @@ screen_multi_cursor(Screen *self, int queried_shape, int *params, unsigned num_p
28712871
write_escape_code_to_child(self, ESC_CSI, ">-1;1;2;3 q");
28722872
} else if (queried_shape == -2) {
28732873
size_t sz = self->extra_cursors.count * 32 + 64;
2874-
RAII_ALLOC(char, buf, malloc(sz));
2874+
RAII_ALLOC(char, buf, malloc(sz)); sz -= 4;
28752875
if (buf) {
28762876
char *p = buf + snprintf(buf, sz, ">-2;");
28772877
for (unsigned i = 0; i < self->extra_cursors.count; i++) {
28782878
index_type cell = self->extra_cursors.locations[i].cell, shape = self->extra_cursors.locations[i].shape;
28792879
index_type y = cell / self->columns, x = cell - (y * self->columns);
2880-
p += snprintf(p, sz - (p - buf), "%d:2:%u:%u;", shape > 3 ? -1 : (int)shape, y+1, x+1);
2880+
int n = snprintf(p, sz - (p - buf), "%d:2:%u:%u;", shape > 3 ? -1 : (int)shape, y+1, x+1);
2881+
if (n < 0 || (unsigned)n > (sz - (p - buf))) break;
2882+
p += n;
28812883
}
28822884
if (*(p-1) == ';') p--;
2883-
p += snprintf(p, sz - (p - buf), " q"); *p = 0;
2885+
*(p++) = ' '; *(p++) = 'q'; *(p++) = 0;
28842886
write_escape_code_to_child(self, ESC_CSI, buf);
28852887
}
28862888
}
@@ -2952,7 +2954,7 @@ screen_multi_cursor(Screen *self, int queried_shape, int *params, unsigned num_p
29522954
bottom = MIN(bottom, self->lines-1); right = MIN(right, self->columns -1);
29532955
index_type xnum = right + 1 - left, ynum = bottom + 1 - top;
29542956
ensure_space_for(&self->extra_cursors, locations, ExtraCursor,
2955-
self->extra_cursors.count + xnum * ynum, capacity, 20 * 80, false);
2957+
self->extra_cursors.count + (unsigned)xnum * ynum, capacity, 20 * 80, false);
29562958
for (index_type y = top; y <= bottom; y++) {
29572959
for (index_type x = left; x <= right; x++) {
29582960
self->extra_cursors.locations[self->extra_cursors.count++] = (ExtraCursor){

0 commit comments

Comments
 (0)