Fix cell_as_unicode

This commit is contained in:
Kovid Goyal 2024-10-26 13:34:28 +05:30
parent 1481fb4fe9
commit 7ff7947ab3
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 5 additions and 1 deletions

View file

@ -59,6 +59,7 @@ static inline PyObject* Py_XNewRef(PyObject *o) { Py_XINCREF(o); return o; }
typedef unsigned long long id_type;
typedef uint32_t char_type;
static_assert(sizeof(Py_UCS4) == sizeof(char_type), "PyUCS4 and char_type dont match");
#define MAX_CHAR_TYPE_VALUE UINT32_MAX
typedef uint32_t color_type;
typedef uint16_t hyperlink_id_type;

View file

@ -229,7 +229,10 @@ static size_t
cell_as_unicode(ListOfChars *lc, bool include_cc, Py_UCS4 *buf, char_type zero_char) {
size_t n = 1;
buf[0] = lc->chars[0] ? lc->chars[0] : zero_char;
if (include_cc && lc->count > 1) memcpy(buf + 1, lc->chars + 1, lc->count - 1);
if (include_cc && lc->count > 1) {
memcpy(buf + 1, lc->chars + 1, (lc->count - 1) * sizeof(lc->chars[0]));
n += lc->count - 1;
}
return n;
}