summaryrefslogtreecommitdiff
path: root/src/dged
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2024-09-17 08:48:49 +0200
committerAlbert Cervin <albert@acervin.com>2024-09-17 08:48:49 +0200
commit10caa92f491504d670b890f9cc99d08240efce41 (patch)
tree4896cb8a9080f56c98e0c92bd015899effe10e51 /src/dged
parentaaf3d2439ff3088a73e7e785185efbe86809256d (diff)
downloaddged-10caa92f491504d670b890f9cc99d08240efce41.tar.gz
dged-10caa92f491504d670b890f9cc99d08240efce41.tar.xz
dged-10caa92f491504d670b890f9cc99d08240efce41.zip
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.
Diffstat (limited to 'src/dged')
-rw-r--r--src/dged/buffer.c5
1 files changed, 3 insertions, 2 deletions
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)};
}
}