From 7ff7947ab3af2cc4810f270ae4f6edb0392b2438 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 26 Oct 2024 13:34:28 +0530 Subject: [PATCH] Fix cell_as_unicode --- kitty/data-types.h | 1 + kitty/line.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/kitty/data-types.h b/kitty/data-types.h index 758ffcab7..6345a2d6e 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -59,6 +59,7 @@ static inline PyObject* Py_XNewRef(PyObject *o) { Py_XINCREF(o); return o; } typedef unsigned long long id_type; typedef uint32_t char_type; +static_assert(sizeof(Py_UCS4) == sizeof(char_type), "PyUCS4 and char_type dont match"); #define MAX_CHAR_TYPE_VALUE UINT32_MAX typedef uint32_t color_type; typedef uint16_t hyperlink_id_type; diff --git a/kitty/line.c b/kitty/line.c index 25ce85a36..1bebc7a78 100644 --- a/kitty/line.c +++ b/kitty/line.c @@ -229,7 +229,10 @@ static size_t cell_as_unicode(ListOfChars *lc, bool include_cc, Py_UCS4 *buf, char_type zero_char) { size_t n = 1; buf[0] = lc->chars[0] ? lc->chars[0] : zero_char; - if (include_cc && lc->count > 1) memcpy(buf + 1, lc->chars + 1, lc->count - 1); + if (include_cc && lc->count > 1) { + memcpy(buf + 1, lc->chars + 1, (lc->count - 1) * sizeof(lc->chars[0])); + n += lc->count - 1; + } return n; }