]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
An alternative way of implementing the assert() that verifies the relative
authordrh <drh@noemail.net>
Mon, 19 Jan 2015 19:48:52 +0000 (19:48 +0000)
committerdrh <drh@noemail.net>
Mon, 19 Jan 2015 19:48:52 +0000 (19:48 +0000)
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.

FossilOrigin-Name: bf744b4908b096f301565f6a4ea8d56667c1d76a

manifest
manifest.uuid
src/vdbeaux.c

index 136cb71f94a17113994c82f4612c0e438093c489..5e36253afb91a8878cc9fade73aa1139cd00c4fb 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Enhance\sthe\scommand-line\sshell\swith\sthe\sability\sto\sset\sthe\nSQLITE_TESTCTRL_NEVER_CORRUPT\sflag\susing:\s".testctrl\snever_corrupt\s1".
-D 2015-01-19T15:05:54.471
+C An\salternative\sway\sof\simplementing\sthe\sassert()\sthat\sverifies\sthe\srelative\nvalues\sof\sKeyInfo.nField+KeyInfo.nXField\sand\sthe\snumber\sof\scolumns\sin\sa\srecord.\nThis\sversion\sof\sthe\sassert()\sonly\sfires\swhen\sthe\shigh-speed\scomparison\nroutines\sare\sused\s-\swhich\sis\sto\ssay\sit\sonly\sfires\swhen\sthe\sconstraint\nactually\smatters.
+D 2015-01-19T19:48:52.667
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -296,7 +296,7 @@ F src/vdbe.c ddfc977981cd6324668aa6b114045eb1c677421a
 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3
 F src/vdbeInt.h 9bb69ff2447c34b6ccc58b34ec35b615f86ead78
 F src/vdbeapi.c 4bc511a46b9839392ae0e90844a71dc96d9dbd71
-F src/vdbeaux.c 07ef87c6d4b5abdf13ff33babb10205702fdab0a
+F src/vdbeaux.c d22d71f5928f0170061b6509b72832d307fb581e
 F src/vdbeblob.c 4af4bfb71f6df7778397b4a0ebc1879793276778
 F src/vdbemem.c 31d8eabb0cd78bfeab4e5124c7363c3e9e54db9f
 F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2
@@ -1236,7 +1236,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 10321910990195878c0af1e94b34ae0cdc0cb31b
-R 1842536563f5d094d57991d4a5161858
+P 824328f9833d01fc155a9d0265ef41d338cf1ffb
+R 62f359e43ad9aa835c85ab2bfc9c70b0
+T *branch * tkt-f97c4637
+T *sym-tkt-f97c4637 *
+T -sym-trunk *
 U drh
-Z b40ce48cd42cd2dd2358d0667c50be5c
+Z e1e735a41c0bcd1d69846f2fcc6f5b85
index a042232dda36b1bd4d3df51f24568bb976c9f9e1..eecb747ee65cadde84a6d675c19638a7fef7d432 100644 (file)
@@ -1 +1 @@
-824328f9833d01fc155a9d0265ef41d338cf1ffb
\ No newline at end of file
+bf744b4908b096f301565f6a4ea8d56667c1d76a
\ No newline at end of file
index 03c229c994a0bd08f621411933a234f4bc956bb4..b3f8278eb1218642da571efa53b78955d2283413 100644 (file)
@@ -3349,6 +3349,39 @@ debugCompareEnd:
 }
 #endif
 
+#if SQLITE_DEBUG
+/*
+** Count the number of fields (a.k.a. columns) in the record given by
+** pKey,nKey.  The verify that this count is less than or equal to the
+** limit given by pKeyInfo->nField + pKeyInfo->nXField.
+**
+** If this constraint is not satisfied, it means that the high-speed
+** vdbeRecordCompareInt() and vdbeRecordCompareString() routines will
+** not work correctly.  If this assert() ever fires, it probably means
+** that the KeyInfo.nField or KeyInfo.nXField values were computed
+** incorrectly.
+*/
+static void vdbeAssertFieldCountWithinLimits(
+  int nKey, const void *pKey,   /* The record to verify */ 
+  const KeyInfo *pKeyInfo       /* Compare size with this KeyInfo */
+){
+  int nField = 0;
+  u32 szHdr;
+  u32 idx;
+  u32 notUsed;
+  const unsigned char *aKey = (const unsigned char*)pKey;
+
+  if( CORRUPT_DB ) return;
+  idx = getVarint32(aKey, szHdr);
+  assert( szHdr<=nKey );
+  while( idx<szHdr ){
+    idx += getVarint32(aKey+idx, notUsed);
+    nField++;
+  }
+  assert( nField <= pKeyInfo->nField+pKeyInfo->nXField );
+}
+#endif
+
 /*
 ** Both *pMem1 and *pMem2 contain string values. Compare the two values
 ** using the collation sequence pColl. As usual, return a negative , zero
@@ -3760,6 +3793,7 @@ static int vdbeRecordCompareInt(
   i64 v = pPKey2->aMem[0].u.i;
   i64 lhs;
 
+  vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo);
   assert( (*(u8*)pKey1)<=0x3F || CORRUPT_DB );
   switch( serial_type ){
     case 1: { /* 1-byte signed integer */
@@ -3847,6 +3881,7 @@ static int vdbeRecordCompareString(
   int serial_type;
   int res;
 
+  vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo);
   getVarint32(&aKey1[1], serial_type);
   if( serial_type<12 ){
     res = pPKey2->r1;      /* (pKey1/nKey1) is a number or a null */