From 7ff5a8027a9f5b520132f5c85d3d22cb9c1db084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 18 Nov 2019 11:31:21 +0100 Subject: [PATCH] term: report_mouse_click(): legacy mode only supports rows/cols up to 223. In the legacy mouse reporting mode, line and column numbers are limited to 223 (255-32). In case the current coordinate falls outside this, simply ignore it (don't report it). --- terminal.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/terminal.c b/terminal.c index e11ca371..bbcd16f2 100644 --- a/terminal.c +++ b/terminal.c @@ -1268,10 +1268,16 @@ report_mouse_click(struct terminal *term, int encoded_button, int row, int col, char response[128]; switch (term->mouse_reporting) { - case MOUSE_NORMAL: + case MOUSE_NORMAL: { + int encoded_col = 32 + col + 1; + int encoded_row = 32 + row + 1; + if (encoded_col > 255 || encoded_row > 255) + return; + snprintf(response, sizeof(response), "\033[M%c%c%c", - 32 + (release ? 3 : encoded_button), 32 + col + 1, 32 + row + 1); + 32 + (release ? 3 : encoded_button), encoded_col, encoded_row); break; + } case MOUSE_SGR: snprintf(response, sizeof(response), "\033[<%d;%d;%d%c",