mdbx: fix mdbx_pnl_grow().

Change-Id: I414501381a0ffea91677d8e5ef696fa6f645001f
This commit is contained in:
Leonid Yuriev 2018-08-15 13:15:48 +03:00
parent 8b24c65119
commit d3e9626a15

View File

@ -692,18 +692,18 @@ static void mdbx_pnl_shrink(MDBX_PNL *ppl) {
* Return the PNL to the size growed by given number. * Return the PNL to the size growed by given number.
* [in,out] ppl Address of the PNL to grow. */ * [in,out] ppl Address of the PNL to grow. */
static int __must_check_result mdbx_pnl_grow(MDBX_PNL *ppl, size_t num) { static int __must_check_result mdbx_pnl_grow(MDBX_PNL *ppl, size_t num) {
MDBX_PNL idn = *ppl - 1; MDBX_PNL pl = *ppl - 1;
assert(idn[0] <= MDBX_PNL_MAX && idn[0] <= idn[-1]); assert(pl[1] <= MDBX_PNL_MAX && pl[1] <= pl[0]);
assert(num <= MDBX_PNL_MAX); assert(num <= MDBX_PNL_MAX);
num += *idn; num += pl[0];
if (unlikely(num > MDBX_PNL_MAX)) if (unlikely(num > MDBX_PNL_MAX))
return MDBX_TXN_FULL; return MDBX_TXN_FULL;
/* grow it */ /* grow it */
idn = realloc(idn, (num + 2) * sizeof(pgno_t)); pl = realloc(pl, (num + 2) * sizeof(pgno_t));
if (unlikely(!idn)) if (unlikely(!pl))
return MDBX_ENOMEM; return MDBX_ENOMEM;
*idn++ += (pgno_t)num; *pl = (pgno_t)num;
*ppl = idn; *ppl = pl + 1;
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }