Fast and reasonably complete (framebuffer) terminal emulator (Zig fork)

Fix several issues caught by address sanitiser

mintsuki 6ee3fe00 4199c330

Changed files
+15 -6
backends
+7 -4
backends/framebuffer.c
···
static void fbterm_revscroll(struct term_context *_ctx) {
struct fbterm_context *ctx = (void *)_ctx;
-
for (size_t i = (_ctx->scroll_bottom_margin - 1) * _ctx->cols - 1; ; i--) {
+
for (size_t i = (_ctx->scroll_bottom_margin - 1) * _ctx->cols - 1;
+
i > (_ctx->scroll_top_margin + 1) * _ctx->cols; i--) {
struct fbterm_char *c;
struct fbterm_queue_item *q = ctx->map[i];
if (q != NULL) {
···
c = &ctx->grid[i];
}
push_to_queue(_ctx, c, (i + _ctx->cols) % _ctx->cols, (i + _ctx->cols) / _ctx->cols);
-
if (i == _ctx->scroll_top_margin * _ctx->cols) {
-
break;
-
}
}
// Clear the first line of the screen.
···
struct fbterm_context *ctx = (void *)_ctx;
size_t i = ctx->cursor_x + ctx->cursor_y * _ctx->cols;
+
+
if (i >= _ctx->cols * _ctx->rows) {
+
return;
+
}
+
struct fbterm_char c;
struct fbterm_queue_item *q = ctx->map[i];
if (q != NULL) {
+8 -2
term.c
···
if (ucs == 0)
return 0;
if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0))
-
return -1;
+
return 1;
/* binary search in table of non-spacing characters */
if (bisearch(ucs, combining,
···
if (ctx->unicode_remaining != 0) {
+
if ((c & 0xc0) != 0x80) {
+
ctx->unicode_remaining = 0;
+
goto unicode_error;
+
}
+
ctx->unicode_remaining--;
ctx->code_point |= (c & 0x3f) << (6 * ctx->unicode_remaining);
if (ctx->unicode_remaining != 0) {
···
return;
-
if (c > 0x7f && ctx->in_bootloader == false) {
+
unicode_error:
+
if (c >= 0xc0 && c <= 0xf7 && ctx->in_bootloader == false) {
if (c >= 0xc0 && c <= 0xdf) {
ctx->unicode_remaining = 1;
ctx->code_point = (c & 0x1f) << 6;