/ Check-in [bf744b49]
Login

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

Overview
Comment:An alternative way of implementing the assert() that verifies the relative values of KeyInfo.nField+KeyInfo.nXField and the number of columns in a record. This version of the assert() only fires when the high-speed comparison routines are used - which is to say it only fires when the constraint actually matters.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tkt-f97c4637
Files: files | file ages | folders
SHA1: bf744b4908b096f301565f6a4ea8d56667c1d76a
User & Date: drh 2015-01-19 19:48:52
Context
2015-01-19
20:57
Fix the assert() of the previous check-in so that it works even when compiled without SQLITE_DEBUG. check-in: 38868f84 user: drh tags: tkt-f97c4637
19:48
An alternative way of implementing the assert() that verifies the relative values of KeyInfo.nField+KeyInfo.nXField and the number of columns in a record. This version of the assert() only fires when the high-speed comparison routines are used - which is to say it only fires when the constraint actually matters. check-in: bf744b49 user: drh tags: tkt-f97c4637
15:05
Enhance the command-line shell with the ability to set the SQLITE_TESTCTRL_NEVER_CORRUPT flag using: ".testctrl never_corrupt 1". check-in: 824328f9 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbeaux.c.

  3345   3345     if( desiredResult>0 && rc>0 ) return 1;
  3346   3346     if( CORRUPT_DB ) return 1;
  3347   3347     if( pKeyInfo->db->mallocFailed ) return 1;
  3348   3348     return 0;
  3349   3349   }
  3350   3350   #endif
  3351   3351   
         3352  +#if SQLITE_DEBUG
         3353  +/*
         3354  +** Count the number of fields (a.k.a. columns) in the record given by
         3355  +** pKey,nKey.  The verify that this count is less than or equal to the
         3356  +** limit given by pKeyInfo->nField + pKeyInfo->nXField.
         3357  +**
         3358  +** If this constraint is not satisfied, it means that the high-speed
         3359  +** vdbeRecordCompareInt() and vdbeRecordCompareString() routines will
         3360  +** not work correctly.  If this assert() ever fires, it probably means
         3361  +** that the KeyInfo.nField or KeyInfo.nXField values were computed
         3362  +** incorrectly.
         3363  +*/
         3364  +static void vdbeAssertFieldCountWithinLimits(
         3365  +  int nKey, const void *pKey,   /* The record to verify */ 
         3366  +  const KeyInfo *pKeyInfo       /* Compare size with this KeyInfo */
         3367  +){
         3368  +  int nField = 0;
         3369  +  u32 szHdr;
         3370  +  u32 idx;
         3371  +  u32 notUsed;
         3372  +  const unsigned char *aKey = (const unsigned char*)pKey;
         3373  +
         3374  +  if( CORRUPT_DB ) return;
         3375  +  idx = getVarint32(aKey, szHdr);
         3376  +  assert( szHdr<=nKey );
         3377  +  while( idx<szHdr ){
         3378  +    idx += getVarint32(aKey+idx, notUsed);
         3379  +    nField++;
         3380  +  }
         3381  +  assert( nField <= pKeyInfo->nField+pKeyInfo->nXField );
         3382  +}
         3383  +#endif
         3384  +
  3352   3385   /*
  3353   3386   ** Both *pMem1 and *pMem2 contain string values. Compare the two values
  3354   3387   ** using the collation sequence pColl. As usual, return a negative , zero
  3355   3388   ** or positive value if *pMem1 is less than, equal to or greater than 
  3356   3389   ** *pMem2, respectively. Similar in spirit to "rc = (*pMem1) - (*pMem2);".
  3357   3390   */
  3358   3391   static int vdbeCompareMemString(
................................................................................
  3756   3789     int serial_type = ((const u8*)pKey1)[1];
  3757   3790     int res;
  3758   3791     u32 y;
  3759   3792     u64 x;
  3760   3793     i64 v = pPKey2->aMem[0].u.i;
  3761   3794     i64 lhs;
  3762   3795   
         3796  +  vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo);
  3763   3797     assert( (*(u8*)pKey1)<=0x3F || CORRUPT_DB );
  3764   3798     switch( serial_type ){
  3765   3799       case 1: { /* 1-byte signed integer */
  3766   3800         lhs = ONE_BYTE_INT(aKey);
  3767   3801         testcase( lhs<0 );
  3768   3802         break;
  3769   3803       }
................................................................................
  3843   3877     int nKey1, const void *pKey1, /* Left key */
  3844   3878     UnpackedRecord *pPKey2        /* Right key */
  3845   3879   ){
  3846   3880     const u8 *aKey1 = (const u8*)pKey1;
  3847   3881     int serial_type;
  3848   3882     int res;
  3849   3883   
         3884  +  vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo);
  3850   3885     getVarint32(&aKey1[1], serial_type);
  3851   3886     if( serial_type<12 ){
  3852   3887       res = pPKey2->r1;      /* (pKey1/nKey1) is a number or a null */
  3853   3888     }else if( !(serial_type & 0x01) ){ 
  3854   3889       res = pPKey2->r2;      /* (pKey1/nKey1) is a blob */
  3855   3890     }else{
  3856   3891       int nCmp;