From c3869dc4794513b1f5817a38f72caef3318e71f9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 1 Mar 2024 11:07:51 +0530 Subject: [PATCH] ... --- kitty/disk-cache.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/kitty/disk-cache.c b/kitty/disk-cache.c index 2cfcb0704..9cd5c87cc 100644 --- a/kitty/disk-cache.c +++ b/kitty/disk-cache.c @@ -235,14 +235,17 @@ needs_defrag(DiskCache *self) { static void add_hole(DiskCache *self, off_t pos, off_t size) { if (size <= self->small_hole_threshold) return; - // see if we can find a hole that ends where we start and merge - // look through the prev at most 128 holes for a match - Hole *h = &self->holes.items[self->holes.count-1]; - for (size_t i = 0; i < MIN(self->holes.count, 128u); i++, h--) { - if (h->pos + h->size == pos) { - h->size += size; - self->holes.largest_hole_size = MAX(self->holes.largest_hole_size, h->size); - return; + Hole *h; + if (self->holes.count) { + // see if we can find a hole that ends where we start and merge + // look through the prev at most 128 holes for a match + h = &self->holes.items[self->holes.count-1]; + for (size_t i = 0; i < MIN(self->holes.count, 128u); i++, h--) { + if (h->pos + h->size == pos) { + h->size += size; + self->holes.largest_hole_size = MAX(self->holes.largest_hole_size, h->size); + return; + } } } ensure_space_for(&self->holes, items, Hole, 1, capacity, 64, false);