mdbx: use saturated pgno_add() to avoid overflows.

Change-Id: I70000a86a69c9b3399d0a2c345d57ca1908f2881
This commit is contained in:
Leo Yuriev
2017-07-26 10:28:09 +03:00
parent a9927e7214
commit 4f06a38a50
2 changed files with 12 additions and 6 deletions

View File

@@ -1195,3 +1195,8 @@ static __inline pgno_t bytes2pgno(const MDBX_env *env, size_t bytes) {
mdbx_assert(env, (env->me_psize >> env->me_psize2log) == 1);
return (pgno_t)(bytes >> env->me_psize2log);
}
static __inline pgno_t pgno_add(pgno_t base, pgno_t augend) {
assert(base <= MAX_PAGENO);
return (augend < MAX_PAGENO - base) ? base + augend : MAX_PAGENO;
}