From cea49794a032404a4825ccc76ee168ee004ccff3 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Tue, 15 Nov 2016 22:28:27 +0100 Subject: [PATCH] termiolink: hopefully fixes segfault. Closes T4896 --- src/bin/termiolink.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bin/termiolink.c b/src/bin/termiolink.c index a54763da..a69c7d6a 100644 --- a/src/bin/termiolink.c +++ b/src/bin/termiolink.c @@ -73,6 +73,8 @@ _txt_at(Termpty *ty, int *x, int *y, char *txt, int *txtlenp) cells = termpty_cellrow_get(ty, *y, &w); if (!cells || !w) goto bad; + if ((*x >= w)) + *x = w-1; cell = cells[*x]; if ((cell.codepoint == 0) && (cell.att.dblwidth)) { @@ -113,7 +115,7 @@ _txt_prev_at(Termpty *ty, int *x, int *y, char *txt, int *txtlenp) cells = termpty_cellrow_get(ty, *y, &w); if (!cells || !w) goto bad; - if ((*x) < 0) + if (((*x) < 0) || ((*x) >= w)) *x = w-1; cell = cells[*x];