Fix several issues caught by address sanitiser

This commit is contained in:
mintsuki 2022-12-03 19:27:37 +01:00
parent 4199c330c1
commit 6ee3fe00c6
2 changed files with 15 additions and 6 deletions

View File

@ -467,7 +467,8 @@ static void push_to_queue(struct term_context *_ctx, struct fbterm_char *c, size
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) {
@ -476,9 +477,6 @@ static void fbterm_revscroll(struct term_context *_ctx) {
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.
@ -650,6 +648,11 @@ static void draw_cursor(struct term_context *_ctx) {
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) {

10
term.c
View File

@ -938,7 +938,7 @@ int mk_wcwidth(wchar_t ucs) {
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,
@ -1146,6 +1146,11 @@ static void term_putchar(struct term_context *ctx, uint8_t c) {
}
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) {
@ -1165,7 +1170,8 @@ static void term_putchar(struct term_context *ctx, uint8_t c) {
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;