From 61ef28e975fd0afc04b6bc4411efa37d394843b1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 16 Feb 2025 10:21:40 +0530 Subject: [PATCH] Cleanup loop exit condition --- kitty/fonts.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kitty/fonts.c b/kitty/fonts.c index adb7dac40..bc822f02e 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -1109,9 +1109,9 @@ load_hb_buffer(CPUCell *first_cpu_cell, GPUCell *first_gpu_cell, index_type num_ for (num = 0; num_cells; first_cpu_cell++, first_gpu_cell++, num_cells--) { text_in_cell(first_cpu_cell, tc, lc); if (first_cpu_cell->is_multicell && first_cpu_cell->x) continue; - if (lc->count + num > arraysz(shape_buffer)) break; - memcpy(shape_buffer + num, lc->chars, lc->count * sizeof(shape_buffer[0])); - num += lc->count; + const size_t count = MIN(lc->count, arraysz(shape_buffer) - num); + memcpy(shape_buffer + num, lc->chars, count * sizeof(shape_buffer[0])); + num += count; } hb_buffer_add_utf32(harfbuzz_buffer, shape_buffer, num, 0, num); }