Skip to content

Commit 6834e36

Browse files
committed
macOS: Fix a regression in the previous release that caused junk to be rendered in font previews in the choose fonts kitten and crash on Intel macs
Fixes #7892
1 parent 866c142 commit 6834e36

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ Detailed list of changes
8181

8282
- Wayland GNOME: Fix a crash when using multiple monitors with different scales and starting on or moving to the monitor with lower scale (:iss:`7894`)
8383

84+
- macOS: Fix a regression in the previous release that caused junk to be rendered in font previews in the choose fonts kitten and crash on Intel macs (:iss:`7892`)
85+
8486

8587
0.36.3 [2024-09-25]
8688
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

kitty/core_text.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -813,13 +813,13 @@ static CTFontRef nerd_font(CGFloat sz) {
813813
if (!PyArg_ParseTuple(args, "Ukk|k", &ptext, &canvas_width, &canvas_height, &fg)) return NULL;
814814
unsigned int cell_width, cell_height, baseline, underline_position, underline_thickness, strikethrough_position, strikethrough_thickness;
815815
cell_metrics((PyObject*)self, &cell_width, &cell_height, &baseline, &underline_position, &underline_thickness, &strikethrough_position, &strikethrough_thickness);
816-
RAII_PyObject(pbuf, PyBytes_FromStringAndSize(NULL, sizeof(pixel) * canvas_width * canvas_height));
817-
if (!pbuf) return NULL;
818-
memset(PyBytes_AS_STRING(pbuf), 0, PyBytes_GET_SIZE(pbuf));
819-
if (!cell_width || !cell_height) return Py_BuildValue("OII", pbuf, cell_width, cell_height);
816+
if (!cell_width || !cell_height) return Py_BuildValue("yII", "", cell_width, cell_height);
820817
size_t num_chars = PyUnicode_GET_LENGTH(ptext);
821818
int num_chars_per_line = canvas_width / cell_width, num_of_lines = (int)ceil((float)num_chars / (float)num_chars_per_line);
822819
canvas_height = MIN(canvas_height, num_of_lines * cell_height);
820+
RAII_PyObject(pbuf, PyBytes_FromStringAndSize(NULL, sizeof(pixel) * canvas_width * canvas_height));
821+
if (!pbuf) return NULL;
822+
memset(PyBytes_AS_STRING(pbuf), 0, PyBytes_GET_SIZE(pbuf));
823823

824824
__attribute__((cleanup(destroy_hb_buffer))) hb_buffer_t *hb_buffer = hb_buffer_create();
825825
if (!hb_buffer_pre_allocate(hb_buffer, 4*num_chars)) { PyErr_NoMemory(); return NULL; }
@@ -858,9 +858,10 @@ static CTFontRef nerd_font(CGFloat sz) {
858858
render_glyphs(font, canvas_width, canvas_height, baseline, num_glyphs);
859859
uint8_t r = (fg >> 16) & 0xff, g = (fg >> 8) & 0xff, b = fg & 0xff;
860860
const uint8_t *last_pixel = (uint8_t*)PyBytes_AS_STRING(pbuf) + PyBytes_GET_SIZE(pbuf) - sizeof(pixel);
861+
const uint8_t *s_limit = buffers.render_buf + canvas_width * canvas_height;
861862
for (
862863
uint8_t *p = (uint8_t*)PyBytes_AS_STRING(pbuf), *s = buffers.render_buf;
863-
p <= last_pixel;
864+
p <= last_pixel && s < s_limit;
864865
p += sizeof(pixel), s++
865866
) {
866867
p[0] = r; p[1] = g; p[2] = b; p[3] = s[0];

0 commit comments

Comments
 (0)