Index: src/btree.c ================================================================== --- src/btree.c +++ src/btree.c @@ -7519,17 +7519,11 @@ ** if sibling page iOld had the same page number as pNew, and if ** pCell really was a part of sibling page iOld (not a divider or ** 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[usableSize] -#endif + || !SQLITE_WITHIN(pCell,aOld,&aOld[usableSize]) ){ if( !leafCorrection ){ ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc); } if( cachedCellSize(&b,i)>pNew->minLocal ){ Index: src/malloc.c ================================================================== --- src/malloc.c +++ src/malloc.c @@ -356,11 +356,11 @@ ** would be much more complicated.) */ assert( scratchAllocOut>=1 && scratchAllocOut<=2 ); scratchAllocOut--; #endif - if( p>=sqlite3GlobalConfig.pScratch && ppNext = mem0.pScratchFree; @@ -392,11 +392,11 @@ /* ** TRUE if p is a lookaside memory allocation from db */ #ifndef SQLITE_OMIT_LOOKASIDE static int isLookaside(sqlite3 *db, void *p){ - return p>=db->lookaside.pStart && plookaside.pEnd; + return SQLITE_WITHIN(p, db->lookaside.pStart, db->lookaside.pEnd); } #else #define isLookaside(A,B) 0 #endif Index: src/sqliteInt.h ================================================================== --- src/sqliteInt.h +++ src/sqliteInt.h @@ -171,10 +171,25 @@ #else /* Generates a warning - but it always works */ # define SQLITE_INT_TO_PTR(X) ((void*)(X)) # define SQLITE_PTR_TO_INT(X) ((int)(X)) #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. */ #if defined(__GNUC__)