From 10caa92f491504d670b890f9cc99d08240efce41 Mon Sep 17 00:00:00 2001 From: Albert Cervin Date: Tue, 17 Sep 2024 08:48:49 +0200 Subject: Fix crash when buffer was non-lazy add In this case, the end of the buffer is on the last line, however if there are no lines in the buffer, it would cause an underflow. --- src/dged/buffer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/dged/buffer.c') diff --git a/src/dged/buffer.c b/src/dged/buffer.c index c537fb3..84d2f75 100644 --- a/src/dged/buffer.c +++ b/src/dged/buffer.c @@ -788,8 +788,9 @@ struct location buffer_end(struct buffer *buffer) { if (buffer->lazy_row_add) { return (struct location){.line = nlines, .col = 0}; } else { - return (struct location){.line = nlines - 1, - .col = buffer_line_length(buffer, nlines - 1)}; + nlines = nlines == 0 ? 0 : nlines - 1; + return (struct location){.line = nlines, + .col = buffer_line_length(buffer, nlines)}; } } -- cgit v1.2.3