From aae50f9a99f1f09f2b748ec24439fe3536913529 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 27 Oct 2024 14:12:20 +0530 Subject: [PATCH] ... --- kitty/fonts.c | 5 +++-- kitty/text-cache.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/kitty/fonts.c b/kitty/fonts.c index 201548a0f..8e01705b2 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -1728,8 +1728,9 @@ get_fallback_font(PyObject UNUSED *self, PyObject *args) { int bold, italic; if (!PyArg_ParseTuple(args, "Upp", &text, &bold, &italic)) return NULL; GPUCell gpu_cell = {0}; - RAII_ListOfChars(lc); ensure_space_for_chars(&lc, PyUnicode_GetLength(text)); - if (!PyUnicode_AsUCS4(text, lc.chars, lc.count, 1)) return NULL; + RAII_ListOfChars(lc); lc.count = PyUnicode_GET_LENGTH(text); + ensure_space_for_chars(&lc, lc.count); + if (!PyUnicode_AsUCS4(text, lc.chars, lc.capacity, 1)) return NULL; if (bold) gpu_cell.attrs.bold = true; if (italic) gpu_cell.attrs.italic = true; FontGroup *fg = font_groups; diff --git a/kitty/text-cache.h b/kitty/text-cache.h index d3245fa42..87098aea1 100644 --- a/kitty/text-cache.h +++ b/kitty/text-cache.h @@ -36,7 +36,7 @@ ensure_space_for_chars(ListOfChars *lc, size_t count) { lc->capacity = count + LIST_OF_CHARS_STACK_SIZE; void *chars = malloc(lc->capacity * sizeof(lc->chars[0])); if (!chars) fatal("Out of memory allocating LCChars char space"); - memcpy(chars, lc->chars, MIN(lc->count, LIST_OF_CHARS_STACK_SIZE) * sizeof(lc->chars[0])); + memcpy(chars, lc->chars, LIST_OF_CHARS_STACK_SIZE * sizeof(lc->chars[0])); lc->chars = chars; } }