From d08206dce1291f512d7de9037d9ef1ffbf705cac Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 3 Dec 2018 10:07:58 +0100 Subject: vi: correctly detect when a deletion empties the buffer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Michał Berger has reported two issues: - Repeatedly deleting and undoing the deletion of the last line results in characters being lost from the end of the line. - Deleting the bottom line twice then attempting to undo each of these deletions results in a segfault. The problem seems to be an incorrect test for whether the text buffer is empty. Reported-by: Michał Berger Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- editors/vi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editors') diff --git a/editors/vi.c b/editors/vi.c index ee3c7feb2..271529404 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -2364,7 +2364,7 @@ static void undo_push(char *src, unsigned int length, uint8_t u_type) // Add to // Allocate a new undo object if (u_type == UNDO_DEL || u_type == UNDO_DEL_CHAIN) { // For UNDO_DEL objects, save deleted text - if ((src + length) == end) + if ((text + length) == end) length--; // If this deletion empties text[], strip the newline. When the buffer becomes // zero-length, a newline is added back, which requires this to compensate. -- cgit v1.2.3