From: drh Date: Sat, 1 Mar 2014 14:45:18 +0000 (+0000) Subject: Add extra assert() statements trying to catch a Mem object in an inconsistent X-Git-Tag: version-3.8.4~38^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=defbd9dade8a135ebc79c14efafe1a22c0f99c94;p=thirdparty%2Fsqlite.git Add extra assert() statements trying to catch a Mem object in an inconsistent state. FossilOrigin-Name: 4aeb3ae435c78070232fef21a147fde4e1c5cd31 --- diff --git a/manifest b/manifest index 3686379a18..8fbb26ce51 100644 --- 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 diff --git a/manifest.uuid b/manifest.uuid index 6108cf5bed..aa3e8c1f3c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e6ecf7337658624d664e1e71ba3fc527fd6578c1 \ No newline at end of file +4aeb3ae435c78070232fef21a147fde4e1c5cd31 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 5ab0127658..cca69092a2 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -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( p2nHdrParsed ); 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 */ diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 88c072adec..56ea39ffc3 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -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 diff --git a/src/vdbeaux.c b/src/vdbeaux.c index ef70f8ae3f..c22003f461 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1220,6 +1220,7 @@ static void releaseMemArray(Mem *p, int N){ } for(pEnd=&p[N]; pz 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);