diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/btree.c | 8 | ||||
-rw-r--r-- | src/malloc.c | 4 | ||||
-rw-r--r-- | src/sqliteInt.h | 15 |
3 files changed, 18 insertions, 9 deletions
diff --git a/src/btree.c b/src/btree.c index 34ce8c359..1f279b55f 100644 --- a/src/btree.c +++ b/src/btree.c @@ -7521,13 +7521,7 @@ static int balance_nonroot( ** overflow cell), we can skip updating the pointer map entries. */ if( iOld>=nNew || pNew->pgno!=aPgno[iOld] -#ifdef HAVE_STDINT_H - || (intptr_t)pCell<(intptr_t)aOld - || (intptr_t)pCell>=(intptr_t)&aOld[usableSize] -#else - || pCell<aOld - || pCell>=&aOld[usableSize] -#endif + || !SQLITE_WITHIN(pCell,aOld,&aOld[usableSize]) ){ if( !leafCorrection ){ ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc); diff --git a/src/malloc.c b/src/malloc.c index a4968aaa2..2c493b932 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -358,7 +358,7 @@ void sqlite3ScratchFree(void *p){ scratchAllocOut--; #endif - if( p>=sqlite3GlobalConfig.pScratch && p<mem0.pScratchEnd ){ + if( SQLITE_WITHIN(p, sqlite3GlobalConfig.pScratch, mem0.pScratchEnd) ){ /* Release memory from the SQLITE_CONFIG_SCRATCH allocation */ ScratchFreeslot *pSlot; pSlot = (ScratchFreeslot*)p; @@ -394,7 +394,7 @@ void sqlite3ScratchFree(void *p){ */ #ifndef SQLITE_OMIT_LOOKASIDE static int isLookaside(sqlite3 *db, void *p){ - return p>=db->lookaside.pStart && p<db->lookaside.pEnd; + return SQLITE_WITHIN(p, db->lookaside.pStart, db->lookaside.pEnd); } #else #define isLookaside(A,B) 0 diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 0d477dc06..1f94bad7e 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -174,6 +174,21 @@ #endif /* +** The SQLITE_WITHIN(P,S,E) macro checks to see if pointer P points to +** something between S (inclusive) and E (exclusive). +** +** In other words, S is a buffer and E is a pointer to the first byte after +** the end of buffer S. This macro returns true if P points to something +** contained within the buffer S. +*/ +#if defined(HAVE_STDINT_H) +# define SQLITE_WITHIN(P,S,E) \ + ((uintptr_t)(P)>=(uintptr_h)(S) && (uintptr_t)(P)<(uintptr_t)(E)) +#else +# define SQLITE_WITHIN(P,S,E) ((P)>=(S) && (P)<(E)) +#endif + +/* ** A macro to hint to the compiler that a function should not be ** inlined. */ |