From b1f8dd75d684b3dd00f147a63ef687a6b566fc7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 10 Jul 2019 18:47:32 +0200 Subject: [PATCH] cell: we only need 4 bytes for the longest utf8 sequence We don't *have* to NULL-terminate the utf8 string. So don't. This makes the cell glyph 4 bytes exactly, which is better for alignment and cache usage. --- render.c | 2 +- terminal.h | 2 +- vt.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/render.c b/render.c index 65e2ab96..894bc939 100644 --- a/render.c +++ b/render.c @@ -101,7 +101,7 @@ render_cell(struct terminal *term, struct buffer *buf, const struct cell *cell, cairo_status_t status = cairo_scaled_font_text_to_glyphs( attrs_to_font(term, &cell->attrs), x, y + term->fextents.ascent, - cell->c, strlen(cell->c), &gseq.g, &new_glyphs, + cell->c, strnlen(cell->c, 4), &gseq.g, &new_glyphs, NULL, NULL, NULL); if (status != CAIRO_STATUS_SUCCESS) diff --git a/terminal.h b/terminal.h index 66cfebe0..16e53f22 100644 --- a/terminal.h +++ b/terminal.h @@ -68,7 +68,7 @@ struct attributes { struct cell { struct attributes attrs; - char c[5]; + char c[4]; } __attribute__((packed)); struct scroll_region { diff --git a/vt.c b/vt.c index 8314c060..5d4127c5 100644 --- a/vt.c +++ b/vt.c @@ -757,7 +757,7 @@ action_print(struct terminal *term, uint8_t c) if (unlikely(term->charset[term->selected_charset] == CHARSET_GRAPHIC) && c >= 0x41 && c <= 0x7e) { - strcpy(cell->c, vt100_0[c - 0x41]); + strncpy(cell->c, vt100_0[c - 0x41], sizeof(cell->c)); } else { //LOG_DBG("print: ASCII: %c", c); cell->c[0] = c;