From eec465704d24474627e223fb25916ab0d5f75564 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Tue, 28 Apr 2020 18:23:13 +0300 Subject: [PATCH] mdbx: fix div-by-zero while copy-with-compaction for non-resizeable DB. Change-Id: Ice7f5675c3b2864195874f2e3c4ade9148cad048 --- src/core.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/core.c b/src/core.c index dacedecf..786d7f1f 100644 --- a/src/core.c +++ b/src/core.c @@ -15233,19 +15233,15 @@ done: static __cold void compact_fixup_meta(MDBX_env *env, MDBX_meta *meta) { /* Calculate filesize taking in account shrink/growing thresholds */ - if (meta->mm_geo.next > meta->mm_geo.now) { - const pgno_t aligned = pgno_align2os_pgno( - env, - pgno_add(meta->mm_geo.next, - meta->mm_geo.grow - meta->mm_geo.next % meta->mm_geo.grow)); - meta->mm_geo.now = aligned; - } else if (meta->mm_geo.next < meta->mm_geo.now) { + if (meta->mm_geo.next != meta->mm_geo.now) { meta->mm_geo.now = meta->mm_geo.next; const pgno_t aligner = meta->mm_geo.grow ? meta->mm_geo.grow : meta->mm_geo.shrink; - const pgno_t aligned = pgno_align2os_pgno( - env, meta->mm_geo.next + aligner - meta->mm_geo.next % aligner); - meta->mm_geo.now = aligned; + if (aligner) { + const pgno_t aligned = pgno_align2os_pgno( + env, meta->mm_geo.next + aligner - meta->mm_geo.next % aligner); + meta->mm_geo.now = aligned; + } } if (meta->mm_geo.now < meta->mm_geo.lower)