vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 8127bc4adb12c005f752ca91b06b7c426db7099a
parent d179576eecb0e68f0c1468b24b9a535210dd35e1
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sun, 12 Feb 2017 17:32:33 +0100

view: improve handling of long sequences of combining characters

They will still not be displayed correctly, but at least they
should no longer cause memory errors.

Diffstat:
Mview.c | 4+++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/view.c b/view.c @@ -370,6 +370,8 @@ void view_draw(View *view) { /* NUL byte encountered, store it and continue */ cell = (Cell){ .data = "\x00", .len = 1, .width = 2 }; } else { + if (len >= sizeof(cell.data)) + len = sizeof(cell.data)-1; for (size_t i = 0; i < len; i++) cell.data[i] = cur[i]; cell.data[len] = '\0'; @@ -384,7 +386,7 @@ void view_draw(View *view) { cell = (Cell){ .data = "\n", .len = 2, .width = 1 }; } - if (cell.width == 0 && prev_cell.len + cell.len < sizeof(cell.len)) { + if (cell.width == 0 && prev_cell.len + cell.len < sizeof(cell.data)) { prev_cell.len += cell.len; strcat(prev_cell.data, cell.data); } else {