diff options
| author | Albert Cervin <albert@acervin.com> | 2024-03-07 21:56:36 +0100 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2024-03-07 21:56:36 +0100 |
| commit | cd87d88a930a0b58cfca38678d2e757491c17b26 (patch) | |
| tree | 412352d2ae67b6e64df6320d64a3cfeda0194b88 /src/dged/text.c | |
| parent | a13750209b3836a4a6a16a7ba881625f397f160f (diff) | |
| download | dged-cd87d88a930a0b58cfca38678d2e757491c17b26.tar.gz dged-cd87d88a930a0b58cfca38678d2e757491c17b26.tar.xz dged-cd87d88a930a0b58cfca38678d2e757491c17b26.zip | |
Fix asan errors
It found some really nasty ones :)
Diffstat (limited to 'src/dged/text.c')
| -rw-r--r-- | src/dged/text.c | 7 |
1 files changed, 6 insertions, 1 deletions
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); } |
