]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add extra assert() statements trying to catch a Mem object in an inconsistent
authordrh <drh@noemail.net>
Sat, 1 Mar 2014 14:45:18 +0000 (14:45 +0000)
committerdrh <drh@noemail.net>
Sat, 1 Mar 2014 14:45:18 +0000 (14:45 +0000)
state.

FossilOrigin-Name: 4aeb3ae435c78070232fef21a147fde4e1c5cd31

manifest
manifest.uuid
src/vdbe.c
src/vdbeInt.h
src/vdbeaux.c
src/vdbemem.c

index 3686379a180e4689d5aca5f7412975f73fb5ba53..8fbb26ce51b9ce90baa6d314db1ac3f23fcd744b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C In\sthe\scommand-line\sshell\sadd\sthe\s(undocumented\sand\sunsupported)\s".eqp"\ncommand\sand\s-eqp\scommand-line\soption,\sto\scause\sEXPLAIN\sQUERY\sPLAN\sto\sbe\nrun\son\seach\sSQL\sstatement\sas\sit\sis\sevaluated.\s\sIntended\suse\sis\sfor\sanalysis\nof\sthe\squery\splanner.
-D 2014-02-28T20:47:24.221
+C Add\sextra\sassert()\sstatements\strying\sto\scatch\sa\sMem\sobject\sin\san\sinconsistent\nstate.
+D 2014-03-01T14:45:18.939
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -277,13 +277,13 @@ F src/update.c 5b3e74a03b3811e586b4f2b4cbd7c49f01c93115
 F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269
 F src/util.c c46c90459ef9bdc0c6c73803cf4c55425b4771cf
 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179
-F src/vdbe.c 6c8f28911e702151c8ef03c568db5a066d3a85d4
+F src/vdbe.c e9eda47b8d8410d35840589daf8f3177efa04478
 F src/vdbe.h 147027d6e8e667a63e87177a38e2b42c71fdacf8
-F src/vdbeInt.h 5286af9067cabdb8ba57b87c0c988a931be6c6c8
+F src/vdbeInt.h fa0cadb90633d260f0c7d21f68a2ec5b1c6900e2
 F src/vdbeapi.c 5bc41aaea448a7fc250902c418f1795859be3820
-F src/vdbeaux.c 8b8eeb3cd89e4b3d4f40186344915b49b7c1c0f7
+F src/vdbeaux.c 087e7c75643157a903c9794294f4ff45cec28e7e
 F src/vdbeblob.c d939997de046b8fcc607cfee4248f3d33dbcca50
-F src/vdbemem.c 06603e8e9d2f3247b68c6bbe4bd37fb6721b5bda
+F src/vdbemem.c 7db453561091f0ed8fc7c96ee635cc612334025f
 F src/vdbesort.c 9d83601f9d6243fe70dd0169a2820c5ddfd48147
 F src/vdbetrace.c 6f52bc0c51e144b7efdcfb2a8f771167a8816767
 F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd
@@ -1152,7 +1152,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
-P 0a3579d9b9d2a60bb85a9811bc7936edb88debae
-R 195e6e751f71ffa9e9cfd28d6f8e532d
+P e6ecf7337658624d664e1e71ba3fc527fd6578c1
+R ac78e315b388dc3aeb5c2c8983219f64
+T *branch * enhanced-mem-check
+T *sym-enhanced-mem-check *
+T -sym-trunk *
 U drh
-Z d48791979092ee78fb00c8a21c663b3b
+Z 099f8256c2a0fcf00ebef2162229fe0b
index 6108cf5bede92e5dc215a58523ae639eff19ccbf..aa3e8c1f3c66f2475755c7a9fa78597b4e530cc1 100644 (file)
@@ -1 +1 @@
-e6ecf7337658624d664e1e71ba3fc527fd6578c1
\ No newline at end of file
+4aeb3ae435c78070232fef21a147fde4e1c5cd31
\ No newline at end of file
index 5ab01276580fc0cb230f62128b02fdc969e82c6c..cca69092a2fbb30961b7c29f2819864f6a94528a 100644 (file)
@@ -600,18 +600,21 @@ int sqlite3VdbeExec(
       assert( pOp->p1>0 );
       assert( pOp->p1<=(p->nMem-p->nCursor) );
       assert( memIsValid(&aMem[pOp->p1]) );
+      assert( memSanity1(&aMem[pOp->p1]) );
       REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
     }
     if( (pOp->opflags & OPFLG_IN2)!=0 ){
       assert( pOp->p2>0 );
       assert( pOp->p2<=(p->nMem-p->nCursor) );
       assert( memIsValid(&aMem[pOp->p2]) );
+      assert( memSanity1(&aMem[pOp->p2]) );
       REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
     }
     if( (pOp->opflags & OPFLG_IN3)!=0 ){
       assert( pOp->p3>0 );
       assert( pOp->p3<=(p->nMem-p->nCursor) );
       assert( memIsValid(&aMem[pOp->p3]) );
+      assert( memSanity1(&aMem[pOp->p3]) );
       REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
     }
     if( (pOp->opflags & OPFLG_OUT2)!=0 ){
@@ -2460,6 +2463,7 @@ case OP_Column: {
   */
   assert( p2<pC->nHdrParsed );
   assert( rc==SQLITE_OK );
+  assert( memSanity1(pDest) );
   if( pC->szRow>=aOffset[p2+1] ){
     /* This is the common case where the desired content fits on the original
     ** page - where the content is not on an overflow page */
index 88c072adece7800bee52b547435c5d1eb54617e8..56ea39ffc34a1daeb479063be9834135c63e1af0 100644 (file)
@@ -232,6 +232,24 @@ struct Mem {
 #define memIsValid(M)  ((M)->flags & MEM_Undefined)==0
 #endif
 
+/*
+** A sanity check on a Mem object and especially the Mem.z field.
+** This check says that no more than one of the following may be true:
+**   (1) Mem.z comes from Mem.zMalloc
+**   (2) Mem.z has a destructor Mem.xDel
+**   (3) Mem.z is an ephemeral string
+**   (4) Mem.z is a static string
+**
+** Use only inside of an assert() as follows:  assert( memSanify(pMem) );
+*/
+#ifdef SQLITE_DEBUG
+#define memSanity1(p)                                  \
+   ((((p)->zMalloc && (p)->zMalloc==(p)->z) ? 1 : 0) + \
+    ((((p)->flags&MEM_Dyn)&&(p)->xDel) ? 1 : 0) +      \
+    (((p)->flags&MEM_Ephem) ? 1 : 0) +                 \
+    (((p)->flags&MEM_Static) ? 1 : 0) <= 1 )
+#endif
+
 /*
 ** Each auxilliary data pointer stored by a user defined function 
 ** implementation calling sqlite3_set_auxdata() is stored in an instance
index ef70f8ae3f1848e28f6dca706a98f504e3240833..c22003f4618cec53a74d919afd2fad1d04850cc9 100644 (file)
@@ -1220,6 +1220,7 @@ static void releaseMemArray(Mem *p, int N){
     }
     for(pEnd=&p[N]; p<pEnd; p++){
       assert( (&p[1])==pEnd || p[0].db==p[1].db );
+      assert( memSanity1(p) );
 
       /* This block is really an inlined version of sqlite3VdbeMemRelease()
       ** that takes advantage of the fact that the memory cell value is 
index bcf9586b3fe859352e8db07e67443a7f93a2030c..6a34d3bbc3df7136b7cf04c994d51979d9e73d73 100644 (file)
@@ -67,12 +67,7 @@ int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){
 ** in pMem->z is discarded.
 */
 int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
-  assert( 1 >=
-    ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) +
-    (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) + 
-    ((pMem->flags&MEM_Ephem) ? 1 : 0) + 
-    ((pMem->flags&MEM_Static) ? 1 : 0)
-  );
+  assert( memSanity1(pMem) );
   assert( (pMem->flags&MEM_RowSet)==0 );
 
   /* If the bPreserve flag is set to true, then the memory cell must already
@@ -292,6 +287,7 @@ void sqlite3VdbeMemReleaseExternal(Mem *p){
 ** (Mem.memType==MEM_Str).
 */
 void sqlite3VdbeMemRelease(Mem *p){
+  assert( memSanity1(p) );
   VdbeMemRelease(p);
   if( p->zMalloc ){
     sqlite3DbFree(p->db, p->zMalloc);