Skip to content

Commit 511ff2f

Browse files
Mivirladsr
authored andcommitted
fix mouse x,y coordinate truncation in 1006/1015 modes
In 1006 mode, x,y coordinates may be specified with integers larger than can be stored in 8 bits. The cast to uint8_t prevented mouse clicks at larger indices from being reported correctly.
1 parent 8ee9dc1 commit 511ff2f

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

termbox2.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3700,10 +3700,10 @@ static int extract_esc_mouse(struct tb_event *event) {
37003700
int start = (type == TYPE_1015 ? 2 : 3);
37013701

37023702
unsigned n1 = strtoul(&in->buf[start], NULL, 10);
3703-
unsigned n2 =
3704-
strtoul(&in->buf[indices[FIRST_SEMICOLON] + 1], NULL, 10);
3705-
unsigned n3 =
3706-
strtoul(&in->buf[indices[LAST_SEMICOLON] + 1], NULL, 10);
3703+
int n2 =
3704+
atoi(&in->buf[indices[FIRST_SEMICOLON] + 1]);
3705+
int n3 =
3706+
atoi(&in->buf[indices[LAST_SEMICOLON] + 1]);
37073707

37083708
if (type == TYPE_1015) {
37093709
n1 -= 0x20;
@@ -3744,8 +3744,8 @@ static int extract_esc_mouse(struct tb_event *event) {
37443744
event->mod |= TB_MOD_MOTION;
37453745
}
37463746

3747-
event->x = ((uint8_t)n2) - 1;
3748-
event->y = ((uint8_t)n3) - 1;
3747+
event->x = (n2 - 1 < 0) ? 0 : n2 - 1;
3748+
event->y = (n3 - 1 < 0) ? 0 : n3 - 1;
37493749

37503750
ret = TB_OK;
37513751
}

0 commit comments

Comments
 (0)