This commit is contained in:
Kovid Goyal 2024-10-27 14:12:20 +05:30
parent 8dd6686c86
commit aae50f9a99
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 4 additions and 3 deletions

View file

@ -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;

View file

@ -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;
}
}