From 7d00ba404e3f7ae703503df765cfa04a6bc7d34f Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 5 Dec 2013 12:40:01 +0000 Subject: [PATCH] Fix resizing of statfiles. --- src/statfile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/statfile.c b/src/statfile.c index 9cc2d58f36..b4771ce15e 100644 --- a/src/statfile.c +++ b/src/statfile.c @@ -235,7 +235,7 @@ statfile_pool_reindex (statfile_pool_t * pool, gchar *filename, size_t old_size, } pos = map + (sizeof (struct stat_file) - sizeof (struct stat_file_block)); - while (pos - map < (gint)old_size) { + while (old_size - (pos - map) >= sizeof (block)) { block = (struct stat_file_block *)pos; if (block->hash1 != 0 && block->value != 0) { statfile_pool_set_block_common (pool, new, block->hash1, block->hash2, 0, block->value, FALSE); @@ -307,7 +307,8 @@ statfile_pool_open (statfile_pool_t * pool, gchar *filename, size_t size, gboole } memory_pool_lock_mutex (pool->lock); - if (!forced && size != (size_t)st.st_size && size > sizeof (struct stat_file)) { + if (!forced && labs (size - st.st_size) > (long)sizeof (struct stat_file) * 2 + && size > sizeof (struct stat_file)) { memory_pool_unlock_mutex (pool->lock); msg_warn ("need to reindex statfile old size: %Hz, new size: %Hz", st.st_size, size); return statfile_pool_reindex (pool, filename, st.st_size, size); -- 2.47.3