From 6a126fa18e78ecfef7b072b89018074adec340a4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 23 Jul 2019 10:18:09 +0530 Subject: [PATCH] Fix a crash when displaying very large number of images Fixes #1825 --- docs/changelog.rst | 2 ++ kitty/graphics.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 96e963875..8b6fd264c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -56,6 +56,8 @@ To update |kitty|, :doc:`follow the instructions `. - When using :opt:`strip_trailing_spaces` do not remove empty lines (:iss:`1802`) +- Fix a crash when displaying very large number of images (:iss:`1825`) + 0.14.2 [2019-06-09] --------------------- diff --git a/kitty/graphics.c b/kitty/graphics.c index 6d034ea36..74fcf29a8 100644 --- a/kitty/graphics.c +++ b/kitty/graphics.c @@ -260,7 +260,9 @@ find_or_create_image(GraphicsManager *self, uint32_t id, bool *existing) { } *existing = false; ensure_space_for(self, images, Image, self->image_count + 1, images_capacity, 64, true); - return self->images + self->image_count++; + Image *ans = self->images + self->image_count++; + memset(ans, 0, sizeof(ans[0])); + return ans; } @@ -490,7 +492,10 @@ handle_put_command(GraphicsManager *self, const GraphicsCommand *g, Cursor *c, b break; } } - if (ref == NULL) ref = img->refs + img->refcnt++; + if (ref == NULL) { + ref = img->refs + img->refcnt++; + memset(ref, 0, sizeof(ref[0])); + } img->atime = monotonic(); ref->src_x = g->x_offset; ref->src_y = g->y_offset; ref->src_width = g->width ? g->width : img->width; ref->src_height = g->height ? g->height : img->height; ref->src_width = MIN(ref->src_width, img->width - (img->width > ref->src_x ? ref->src_x : img->width)); @@ -563,6 +568,7 @@ grman_update_layers(GraphicsManager *self, unsigned int scrolled_by, float scree if (ref->z_index < 0) self->num_of_negative_refs++; else self->num_of_positive_refs++; ensure_space_for(self, render_data, ImageRenderData, self->count + 1, capacity, 64, true); ImageRenderData *rd = self->render_data + self->count; + memset(rd, 0, sizeof(rd[0])); set_vertex_data(rd, ref, &r); self->count++; rd->z_index = ref->z_index; rd->image_id = img->internal_id;