diff --git a/src/cogs.h b/src/cogs.h index 11d7fe1d..bfb918e5 100644 --- a/src/cogs.h +++ b/src/cogs.h @@ -246,9 +246,15 @@ MDBX_NOTHROW_PURE_FUNCTION static inline const page_t *data_page(const void *dat MDBX_NOTHROW_PURE_FUNCTION static inline meta_t *page_meta(page_t *mp) { return (meta_t *)page_data(mp); } -MDBX_NOTHROW_PURE_FUNCTION static inline size_t page_numkeys(const page_t *mp) { return mp->lower >> 1; } +MDBX_NOTHROW_PURE_FUNCTION static inline size_t page_numkeys(const page_t *mp) { + assert(mp->lower <= mp->upper); + return mp->lower >> 1; +} -MDBX_NOTHROW_PURE_FUNCTION static inline size_t page_room(const page_t *mp) { return mp->upper - mp->lower; } +MDBX_NOTHROW_PURE_FUNCTION static inline size_t page_room(const page_t *mp) { + assert(mp->lower <= mp->upper); + return mp->upper - mp->lower; +} MDBX_NOTHROW_PURE_FUNCTION static inline size_t page_space(const MDBX_env *env) { STATIC_ASSERT(PAGEHDRSZ % 2 == 0); diff --git a/src/tree-ops.c b/src/tree-ops.c index cb5c02b3..b4d76d04 100644 --- a/src/tree-ops.c +++ b/src/tree-ops.c @@ -1228,6 +1228,7 @@ int page_split(MDBX_cursor *mc, const MDBX_val *const newkey, MDBX_val *const ne /* root split? */ prev_top += mc->top - top; + cASSERT(mn, prev_top <= mn->top && prev_top <= mc->top); /* Right page might now have changed parent. * Check if left page also changed parent. */