From 96d231dfa52cdcdec91dbd71ae7402c84e1eb7f9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 16 Feb 2025 10:02:39 +0530 Subject: [PATCH] Use buffer size in cell_as_unicode_for_fallback as well --- kitty/fontconfig.c | 2 +- kitty/line.c | 4 ++-- kitty/lineops.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kitty/fontconfig.c b/kitty/fontconfig.c index a9a3008dd..83c2f63c0 100644 --- a/kitty/fontconfig.c +++ b/kitty/fontconfig.c @@ -505,7 +505,7 @@ create_fallback_face(PyObject UNUSED *base_face, const ListOfChars *lc, bool bol if (!emoji_presentation && bold) { AP(FcPatternAddInteger, FC_WEIGHT, FC_WEIGHT_BOLD, "weight"); } if (!emoji_presentation && italic) { AP(FcPatternAddInteger, FC_SLANT, FC_SLANT_ITALIC, "slant"); } if (emoji_presentation) { AP(FcPatternAddBool, FC_COLOR, true, "color"); } - size_t num = cell_as_unicode_for_fallback(lc, char_buf); + size_t num = cell_as_unicode_for_fallback(lc, char_buf, arraysz(char_buf)); add_charset(pat, num); d = _fc_match(pat); face_from_descriptor: diff --git a/kitty/line.c b/kitty/line.c index ccf163b73..ec127bd43 100644 --- a/kitty/line.c +++ b/kitty/line.c @@ -402,11 +402,11 @@ text_at(Line* self, Py_ssize_t xval) { } size_t -cell_as_unicode_for_fallback(const ListOfChars *lc, Py_UCS4 *buf) { +cell_as_unicode_for_fallback(const ListOfChars *lc, Py_UCS4 *buf, size_t sz) { size_t n = 1; buf[0] = lc->chars[0] ? lc->chars[0] : ' '; if (buf[0] != '\t') { - for (unsigned i = 1; i < lc->count; i++) { + for (unsigned i = 1; i < lc->count && n < sz; i++) { if (lc->chars[i] != VS15 && lc->chars[i] != VS16) buf[n++] = lc->chars[i]; } } else buf[0] = ' '; diff --git a/kitty/lineops.h b/kitty/lineops.h index 86d944e4f..70b362e8e 100644 --- a/kitty/lineops.h +++ b/kitty/lineops.h @@ -78,7 +78,7 @@ index_type next_char_pos(const Line *self, index_type x, index_type num); index_type prev_char_pos(const Line *self, index_type x, index_type num); bool line_as_ansi(Line *self, ANSILineState *s, index_type start_at, index_type stop_before, char_type prefix_char, bool skip_multiline_non_zero_lines) __attribute__((nonnull)); unsigned int line_length(Line *self); -size_t cell_as_unicode_for_fallback(const ListOfChars *lc, Py_UCS4 *buf); +size_t cell_as_unicode_for_fallback(const ListOfChars *lc, Py_UCS4 *buf, size_t sz); size_t cell_as_utf8_for_fallback(const ListOfChars *lc, char *buf); bool unicode_in_range(const Line *self, const index_type start, const index_type limit, const bool include_cc, const bool add_trailing_newline, const bool skip_zero_cells, bool skip_multiline_non_zero_lines, ANSIBuf*); PyObject* line_as_unicode(Line *, bool, ANSIBuf*);