From ab179bbf427149ee59d9d93535b9c4fb2191cfca Mon Sep 17 00:00:00 2001 From: Pauli Date: Mon, 9 Jul 2018 16:09:34 +0300 Subject: [PATCH] Fix crash when editing lines that are exactly console width plen+cooked_cursor==cols => begin = -1 which is passed to substr. The sign is incorrect as code should be removing a character from begin instead of trying to add a character. --- library/Console-posix.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library/Console-posix.cpp b/library/Console-posix.cpp index 6602b0d0b..da786aaac 100644 --- a/library/Console-posix.cpp +++ b/library/Console-posix.cpp @@ -486,9 +486,10 @@ namespace DFHack int cooked_cursor = raw_cursor; if ((plen+cooked_cursor) >= cols) { - begin = plen+cooked_cursor-cols-1; - len -= plen+cooked_cursor-cols-1; - cooked_cursor -= plen+cooked_cursor-cols-1; + const int text_over = plen + cooked_cursor + 1 - cols; + begin = text_over; + len -= text_over; + cooked_cursor -= text_over; } if (plen+len > cols) len -= plen+len - cols;