From: drh Date: Mon, 26 Nov 2007 13:36:00 +0000 (+0000) Subject: Additional out-of-memory testing. Fix bugs caused by malloc failures in X-Git-Tag: version-3.6.10~1617 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f998b730ddd72c3f623e814f8579aa17237f4e28;p=thirdparty%2Fsqlite.git Additional out-of-memory testing. Fix bugs caused by malloc failures in where.c. Tickets #2794, #2795, #2796, and #2797. (CVS 4560) FossilOrigin-Name: 5e02dbabcfa42173adff234c086df1e962824c92 --- diff --git a/manifest b/manifest index 8ec70fa916..5acaee6ffb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Declare\sthe\sinvalidateCursorsOnModifiedBtrees\sfunction\sto\sbe\sstatic.\nTicket\s#2792.\s(CVS\s4559) -D 2007-11-24T10:23:45 +C Additional\sout-of-memory\stesting.\s\sFix\sbugs\scaused\sby\smalloc\sfailures\sin\nwhere.c.\s\sTickets\s#2794,\s#2795,\s#2796,\sand\s#2797.\s(CVS\s4560) +D 2007-11-26T13:36:00 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7 F Makefile.in 35396fd58890420b29edcf27b6c0e2d054862a6b F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -175,10 +175,10 @@ F src/vdbeblob.c 82f51cdf9b0c0af729732fde48c824e498c0a1ca F src/vdbefifo.c 334c838c8f42d61a94813d136019ee566b5dc2f6 F src/vdbemem.c 123994fcd344993d2fb050a83b91b341bbbd08b4 F src/vtab.c f819d55ef638d45e09ce00009d435da8bf16f528 -F src/where.c ddcbc5c419e9851906c9a9e76839086c98e7cea4 +F src/where.c 82e2cb76d7e15d79a5b19eaef23284c31868d4ee F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 -F test/all.test f069885276df58fa2876bb54b3f9bd379eafa919 +F test/all.test 23c2231ff0361b86cd7278d107208646bbc20196 F test/alter.test a87b7933d41c713c53341abe4eb014d0e273119e F test/alter2.test 4e0c502214daa710a0a9d7ec9689a0326b1a4e2a F test/alter3.test 8ce6b9c5605b3cfe7b901f454ecaf174c4f93e31 @@ -365,10 +365,12 @@ F test/malloc7.test 0d71bb6520b99934b551fa36a9c591404aeaad61 F test/malloc8.test addc27d907fec1af429551b95c72caa47fce2974 F test/malloc9.test 95d7069ad4fa262bf33bc4c5ca0a46f2bb2391cb F test/mallocA.test 5ee8d42ff90e5b1aeee6fb645e73ffcb35bffd21 +F test/mallocAll.test 2a2222a5e447be6c6579055a9a26e507e4586f4e F test/mallocB.test 83bdbea443cc81758a57b0287807b0941218819a F test/mallocC.test 6f02fa2b4baa943bc6d6db323d5d07067967e728 F test/mallocD.test d638fb8f214b47fd31edfae8af738b92bd943dc0 F test/mallocE.test e15333c394d7c330c8372a7cdf7b0f7c16573082 +F test/mallocF.test 249860dd3357fe37855f8b86e105953457795e24 F test/malloc_common.tcl b47137fb36e95fdafb0267745afefcd6b0a5b9dc F test/manydb.test 8de36b8d33aab5ef295b11d9e95310aeded31af8 F test/memdb.test a67bda4ff90a38f2b19f6c7f95aa7289e051d893 @@ -397,7 +399,7 @@ F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47 F test/printf.test 6bf1a86c6a1e45536f72d782bf44c8e3c76510f8 F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 x F test/ptrchng.test 38ae1806833d72d9a81a6121322e274f24937e18 -F test/quick.test 18727c9a480fe87143c5e7f381a38df8d1203d44 +F test/quick.test e4aa7c0c4fb6085ad7a3921da98741b5ce824633 F test/quote.test 215897dbe8de1a6f701265836d6601cc6ed103e6 F test/rdonly.test b34db316525440d3b42c32e83942c02c37d28ef0 F test/reindex.test 38b138abe36bf9a08c791ed44d9f76cd6b97b78b @@ -590,7 +592,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 -P 0fc61f99b54bd269fcc011f448b9b971e902cb01 -R a314c7a29cbfffced0c652613fe340e1 +P 94f25fc1129c7fb8697a67e509ab9de54a173a58 +R 6d662c50cad0936ec8482eb8accdbc47 U drh -Z ef78acb28db3ec4e15d6c19b7209bfc1 +Z c43df1a7af430a19f4c80905dfdc39c8 diff --git a/manifest.uuid b/manifest.uuid index 475fd0f03c..6eb59de5ce 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -94f25fc1129c7fb8697a67e509ab9de54a173a58 \ No newline at end of file +5e02dbabcfa42173adff234c086df1e962824c92 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 1a0142e809..dc918f6088 100644 --- a/src/where.c +++ b/src/where.c @@ -16,7 +16,7 @@ ** so is applicable. Because this module is responsible for selecting ** indices, you might also think of this module as the "query optimizer". ** -** $Id: where.c,v 1.262 2007/11/05 05:12:53 danielk1977 Exp $ +** $Id: where.c,v 1.263 2007/11/26 13:36:00 drh Exp $ */ #include "sqliteInt.h" @@ -234,6 +234,7 @@ static int whereClauseInsert(WhereClause *pWC, Expr *p, int flags){ if( flags & TERM_DYNAMIC ){ sqlite3ExprDelete(p); } + pWC->a = pOld; return 0; } memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm); @@ -552,7 +553,10 @@ static int isLikeOrGlob( } sqlite3DequoteExpr(db, pRight); z = (char *)pRight->token.z; - for(cnt=0; (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2]; cnt++){} + cnt = 0; + if( z ){ + while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){ cnt++; } + } if( cnt==0 || 255==(u8)z[cnt] ){ return 0; } @@ -707,9 +711,9 @@ static void exprAnalyze( WhereClause *pWC, /* the WHERE clause */ int idxTerm /* Index of the term to be analyzed */ ){ - WhereTerm *pTerm = &pWC->a[idxTerm]; - ExprMaskSet *pMaskSet = pWC->pMaskSet; - Expr *pExpr = pTerm->pExpr; + WhereTerm *pTerm; + ExprMaskSet *pMaskSet; + Expr *pExpr; Bitmask prereqLeft; Bitmask prereqAll; int nPattern; @@ -718,7 +722,12 @@ static void exprAnalyze( Parse *pParse = pWC->pParse; sqlite3 *db = pParse->db; - if( db->mallocFailed ) return; + if( db->mallocFailed ){ + return; + } + pTerm = &pWC->a[idxTerm]; + pMaskSet = pWC->pMaskSet; + pExpr = pTerm->pExpr; prereqLeft = exprTableUsage(pMaskSet, pExpr->pLeft); op = pExpr->op; if( op==TK_IN ){ @@ -895,7 +904,7 @@ or_not_possible: pStr1->flags = EP_Dequoted; } pStr2 = sqlite3ExprDup(db, pStr1); - if( pStr2 ){ + if( !db->mallocFailed ){ assert( pStr2->token.dyn ); ++*(u8*)&pStr2->token.z[nPattern-1]; } diff --git a/test/all.test b/test/all.test index 8445285f0f..bc39a7e7aa 100644 --- a/test/all.test +++ b/test/all.test @@ -10,7 +10,7 @@ #*********************************************************************** # This file runs all tests. # -# $Id: all.test,v 1.50 2007/11/23 18:19:22 drh Exp $ +# $Id: all.test,v 1.51 2007/11/26 13:36:00 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -65,6 +65,7 @@ lappend EXCLUDE memleak.test ;# Alternate test driver script lappend EXCLUDE fuzz.test lappend EXCLUDE soak.test ;# Takes a very long time (default 1 hr) lappend EXCLUDE fts3.test ;# Wrapper for muliple fts3*.tests +lappend EXCLUSE mallocAll.test ;# Wrapper for running all malloc tests # Files to include in the test. If this list is empty then everything # that is not in the EXCLUDE list is run. diff --git a/test/mallocAll.test b/test/mallocAll.test new file mode 100644 index 0000000000..5fbd849596 --- /dev/null +++ b/test/mallocAll.test @@ -0,0 +1,67 @@ +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file runs all out-of-memory tests. +# +# $Id: mallocAll.test,v 1.1 2007/11/26 13:36:00 drh Exp $ + +proc lshift {lvar} { + upvar $lvar l + set ret [lindex $l 0] + set l [lrange $l 1 end] + return $ret +} +while {[set arg [lshift argv]] != ""} { + switch -- $arg { + -sharedpagercache { + sqlite3_enable_shared_cache 1 + } + default { + set argv [linsert $argv 0 $arg] + break + } + } +} + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +rename finish_test really_finish_test +proc finish_test {} {} +set ISQUICK 1 + +set EXCLUDE { + mallocAll.test +} + +if {[sqlite3 -has-codec]} { + # lappend EXCLUDE \ + # conflict.test +} + + +# Files to include in the test. If this list is empty then everything +# that is not in the EXCLUDE list is run. +# +set INCLUDE { +} + +foreach testfile [lsort -dictionary [glob $testdir/*malloc*.test]] { + set tail [file tail $testfile] + if {[lsearch -exact $EXCLUDE $tail]>=0} continue + if {[llength $INCLUDE]>0 && [lsearch -exact $INCLUDE $tail]<0} continue + source $testfile + catch {db close} + if {$sqlite_open_file_count>0} { + puts "$tail did not close all files: $sqlite_open_file_count" + incr nErr + lappend ::failList $tail + set sqlite_open_file_count 0 + } +} +source $testdir/misuse.test + +set sqlite_open_file_count 0 +really_finish_test diff --git a/test/mallocF.test b/test/mallocF.test new file mode 100644 index 0000000000..d68cd41ab6 --- /dev/null +++ b/test/mallocF.test @@ -0,0 +1,64 @@ +# 2007 Aug 29 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This test script checks that tickets #2794, #2795, #2796, and #2797 +# have been fixed. +# +# $Id: mallocF.test,v 1.1 2007/11/26 13:36:00 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Only run these tests if memory debugging is turned on. +# +ifcapable !memdebug { + puts "Skipping mallocE tests: not compiled with -DSQLITE_MEMDEBUG..." + finish_test + return +} +source $testdir/malloc_common.tcl + +# tickets #2794 and #2795 and #2797 +# +set PREP { + CREATE TABLE t1(x,y); + INSERT INTO t1 VALUES('abc123', 5); + INSERT INTO t1 VALUES('xyz987', 42); +} +do_malloc_test malloeF-1 -sqlprep $PREP -sqlbody { + SELECT * FROM t1 WHERE x GLOB 'abc*' +} + +# ticket #2796 +# +set PREP { + CREATE TABLE t1(x PRIMARY KEY,y UNIQUE); + INSERT INTO t1 VALUES('abc123', 5); + INSERT INTO t1 VALUES('xyz987', 42); +} +do_malloc_test malloeF-2 -sqlprep $PREP -sqlbody { + SELECT x FROM t1 + WHERE y=1 OR y=2 OR y=3 OR y=4 OR y=5 + OR y=6 OR y=7 OR y=8 OR y=9 OR y=10 + OR y=11 OR y=12 OR y=13 OR y=14 OR y=15 + OR y=x +} + +set PREP { + CREATE TABLE t1(x PRIMARY KEY,y UNIQUE); + INSERT INTO t1 VALUES('abc123', 5); + INSERT INTO t1 VALUES('xyz987', 42); +} +do_malloc_test malloeF-3 -sqlprep $PREP -sqlbody { + SELECT x FROM t1 WHERE y BETWEEN 10 AND 29 +} + +finish_test diff --git a/test/quick.test b/test/quick.test index 6b33e8b4c3..e8aa430f29 100644 --- a/test/quick.test +++ b/test/quick.test @@ -6,7 +6,7 @@ #*********************************************************************** # This file runs all tests. # -# $Id: quick.test,v 1.66 2007/11/23 17:31:19 drh Exp $ +# $Id: quick.test,v 1.67 2007/11/26 13:36:00 drh Exp $ proc lshift {lvar} { upvar $lvar l @@ -54,6 +54,7 @@ set EXCLUDE { fuzz_malloc.test in2.test loadext.test + mallocAll.test malloc.test malloc2.test malloc3.test