From 2d803ddd66f607d19737cf35dfd19d2681249d8b Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Thu, 20 Sep 2018 17:37:50 +0200 Subject: [PATCH] Merge pull request #930 from ailin-nemui/fix-928 fix accessing unallocated text when checking entry position (cherry picked from commit 708ba06dbc30dcec99cf057a1f36fc9857308b72) --- src/fe-text/gui-entry.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index e91fcfb3..b3b4dd56 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -171,7 +171,7 @@ static int pos2scrpos(GUI_ENTRY_REC *entry, int pos) int i; int xpos = 0; - for (i = 0; i < pos; i++) { + for (i = 0; i < entry->text_len && i < pos; i++) { unichar c = entry->text[i]; if (term_type == TERM_TYPE_BIG5) @@ -181,7 +181,7 @@ static int pos2scrpos(GUI_ENTRY_REC *entry, int pos) else xpos++; } - return xpos; + return xpos + pos - i; } static int scrpos2pos(GUI_ENTRY_REC *entry, int pos)