From 72731832cfedb1ab575965e8d9b1d635ec493752 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Fri, 16 Oct 2026 06:17:03 -1000 Subject: Read and write slot keys and pages in full xread and xwrite may move fewer bytes than asked. A short write of the key left a slot that could never match, a short read of it reported a collision, and a page write that moved nothing looped for ever. --- source/cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/cache.c') diff --git a/source/cache.c b/source/cache.c index 60e071b..af391db 100644 --- a/source/cache.c +++ b/source/cache.c @@ -85,7 +85,7 @@ static int open_slot(struct cache_slot *slot) if (fstat(slot->cache_fd, &slot->st)) return errno; - slot->buflen = xread(slot->cache_fd, slot->buf, sizeof(slot->buf)); + slot->buflen = read_in_full(slot->cache_fd, slot->buf, sizeof(slot->buf)); if (slot->buflen < 0) return errno; @@ -265,7 +265,7 @@ static int lock_slot(struct cache_slot *slot) // start from empty now that nobody else can be writing it. if (ftruncate(slot->lock_fd, 0) < 0) return errno; - if (xwrite(slot->lock_fd, slot->key, slot->keylen + 1) < 0) + if (write_in_full(slot->lock_fd, slot->key, slot->keylen + 1) < 0) return errno; return 0; } -- cgit