1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Add extra assert() statements trying to catch a Mem object in an inconsistent

state.

FossilOrigin-Name: 4aeb3ae435c78070232fef21a147fde4e1c5cd31
This commit is contained in:
drh
2014-03-01 14:45:18 +00:00
parent efbf3b1a10
commit defbd9dade
6 changed files with 38 additions and 16 deletions

View File

@@ -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. C Add\sextra\sassert()\sstatements\strying\sto\scatch\sa\sMem\sobject\sin\san\sinconsistent\nstate.
D 2014-02-28T20:47:24.221 D 2014-03-01T14:45:18.939
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81 F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -277,13 +277,13 @@ F src/update.c 5b3e74a03b3811e586b4f2b4cbd7c49f01c93115
F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269 F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269
F src/util.c c46c90459ef9bdc0c6c73803cf4c55425b4771cf F src/util.c c46c90459ef9bdc0c6c73803cf4c55425b4771cf
F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179
F src/vdbe.c 6c8f28911e702151c8ef03c568db5a066d3a85d4 F src/vdbe.c e9eda47b8d8410d35840589daf8f3177efa04478
F src/vdbe.h 147027d6e8e667a63e87177a38e2b42c71fdacf8 F src/vdbe.h 147027d6e8e667a63e87177a38e2b42c71fdacf8
F src/vdbeInt.h 5286af9067cabdb8ba57b87c0c988a931be6c6c8 F src/vdbeInt.h fa0cadb90633d260f0c7d21f68a2ec5b1c6900e2
F src/vdbeapi.c 5bc41aaea448a7fc250902c418f1795859be3820 F src/vdbeapi.c 5bc41aaea448a7fc250902c418f1795859be3820
F src/vdbeaux.c 8b8eeb3cd89e4b3d4f40186344915b49b7c1c0f7 F src/vdbeaux.c 087e7c75643157a903c9794294f4ff45cec28e7e
F src/vdbeblob.c d939997de046b8fcc607cfee4248f3d33dbcca50 F src/vdbeblob.c d939997de046b8fcc607cfee4248f3d33dbcca50
F src/vdbemem.c 06603e8e9d2f3247b68c6bbe4bd37fb6721b5bda F src/vdbemem.c 7db453561091f0ed8fc7c96ee635cc612334025f
F src/vdbesort.c 9d83601f9d6243fe70dd0169a2820c5ddfd48147 F src/vdbesort.c 9d83601f9d6243fe70dd0169a2820c5ddfd48147
F src/vdbetrace.c 6f52bc0c51e144b7efdcfb2a8f771167a8816767 F src/vdbetrace.c 6f52bc0c51e144b7efdcfb2a8f771167a8816767
F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd
@@ -1152,7 +1152,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
P 0a3579d9b9d2a60bb85a9811bc7936edb88debae P e6ecf7337658624d664e1e71ba3fc527fd6578c1
R 195e6e751f71ffa9e9cfd28d6f8e532d R ac78e315b388dc3aeb5c2c8983219f64
T *branch * enhanced-mem-check
T *sym-enhanced-mem-check *
T -sym-trunk *
U drh U drh
Z d48791979092ee78fb00c8a21c663b3b Z 099f8256c2a0fcf00ebef2162229fe0b

View File

@@ -1 +1 @@
e6ecf7337658624d664e1e71ba3fc527fd6578c1 4aeb3ae435c78070232fef21a147fde4e1c5cd31

View File

@@ -600,18 +600,21 @@ int sqlite3VdbeExec(
assert( pOp->p1>0 ); assert( pOp->p1>0 );
assert( pOp->p1<=(p->nMem-p->nCursor) ); assert( pOp->p1<=(p->nMem-p->nCursor) );
assert( memIsValid(&aMem[pOp->p1]) ); assert( memIsValid(&aMem[pOp->p1]) );
assert( memSanity1(&aMem[pOp->p1]) );
REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]); REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
} }
if( (pOp->opflags & OPFLG_IN2)!=0 ){ if( (pOp->opflags & OPFLG_IN2)!=0 ){
assert( pOp->p2>0 ); assert( pOp->p2>0 );
assert( pOp->p2<=(p->nMem-p->nCursor) ); assert( pOp->p2<=(p->nMem-p->nCursor) );
assert( memIsValid(&aMem[pOp->p2]) ); assert( memIsValid(&aMem[pOp->p2]) );
assert( memSanity1(&aMem[pOp->p2]) );
REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]); REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
} }
if( (pOp->opflags & OPFLG_IN3)!=0 ){ if( (pOp->opflags & OPFLG_IN3)!=0 ){
assert( pOp->p3>0 ); assert( pOp->p3>0 );
assert( pOp->p3<=(p->nMem-p->nCursor) ); assert( pOp->p3<=(p->nMem-p->nCursor) );
assert( memIsValid(&aMem[pOp->p3]) ); assert( memIsValid(&aMem[pOp->p3]) );
assert( memSanity1(&aMem[pOp->p3]) );
REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]); REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
} }
if( (pOp->opflags & OPFLG_OUT2)!=0 ){ if( (pOp->opflags & OPFLG_OUT2)!=0 ){
@@ -2460,6 +2463,7 @@ case OP_Column: {
*/ */
assert( p2<pC->nHdrParsed ); assert( p2<pC->nHdrParsed );
assert( rc==SQLITE_OK ); assert( rc==SQLITE_OK );
assert( memSanity1(pDest) );
if( pC->szRow>=aOffset[p2+1] ){ if( pC->szRow>=aOffset[p2+1] ){
/* This is the common case where the desired content fits on the original /* This is the common case where the desired content fits on the original
** page - where the content is not on an overflow page */ ** page - where the content is not on an overflow page */

View File

@@ -232,6 +232,24 @@ struct Mem {
#define memIsValid(M) ((M)->flags & MEM_Undefined)==0 #define memIsValid(M) ((M)->flags & MEM_Undefined)==0
#endif #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 ** Each auxilliary data pointer stored by a user defined function
** implementation calling sqlite3_set_auxdata() is stored in an instance ** implementation calling sqlite3_set_auxdata() is stored in an instance

View File

@@ -1220,6 +1220,7 @@ static void releaseMemArray(Mem *p, int N){
} }
for(pEnd=&p[N]; p<pEnd; p++){ for(pEnd=&p[N]; p<pEnd; p++){
assert( (&p[1])==pEnd || p[0].db==p[1].db ); assert( (&p[1])==pEnd || p[0].db==p[1].db );
assert( memSanity1(p) );
/* This block is really an inlined version of sqlite3VdbeMemRelease() /* This block is really an inlined version of sqlite3VdbeMemRelease()
** that takes advantage of the fact that the memory cell value is ** that takes advantage of the fact that the memory cell value is

View File

@@ -67,12 +67,7 @@ int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){
** in pMem->z is discarded. ** in pMem->z is discarded.
*/ */
int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){ int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
assert( 1 >= assert( memSanity1(pMem) );
((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( (pMem->flags&MEM_RowSet)==0 ); assert( (pMem->flags&MEM_RowSet)==0 );
/* If the bPreserve flag is set to true, then the memory cell must already /* 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). ** (Mem.memType==MEM_Str).
*/ */
void sqlite3VdbeMemRelease(Mem *p){ void sqlite3VdbeMemRelease(Mem *p){
assert( memSanity1(p) );
VdbeMemRelease(p); VdbeMemRelease(p);
if( p->zMalloc ){ if( p->zMalloc ){
sqlite3DbFree(p->db, p->zMalloc); sqlite3DbFree(p->db, p->zMalloc);