From cd87d88a930a0b58cfca38678d2e757491c17b26 Mon Sep 17 00:00:00 2001 From: Albert Cervin Date: Thu, 7 Mar 2024 21:56:36 +0100 Subject: Fix asan errors It found some really nasty ones :) --- src/dged/text.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/dged/text.c') diff --git a/src/dged/text.c b/src/dged/text.c index 0a92933..82c49bc 100644 --- a/src/dged/text.c +++ b/src/dged/text.c @@ -77,9 +77,14 @@ void text_clear(struct text *text) { // given `char_idx` as a character index, return the byte index uint32_t charidx_to_byteidx(struct line *line, uint32_t char_idx) { + if (line->nchars == 0) { + return 0; + } + if (char_idx > line->nchars) { - return line->nbytes; + return line->nbytes - 1; } + return utf8_nbytes(line->data, line->nbytes, char_idx); } -- cgit v1.2.3