/ Check-in [05bc4f92]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Move pointer range comparisons into a macro, where they can be dealt with in a more portable way.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 05bc4f920ce23da48d1da6cd36a956fd6fd7c862
User & Date: drh 2015-12-10 17:59:50
Context
2015-12-11
04:11
Fix a memory allocation bug introduced last week by check-in [a9e819082ba]. The bug only appears on systems where the size of a structure is not always a multiple of 8 - which in practice means only on 32-bit windows systems. check-in: 96d3e99f user: drh tags: trunk
2015-12-10
17:59
Move pointer range comparisons into a macro, where they can be dealt with in a more portable way. check-in: 05bc4f92 user: drh tags: trunk
15:09
Move pointer range comparisons into a macro, where they can be dealt with in a more portable way. Closed-Leaf check-in: ad3124c8 user: drh tags: stdint.h
2015-12-09
17:23
Further simplifications to the VDBE code generation logic that flow out of the previous check-in. check-in: 6a5dfe85 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  7517   7517         ** was either part of sibling page iOld (possibly an overflow cell), 
  7518   7518         ** or else the divider cell to the left of sibling page iOld. So,
  7519   7519         ** if sibling page iOld had the same page number as pNew, and if
  7520   7520         ** pCell really was a part of sibling page iOld (not a divider or
  7521   7521         ** overflow cell), we can skip updating the pointer map entries.  */
  7522   7522         if( iOld>=nNew
  7523   7523          || pNew->pgno!=aPgno[iOld]
  7524         -#ifdef HAVE_STDINT_H
  7525         -       || (intptr_t)pCell<(intptr_t)aOld
  7526         -       || (intptr_t)pCell>=(intptr_t)&aOld[usableSize]
  7527         -#else
  7528         -       || pCell<aOld
  7529         -       || pCell>=&aOld[usableSize]
  7530         -#endif
         7524  +       || !SQLITE_WITHIN(pCell,aOld,&aOld[usableSize])
  7531   7525         ){
  7532   7526           if( !leafCorrection ){
  7533   7527             ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc);
  7534   7528           }
  7535   7529           if( cachedCellSize(&b,i)>pNew->minLocal ){
  7536   7530             ptrmapPutOvflPtr(pNew, pCell, &rc);
  7537   7531           }

Changes to src/malloc.c.

   354    354       ** is outstanding at one time.  (This is only checked in the
   355    355       ** single-threaded case since checking in the multi-threaded case
   356    356       ** would be much more complicated.) */
   357    357       assert( scratchAllocOut>=1 && scratchAllocOut<=2 );
   358    358       scratchAllocOut--;
   359    359   #endif
   360    360   
   361         -    if( p>=sqlite3GlobalConfig.pScratch && p<mem0.pScratchEnd ){
          361  +    if( SQLITE_WITHIN(p, sqlite3GlobalConfig.pScratch, mem0.pScratchEnd) ){
   362    362         /* Release memory from the SQLITE_CONFIG_SCRATCH allocation */
   363    363         ScratchFreeslot *pSlot;
   364    364         pSlot = (ScratchFreeslot*)p;
   365    365         sqlite3_mutex_enter(mem0.mutex);
   366    366         pSlot->pNext = mem0.pScratchFree;
   367    367         mem0.pScratchFree = pSlot;
   368    368         mem0.nScratchFree++;
................................................................................
   390    390   }
   391    391   
   392    392   /*
   393    393   ** TRUE if p is a lookaside memory allocation from db
   394    394   */
   395    395   #ifndef SQLITE_OMIT_LOOKASIDE
   396    396   static int isLookaside(sqlite3 *db, void *p){
   397         -  return p>=db->lookaside.pStart && p<db->lookaside.pEnd;
          397  +  return SQLITE_WITHIN(p, db->lookaside.pStart, db->lookaside.pEnd);
   398    398   }
   399    399   #else
   400    400   #define isLookaside(A,B) 0
   401    401   #endif
   402    402   
   403    403   /*
   404    404   ** Return the size of a memory allocation previously obtained from

Changes to src/sqliteInt.h.

   169    169   # define SQLITE_INT_TO_PTR(X)  ((void*)(intptr_t)(X))
   170    170   # define SQLITE_PTR_TO_INT(X)  ((int)(intptr_t)(X))
   171    171   #else                          /* Generates a warning - but it always works */
   172    172   # define SQLITE_INT_TO_PTR(X)  ((void*)(X))
   173    173   # define SQLITE_PTR_TO_INT(X)  ((int)(X))
   174    174   #endif
   175    175   
          176  +/*
          177  +** The SQLITE_WITHIN(P,S,E) macro checks to see if pointer P points to
          178  +** something between S (inclusive) and E (exclusive).
          179  +**
          180  +** In other words, S is a buffer and E is a pointer to the first byte after
          181  +** the end of buffer S.  This macro returns true if P points to something
          182  +** contained within the buffer S.
          183  +*/
          184  +#if defined(HAVE_STDINT_H)
          185  +# define SQLITE_WITHIN(P,S,E) \
          186  +    ((uintptr_t)(P)>=(uintptr_t)(S) && (uintptr_t)(P)<(uintptr_t)(E))
          187  +#else
          188  +# define SQLITE_WITHIN(P,S,E) ((P)>=(S) && (P)<(E))
          189  +#endif
          190  +
   176    191   /*
   177    192   ** A macro to hint to the compiler that a function should not be
   178    193   ** inlined.
   179    194   */
   180    195   #if defined(__GNUC__)
   181    196   #  define SQLITE_NOINLINE  __attribute__((noinline))
   182    197   #elif defined(_MSC_VER) && _MSC_VER>=1310