From 5cdfc49ba0de3a883a88df2ce3865036e124af8f Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 16 Mar 2022 03:07:40 +0000 Subject: [PATCH] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 7 ++++--- source/libs/tdb/src/inc/tdbUtil.h | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index c96f109bad..392cdbd9db 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -233,10 +233,13 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *p c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen); if (c < 0) { /* TODO */ + ASSERT(0); } else if (c > 0) { /* TODO */ + ASSERT(0); } else { /* TODO */ + ASSERT(0); } } } @@ -797,9 +800,7 @@ static int tdbBtreeDecodePayload(SPage *pPage, const u8 *pPayload, SCellDecoder if (!pDecoder->pVal) { pDecoder->pVal = (void *)(pPayload + pDecoder->kLen); } - } - - { + } else { // TODO: handle overflow case ASSERT(0); } diff --git a/source/libs/tdb/src/inc/tdbUtil.h b/source/libs/tdb/src/inc/tdbUtil.h index 4dd917e0d1..9576ee6d15 100644 --- a/source/libs/tdb/src/inc/tdbUtil.h +++ b/source/libs/tdb/src/inc/tdbUtil.h @@ -62,19 +62,20 @@ static inline int tdbGetVarInt(const u8 *p, int *v) { int tv = 0; for (;;) { - if (p[n] & 0x80 == 0) { - tv = (tv << 7) & p[n]; + if (p[n] <= 0x7f) { + tv = (tv << 7) | p[n]; n++; break; } - tv = (tv << 7) & (p[n] & 0x7f); + tv = (tv << 7) | (p[n] & 0x7f); n++; } ASSERT(n < 6); - return 0; + *v = tv; + return n; } #ifdef __cplusplus