Fix bug pointed out by ASAN

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

View file

@ -703,7 +703,8 @@ static CTFontRef nerd_font(CGFloat sz) {
static void
finalize(void) {
free(ft_buffer.buf); free(buffers.render_buf); free(buffers.glyphs); free(buffers.boxes); free(buffers.positions);
free(ft_buffer.buf); ft_buffer.buf = NULL; ft_buffer.capacity = 0;
free(buffers.render_buf); free(buffers.glyphs); free(buffers.boxes); free(buffers.positions);
memset(&buffers, 0, sizeof(struct RenderBuffers));
if (all_fonts_collection_data) CFRelease(all_fonts_collection_data);
if (window_title_font) CFRelease(window_title_font);

View file

@ -79,8 +79,8 @@ tc_first_char_at_index(const TextCache *self, char_type idx) {
void
tc_chars_at_index(const TextCache *self, char_type idx, ListOfChars *ans) {
if (self->array.count > idx) {
ensure_space_for_chars(ans, self->array.items[idx].count);
ans->count = self->array.items[idx].count;
ensure_space_for_chars(ans, ans->count);
memcpy(ans->chars, self->array.items[idx].chars, sizeof(ans->chars[0]) * ans->count);
} else {
ans->count = 0;

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, lc->count * sizeof(lc->chars[0]));
memcpy(chars, lc->chars, MIN(lc->count, LIST_OF_CHARS_STACK_SIZE) * sizeof(lc->chars[0]));
lc->chars = chars;
}
}