From 936c25e671f29686b34fa39a82b7b64f08a1af6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Fri, 21 Feb 2025 16:01:03 +0300 Subject: [PATCH] =?UTF-8?q?mdbx:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20assert-=D0=BF=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=BE=D0=BA=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D1=82?= =?UTF-8?q?=D0=BB=D0=BE=D0=B2=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=D0=B2=D0=BE=D0=B4=D1=8F=D1=89=D0=B8=D1=85?= =?UTF-8?q?=20=D0=BA=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BF=D0=BE=D0=BB=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8E/=D0=BF=D0=BE=D0=B2=D1=80=D0=B5=D0=B6?= =?UTF-8?q?=D0=B4=D0=B5=D0=BD=D0=B8=D1=8E=20=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=86.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cogs.h | 10 ++++++++-- src/tree-ops.c | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) 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. */