]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Additional coverage testing. Fix a segfault following OOM in
authordrh <drh@noemail.net>
Sat, 2 Aug 2008 03:50:39 +0000 (03:50 +0000)
committerdrh <drh@noemail.net>
Sat, 2 Aug 2008 03:50:39 +0000 (03:50 +0000)
sqltie3_load_extension(). (CVS 5523)

FossilOrigin-Name: f1e44eb323f05495cbae25113aebcc50d16b40df

22 files changed:
manifest
manifest.uuid
src/build.c
src/legacy.c
src/loadext.c
src/pager.c
src/prepare.c
src/select.c
src/sqliteInt.h
src/test_func.c
src/test_loadext.c
src/vdbeInt.h
src/vdbeapi.c
src/vdbeaux.c
src/vtab.c
test/autovacuum.test
test/limit.test
test/loadext.test
test/mallocI.test [new file with mode: 0644]
test/misc7.test
test/select5.test
test/vacuum3.test

index 5edee71f8c1910c07e01559507d9228e8f997b54..b0a696ef2781593a6fdd59352a65e8aa3922333f 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Bring\stest\scoverage\sup\sto\s99%.\s(CVS\s5522)
-D 2008-08-01T20:10:08
+C Additional\scoverage\stesting.\s\sFix\sa\ssegfault\sfollowing\sOOM\sin\nsqltie3_load_extension().\s(CVS\s5523)
+D 2008-08-02T03:50:39
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in bbb62eecc851379aef5a48a1bf8787eb13e6ec06
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -99,7 +99,7 @@ F src/btmutex.c 709cad2cdca0afd013f0f612363810e53f59ec53
 F src/btree.c 0be00cb6a5cd130127a06eb5f661cb5e4a9d0259
 F src/btree.h 03256ed7ee42b5ecacbe887070b0f8249e7d069d
 F src/btreeInt.h ab18c7b4980314e9e4b402e5dcde09f3c2545576
-F src/build.c 77d5518a64c0a905024bee80f6df2e794f4f5d43
+F src/build.c 05be60b1edc70bb8b354778facfb0ad5137c679a
 F src/callback.c c9f75a4c403f166af3761df47d78a806587d63af
 F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c
 F src/date.c 52a54811218a76da6235420f532ece841159a96d
@@ -113,8 +113,8 @@ F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53
 F src/hwtime.h 4a1d45f4cae1f402ea19686acf24acf4f0cb53cb
 F src/insert.c 89cd9af52a5ea6fb7d0cfc9c3b935d6406c360c4
 F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e
-F src/legacy.c 3635cc6a5889918086b3501de8287cbbecb55917
-F src/loadext.c 9ab55455f59dce0ae6388952216a1505ce7f9d13
+F src/legacy.c aac57bd984e666059011ea01ec4383892a253be3
+F src/loadext.c eb1fe4f44d7c8ff53fc0c6a4388ab79fbd34cd64
 F src/main.c 730c6f40379e2258718ee2e591a4ae091d4e26c6
 F src/malloc.c f0ad28008351cac2337ef502a3fdc8ffd3e5d9a9
 F src/md5.c 008216bbb5d34c6fbab5357aa68575ad8a31516a
@@ -135,18 +135,18 @@ F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60
 F src/os_os2.c 676ed273b17bd260f905df81375c9f9950d85517
 F src/os_unix.c fe0dbc35bcd3de49e46b132abfc0f45d6dd6a864
 F src/os_win.c aefe9ee26430678a19a058a874e4e2bd91398142
-F src/pager.c 6ad4d2b9b62a40f9ee898111d4519fec2e7c4796
+F src/pager.c b6a366f2343e7f127d7e70dbe76cd664336143cd
 F src/pager.h 588c1ac195228b2da45c4e5f7ab6c2fd253d1751
 F src/parse.y d962e544d9953289db23c1d4cc2dab514c7136fa
 F src/pragma.c 6e207b4f69901089758c02c02e0bf86ed12a4d8f
-F src/prepare.c d2d53aec81517f8666450aa5fd1a041a3b72320e
+F src/prepare.c d9f420808f7d2802258f0bf64103271311e2d87f
 F src/printf.c 2e984b2507291a7e16d89dc9bb60582904f6247d
 F src/random.c 5c754319d38abdd6acd74601ee0105504adc508a
-F src/select.c 95fb28783ef1342be8c6ee278c539309e29c010e
+F src/select.c 23106fd9a9618a832abaf5dc906c79dc21755edc
 F src/shell.c 4b835fe734304ac22a3385868cd3790c1e4f7aa1
 F src/sqlite.h.in 30af3a002a0b672aaae8f4a5deb0a2e9a4b699af
 F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e
-F src/sqliteInt.h 80fa4a46024dee8cb6c66a6f04a716c253d98165
+F src/sqliteInt.h 4c3a19206bacfab8650f2616bc0004c1dea7fbf3
 F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
 F src/status.c 8ad1f215934c5f5afb91df86e44dccff7ef3c1d0
 F src/table.c 22744786199c9195720c15a7a42cb97b2e2728d8
@@ -165,9 +165,9 @@ F src/test_autoext.c f53b0cdf7bf5f08100009572a5d65cdb540bd0ad
 F src/test_btree.c 7170e0c922ed3979f2d38f4a3f84728e5740dfc3
 F src/test_config.c 224f699a34d45eb8ac5c22a7ad6cdbb8edf0ba28
 F src/test_devsym.c 6012cb8e3acf812513511025a4fa5d626e0ba19b
-F src/test_func.c 94c4424ed9869ecf2e2132662a04581bbec016f6
+F src/test_func.c df7ddd5abfc5c8d6cd3e36ae9ecb0c276b0e9039
 F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f
-F src/test_loadext.c df8ab3a6481ddebbdf0d28ebac5d9e0790f7860f
+F src/test_loadext.c 97dc8800e46a46ed002c2968572656f37e9c0dd9
 F src/test_malloc.c 3919ed155da54a1ee1e06282a69fb8a035b2749f
 F src/test_md5.c 28209a4e2068711b5443c33104fe41f21d160071
 F src/test_mutex.c d3422d9f60cc1330249d102e74b333f0d24a0cb6
@@ -185,13 +185,13 @@ F src/util.c afe659ccc05d1f8af9e8631dabfec3ee3a7144af
 F src/vacuum.c ef342828002debc97514617af3424aea8ef8522c
 F src/vdbe.c a548d1dd6c5d99b2bd38e522aba2fa401340c99c
 F src/vdbe.h 647fcf33a551ba10a974162c56846cb9aef2276b
-F src/vdbeInt.h ab27f964458fd070c6660f80694ab85d56d5f4c5
-F src/vdbeapi.c 6a769ea6708f75b1e55268ec1c7bcf8e96fc7628
-F src/vdbeaux.c 81a433ce73b79df605cc9709af430362e771ecdc
+F src/vdbeInt.h 6f04c2bf65a0d5c2bb8318b226278a35d1f7a8f5
+F src/vdbeapi.c 803f365b77a22c1b2680a0dee9202bc75c02bf4a
+F src/vdbeaux.c 21126e0d319e19125f5e42fceafb17eafe58721c
 F src/vdbeblob.c f93110888ddc246215e9ba1f831d3d375bfd8355
 F src/vdbefifo.c 20fda2a7c4c0bcee1b90eb7e545fefcdbf2e1de7
 F src/vdbemem.c c37b2a266a49eaf0c0f5080157f9f1a908fdaac3
-F src/vtab.c 914db4c9435c61a522e3cdaf103dac163d38aa30
+F src/vtab.c 9c1bbb54d8b29a3412bff4eee32e9be309d85727
 F src/where.c a800184a2d023b15d6f2758b7a6c7ab011258fee
 F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
@@ -211,7 +211,7 @@ F test/attachmalloc.test f7f62363896475080b0d41907a85a9fd94625296
 F test/auth.test 9eb4b6b99eee54c95711c74c4b9694acf4d850ed
 F test/auth2.test ee3ba272e2b975e913afc9b041ee75706e190005
 F test/autoinc.test 42af2c407c4e37d0626f9cda57ed381e94522c9d
-F test/autovacuum.test 4339e66003b9cf813dd667a83aed2dee27c4c36d
+F test/autovacuum.test e3428031ad7a14f16a7d515cd2a0480854e66b21
 F test/autovacuum_ioerr2.test 598b0663074d3673a9c1bc9a16e80971313bafe6
 F test/avtrans.test 1e901d8102706b63534dbd2bdd4d8f16c4082650
 F test/badutf.test d5360fc31f643d37a973ab0d8b4fb85799c3169f
@@ -385,8 +385,8 @@ F test/lastinsert.test 474d519c68cb79d07ecae56a763aa7f322c72f51
 F test/laststmtchanges.test 18ead86c8a87ade949a1d5658f6dc4bb111d1b02
 F test/like.test 2a3ddbd5d91503f914eabae67a47c4196fe33a58
 F test/like2.test 3b2ee13149ba4a8a60b59756f4e5d345573852da
-F test/limit.test ca61a9fc520f54470edb3a771167fe4b68abc247
-F test/loadext.test 5f4354b3eb22584563a51ff74329f06e48dfae33
+F test/limit.test 2db7b3b34fb925b8e847d583d2eb67531d0ce67e
+F test/loadext.test f79e5460c4664916a93ba6e7c762886153e2014b
 F test/loadext2.test 0bcaeb4d81cd5b6e883fdfea3c1bdbe1f173cbca
 F test/lock.test 6825aea0b5885578b1b63a3b178803842c4ee9f1
 F test/lock2.test 018b846f6f3b3b695fad07e317b7988442b556f4
@@ -412,6 +412,7 @@ F test/mallocE.test db1ed69d7eded1b080952e2a7c37f364ad241b08
 F test/mallocF.test 2d5c590ebc2fc7f0dcebdf5aa8498b9aed69107e
 F test/mallocG.test 4584d0d8ddb8009f16ca0c8bab1fa37f6358efa2
 F test/mallocH.test 79b65aed612c9b3ed2dcdaa727c85895fd1bfbdb
+F test/mallocI.test 6e24fe6444bd2999ccc81f984977b44c0d6e5591
 F test/malloc_common.tcl 753eb1ff3481f6cddb65cff33b9ef9f72c5ccdf7
 F test/manydb.test 8de36b8d33aab5ef295b11d9e95310aeded31af8
 F test/memdb.test a67bda4ff90a38f2b19f6c7f95aa7289e051d893
@@ -427,7 +428,7 @@ F test/misc3.test 7212ed8dad01427e9acab9bd3e7e5e2c2e89be9e
 F test/misc4.test 91e8ed25c092c2bb4e0bb01864631e2930f8d7de
 F test/misc5.test 6a5c1e3217a95b0db05ff9a0f1ecb5ce9043ffef
 F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
-F test/misc7.test 9aef880e037722f6a8549dfec4013080489ee822
+F test/misc7.test fd424ff93a83bb6a31463eb043c588777d8215a8
 F test/misuse.test 30b3a458e5a70c31e74c291937b6c82204c59f33
 F test/mutex1.test 7f5e21fd11fe22de079e5dcd394ee4f6c257e68e
 F test/mutex2.test 56f282f436596e9febdc6e0db2c507432b6724bb
@@ -460,7 +461,7 @@ F test/select1.test e66c18df883aa2a3b883d5b0aeece3fa64053a9b
 F test/select2.test 272a3d3e35b1d3a0760168ababf555e656357fc4
 F test/select3.test 2ce595f8fb8e2ac10071d3b4e424cadd4634a054
 F test/select4.test 0618c9377013840194b7901e6224d841cd3e7193
-F test/select5.test 5ad14ea338aada2e6394ba98fa9aa40e3e50aec0
+F test/select5.test 1bddfe92ae0b00ca53dc2735d5d23ce6b9723c26
 F test/select6.test 1131113eb6ae398069a8bc2173eb6c9a2d8ff1cd
 F test/select7.test 7906735805cfbee4dddc0bed4c14e68d7f5f9c5f
 F test/select8.test 391de11bdd52339c30580dabbbbe97e3e9a3c79d
@@ -566,7 +567,7 @@ F test/update.test 8bc86fd7ef1a00014f76dc6a6a7c974df4aef172
 F test/utf16align.test 7360e84472095518c56746f76b1f9d4dce99fb4d
 F test/vacuum.test 0bc75ee74ab9c69322d6563aa2287375697e630b
 F test/vacuum2.test d3b9691541fe6ed5c711f547a1c7d70e9760ac6f
-F test/vacuum3.test 75dee6ffd1baa60308dcad93f2c689126500dcff
+F test/vacuum3.test 306b65554980d8d4a3b6eeb7b3ccd11c65ebb540
 F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
 F test/veryquick.test e265401afefa994cdf2fe4b6f286b1e87c2f9b9d
 F test/view.test 5799906511d6c77cfe3516d3d1189224350ef732
@@ -616,7 +617,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P b65f493c7519e8a5ee632a395b57d45269741dda
-R 569ccbda0a2f36d2174f959575a5f332
+P 2cd6bae80984126023bcf479e5f3db5eaa5c4134
+R cea4eb266e996617279acd70a132ce2a
 U drh
-Z f6ba4601378d31882289341741f7ff01
+Z 7dbeb8531e58c51f99b7f023b4b1da67
index 0244b8bfd22d7b0e533ad2e7fe6234588a61a6fa..9a9062a7d26349d26fbe1bb387de13080c41309e 100644 (file)
@@ -1 +1 @@
-2cd6bae80984126023bcf479e5f3db5eaa5c4134
\ No newline at end of file
+f1e44eb323f05495cbae25113aebcc50d16b40df
\ No newline at end of file
index 19f09dc8d8296ab2380f6383043c53c697d14bbb..715e219bf9d00a397ae32b49a1a54bf97ed221a4 100644 (file)
@@ -22,7 +22,7 @@
 **     COMMIT
 **     ROLLBACK
 **
-** $Id: build.c,v 1.491 2008/07/28 19:34:53 drh Exp $
+** $Id: build.c,v 1.492 2008/08/02 03:50:39 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -137,12 +137,6 @@ void sqlite3FinishCoding(Parse *pParse){
   if( db->mallocFailed ) return;
   if( pParse->nested ) return;
   if( pParse->nErr ) return;
-  if( !pParse->pVdbe ){
-    if( pParse->rc==SQLITE_OK && pParse->nErr ){
-      pParse->rc = SQLITE_ERROR;
-      return;
-    }
-  }
 
   /* Begin by generating some termination code at the end of the
   ** vdbe program
index 825c57b25d27a7824ae272408d59ee8d101a4fe1..e6b75c0a672c6e08ca497f4f9c95d63eb7261157 100644 (file)
@@ -14,7 +14,7 @@
 ** other files are for internal use by SQLite and should not be
 ** accessed by users of the library.
 **
-** $Id: legacy.c,v 1.28 2008/07/28 19:34:53 drh Exp $
+** $Id: legacy.c,v 1.29 2008/08/02 03:50:39 drh Exp $
 */
 
 #include "sqliteInt.h"
@@ -84,10 +84,9 @@ int sqlite3_exec(
           }
           for(i=0; i<nCol; i++){
             azCols[i] = (char *)sqlite3_column_name(pStmt, i);
-            if( !azCols[i] ){
-              db->mallocFailed = 1;
-              goto exec_out;
-            }
+            /* sqlite3VdbeSetColName() installs column names as UTF8
+            ** strings so there is no way for sqlite3_column_name() to fail. */
+            assert( azCols[i]!=0 );
           }
           nCallback++;
         }
index 2d44f315be428b36e1ff84ea15560fffbc3fb662..2f7ca523549b927fc409c4b13ba2a59e07da2711 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains code used to dynamically load extensions into
 ** the SQLite library.
 **
-** $Id: loadext.c,v 1.52 2008/07/28 19:34:53 drh Exp $
+** $Id: loadext.c,v 1.53 2008/08/02 03:50:39 drh Exp $
 */
 
 #ifndef SQLITE_CORE
@@ -392,18 +392,17 @@ static int sqlite3LoadExtension(
   }
 
   /* Append the new shared library handle to the db->aExtension array. */
-  db->nExtension++;
-  aHandle = sqlite3DbMallocZero(db, sizeof(handle)*db->nExtension);
+  aHandle = sqlite3DbMallocZero(db, sizeof(handle)*(db->nExtension+1));
   if( aHandle==0 ){
     return SQLITE_NOMEM;
   }
   if( db->nExtension>0 ){
-    memcpy(aHandle, db->aExtension, sizeof(handle)*(db->nExtension-1));
+    memcpy(aHandle, db->aExtension, sizeof(handle)*db->nExtension);
   }
   sqlite3DbFree(db, db->aExtension);
   db->aExtension = aHandle;
 
-  db->aExtension[db->nExtension-1] = handle;
+  db->aExtension[db->nExtension++] = handle;
   return SQLITE_OK;
 }
 int sqlite3_load_extension(
index 1fa65a75eed081544eae30cc32489c153907ce53..bf33514adf504725ec80d13769fdb0592f9bbc26 100644 (file)
@@ -18,7 +18,7 @@
 ** file simultaneously, or one process from reading the database while
 ** another is writing.
 **
-** @(#) $Id: pager.c,v 1.468 2008/08/01 10:50:23 danielk1977 Exp $
+** @(#) $Id: pager.c,v 1.469 2008/08/02 03:50:39 drh Exp $
 */
 #ifndef SQLITE_OMIT_DISKIO
 #include "sqliteInt.h"
@@ -4580,6 +4580,9 @@ static int pager_incr_changecounter(Pager *pPager, int isDirect){
   u32 change_counter;
   int rc = SQLITE_OK;
 
+#ifndef SQLITE_ENABLE_ATOMIC_WRITE
+  assert( isDirect==0 );  /* isDirect is only true for atomic writes */
+#endif
   if( !pPager->changeCountDone ){
     /* Open page 1 of the file for writing. */
     rc = sqlite3PagerGet(pPager, 1, &pPgHdr);
@@ -4598,10 +4601,12 @@ static int pager_incr_changecounter(Pager *pPager, int isDirect){
     change_counter++;
     put32bits(((char*)PGHDR_TO_DATA(pPgHdr))+24, change_counter);
 
+#ifdef SQLITE_ENABLE_ATOMIC_WRITE
     if( isDirect && pPager->fd->pMethods ){
       const void *zBuf = PGHDR_TO_DATA(pPgHdr);
       rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
     }
+#endif
 
     /* Release the page reference. */
     sqlite3PagerUnref(pPgHdr);
index a8d98bddbd445909c8a6765103e2d66f05be47a7..ef49f0a64cd6b33e0af17e2e476bda981ede592f 100644 (file)
@@ -13,7 +13,7 @@
 ** interface, and routines that contribute to loading the database schema
 ** from disk.
 **
-** $Id: prepare.c,v 1.90 2008/07/28 19:34:53 drh Exp $
+** $Id: prepare.c,v 1.91 2008/08/02 03:50:39 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -224,7 +224,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
   rc = sqlite3BtreeCursor(pDb->pBt, MASTER_ROOT, 0, 0, curMain);
   if( rc!=SQLITE_OK && rc!=SQLITE_EMPTY ){
     sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc));
-    goto leave_error_out;
+    goto initone_error_out;
   }
 
   /* Get the database meta information.
@@ -246,12 +246,12 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
   */
   if( rc==SQLITE_OK ){
     int i;
-    for(i=0; rc==SQLITE_OK && i<sizeof(meta)/sizeof(meta[0]); i++){
+    for(i=0; i<sizeof(meta)/sizeof(meta[0]); i++){
       rc = sqlite3BtreeGetMeta(pDb->pBt, i+1, (u32 *)&meta[i]);
-    }
-    if( rc ){
-      sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc));
-      goto leave_error_out;
+      if( rc ){
+        sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc));
+        goto initone_error_out;
+      }
     }
   }else{
     memset(meta, 0, sizeof(meta));
@@ -274,7 +274,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
         sqlite3SetString(pzErrMsg, db, "attached databases must use the same"
             " text encoding as main database");
         rc = SQLITE_ERROR;
-        goto leave_error_out;
+        goto initone_error_out;
       }
     }
   }else{
@@ -303,7 +303,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
   if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){
     sqlite3SetString(pzErrMsg, db, "unsupported file format");
     rc = SQLITE_ERROR;
-    goto leave_error_out;
+    goto initone_error_out;
   }
 
   /* Ticket #2804:  When we open a database in the newer file format,
@@ -368,7 +368,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
   ** curMain and calling sqlite3BtreeEnter(). For an error that occurs
   ** before that point, jump to error_out.
   */
-leave_error_out:
+initone_error_out:
   sqlite3BtreeCloseCursor(curMain);
   sqlite3_free(curMain);
   sqlite3BtreeLeave(pDb->pBt);
index e726d2e27240ff5d25b5b05d92ccb5ef51661792..eb04ead73bd1e9ec1582ceaa3caa824ea71abfd8 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains C code routines that are called by the parser
 ** to handle SELECT statements in SQLite.
 **
-** $Id: select.c,v 1.461 2008/08/01 18:47:02 drh Exp $
+** $Id: select.c,v 1.462 2008/08/02 03:50:39 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -1891,10 +1891,7 @@ static int multiSelect(
   /* Make sure there is no ORDER BY or LIMIT clause on prior SELECTs.  Only
   ** the last (right-most) SELECT in the series may have an ORDER BY or LIMIT.
   */
-  if( p==0 || p->pPrior==0 ){
-    rc = 1;
-    goto multi_select_end;
-  }
+  assert( p && p->pPrior );  /* Calling function guarantees this much */
   db = pParse->db;
   pPrior = p->pPrior;
   assert( pPrior->pRightmost!=pPrior );
@@ -1912,13 +1909,8 @@ static int multiSelect(
     goto multi_select_end;
   }
 
-  /* Make sure we have a valid query engine.  If not, create a new one.
-  */
   v = sqlite3GetVdbe(pParse);
-  if( v==0 ){
-    rc = 1;
-    goto multi_select_end;
-  }
+  assert( v!=0 );  /* The VDBE already created by calling function */
 
   /* Create the destination temporary table if necessary
   */
@@ -4000,12 +3992,20 @@ int sqlite3Select(
           struct AggInfo_col *pCol = &sAggInfo.aCol[i];
           if( pCol->iSorterColumn>=j ){
             int r1 = j + regBase;
-            int r2 = sqlite3ExprCodeGetColumn(pParse, 
+#ifndef NDEBUG
+            int r2 = 
+#endif
+                     sqlite3ExprCodeGetColumn(pParse, 
                                pCol->pTab, pCol->iColumn, pCol->iTable, r1, 0);
-            if( r1!=r2 ){
-              sqlite3VdbeAddOp2(v, OP_SCopy, r2, r1);
-            }
             j++;
+
+            /* sAggInfo.aCol[] only contains one entry per column.  So
+            ** The reference to pCol->iColumn,pCol->iTable must have been
+            ** the first reference to that column.  Hence, 
+            ** sqliteExprCodeGetColumn is guaranteed to put the result in
+            ** the column requested. 
+            */
+            assert( r1==r2 );
           }
         }
         regRecord = sqlite3GetTempReg(pParse);
index caf04211cc30c0c0f70a9f30bd9880e50ba58bdd..36fa811a4c3587643ef11c996ff210f2cf55a185 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.749 2008/08/01 17:37:41 danielk1977 Exp $
+** @(#) $Id: sqliteInt.h,v 1.750 2008/08/02 03:50:39 drh Exp $
 */
 #ifndef _SQLITEINT_H_
 #define _SQLITEINT_H_
@@ -2264,13 +2264,11 @@ int sqlite3AutoLoadExtensions(sqlite3*);
 #  define sqlite3VtabSync(X,Y) (Y)
 #  define sqlite3VtabRollback(X)
 #  define sqlite3VtabCommit(X)
-#  define sqlite3VtabTransferError(A,B,C)
 #else
    void sqlite3VtabClear(Table*);
    int sqlite3VtabSync(sqlite3 *db, char **);
    int sqlite3VtabRollback(sqlite3 *db);
    int sqlite3VtabCommit(sqlite3 *db);
-   void sqlite3VtabTransferError(sqlite3 *db, int, sqlite3_vtab*);
 #endif
 void sqlite3VtabMakeWritable(Parse*,Table*);
 void sqlite3VtabLock(sqlite3_vtab*);
index 83f9730df5e28760d3c8095094963b6d79bdb8e3..eaafc23c7d8f1ff2d38c1a8e85bbd9fe32ca9b27 100644 (file)
@@ -12,7 +12,7 @@
 ** Code for testing all sorts of SQLite interfaces.  This code
 ** implements new SQL functions used by the test scripts.
 **
-** $Id: test_func.c,v 1.9 2008/07/31 01:47:11 shane Exp $
+** $Id: test_func.c,v 1.10 2008/08/02 03:50:39 drh Exp $
 */
 #include "sqlite3.h"
 #include "tcl.h"
@@ -308,7 +308,8 @@ static int autoinstall_test_funcs(
   int objc,
   Tcl_Obj *CONST objv[]
 ){
-  sqlite3_auto_extension((void*)registerTestFunctions);
+  int rc = sqlite3_auto_extension((void*)registerTestFunctions);
+  Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
   return TCL_OK;
 }
 
index 6dbd6421a9062287046fcc0448944669c19ce2be..e9735665fd98888d5309cd71947255c0dc0a8660 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Test extension for testing the sqlite3_load_extension() function.
 **
-** $Id: test_loadext.c,v 1.2 2008/06/19 15:44:00 drh Exp $
+** $Id: test_loadext.c,v 1.3 2008/08/02 03:50:39 drh Exp $
 */
 #include <string.h>
 #include "sqlite3ext.h"
@@ -98,13 +98,14 @@ int testloadext_init(
   char **pzErrMsg, 
   const sqlite3_api_routines *pApi
 ){
+  int nErr = 0;
   SQLITE_EXTENSION_INIT2(pApi);
-  sqlite3_create_function(db, "half", 1, SQLITE_ANY, 0, halfFunc, 0, 0);
-  sqlite3_create_function(db, "sqlite3_status", 1, SQLITE_ANY, 0,
+  nErr |= sqlite3_create_function(db, "half", 1, SQLITE_ANY, 0, halfFunc, 0, 0);
+  nErr |= sqlite3_create_function(db, "sqlite3_status", 1, SQLITE_ANY, 0,
                           statusFunc, 0, 0);
-  sqlite3_create_function(db, "sqlite3_status", 2, SQLITE_ANY, 0,
+  nErr |= sqlite3_create_function(db, "sqlite3_status", 2, SQLITE_ANY, 0,
                           statusFunc, 0, 0);
-  return 0;
+  return nErr ? SQLITE_ERROR : SQLITE_OK;
 }
 
 /*
index 7d36c61abec645da8602fb722b3e1167a857c22d..6516f131c0720e477d902f5e059017272ba88aaf 100644 (file)
@@ -15,7 +15,7 @@
 ** 6000 lines long) it was split up into several smaller files and
 ** this header information was factored out.
 **
-** $Id: vdbeInt.h,v 1.152 2008/07/30 13:14:55 drh Exp $
+** $Id: vdbeInt.h,v 1.153 2008/08/02 03:50:39 drh Exp $
 */
 #ifndef _VDBEINT_H_
 #define _VDBEINT_H_
@@ -318,7 +318,6 @@ struct Vdbe {
   Mem *pResultSet;        /* Pointer to an array of results */
   u8 explain;             /* True if EXPLAIN present on SQL command */
   u8 changeCntOn;         /* True to update the change-counter */
-  u8 aborted;             /* True if ROLLBACK in another VM causes an abort */
   u8 expired;             /* True if the VM needs to be recompiled */
   u8 minWriteFileFormat;  /* Minimum file format for writable database files */
   u8 inVtabMethod;        /* See comments above */
index 9f1471dc9375daa9e214394edc4f7b82102104ba..880c4ae547c2ef7c0d96a5286405e6e128fbaa9a 100644 (file)
@@ -13,7 +13,7 @@
 ** This file contains code use to implement APIs that are part of the
 ** VDBE.
 **
-** $Id: vdbeapi.c,v 1.137 2008/08/01 20:10:08 drh Exp $
+** $Id: vdbeapi.c,v 1.138 2008/08/02 03:50:39 drh Exp $
 */
 #include "sqliteInt.h"
 #include "vdbeInt.h"
@@ -435,9 +435,6 @@ static int sqlite3Step(Vdbe *p){
   db = p->db;
   assert( !db->mallocFailed );
 
-  if( p->aborted ){
-    return SQLITE_ABORT;
-  }
   if( p->pc<=0 && p->expired ){
     if( p->rc==SQLITE_OK ){
       p->rc = SQLITE_SCHEMA;
index 5dada4f07e3007005db1ce990bd86e4035575335..cded81f89b439b73543d65f00cfc4a7af4d0700e 100644 (file)
@@ -14,7 +14,7 @@
 ** to version 2.8.7, all this code was combined into the vdbe.c source file.
 ** But that file was getting too big so this subroutines were split out.
 **
-** $Id: vdbeaux.c,v 1.404 2008/08/01 20:10:08 drh Exp $
+** $Id: vdbeaux.c,v 1.405 2008/08/02 03:50:39 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -1760,7 +1760,6 @@ int sqlite3VdbeReset(Vdbe *p){
   }
 #endif
   p->magic = VDBE_MAGIC_INIT;
-  p->aborted = 0;
   return p->rc & db->errMask;
 }
  
index 62636104aa83750501ce5db4a32cd2af277f4208..bd18c479a5cea6165b36b50f666fae444d5c13ec 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** This file contains code used to help implement virtual tables.
 **
-** $Id: vtab.c,v 1.73 2008/08/01 17:37:41 danielk1977 Exp $
+** $Id: vtab.c,v 1.74 2008/08/02 03:50:39 drh Exp $
 */
 #ifndef SQLITE_OMIT_VIRTUALTABLE
 #include "sqliteInt.h"
@@ -790,7 +790,11 @@ FuncDef *sqlite3VtabOverloadFunction(
     }
     rc = pMod->xFindFunction(pVtab, nArg, zLowerName, &xFunc, &pArg);
     sqlite3DbFree(db, zLowerName);
-    sqlite3VtabTransferError(db, rc, pVtab);
+    if( pVtab->zErrMsg ){
+      sqlite3Error(db, rc, "%s", pVtab->zErrMsg);
+      sqlite3DbFree(db, pVtab->zErrMsg);
+      pVtab->zErrMsg = 0;
+    }
   }
   if( rc==0 ){
     return pDef;
@@ -831,15 +835,4 @@ void sqlite3VtabMakeWritable(Parse *pParse, Table *pTab){
   }
 }
 
-/*
-** Transfer a virtual table error into the database connection.
-*/
-void sqlite3VtabTransferError(sqlite3 *db, int rc, sqlite3_vtab *pVtab){
-  if( pVtab->zErrMsg ){
-    sqlite3Error(db, rc, "%s", pVtab->zErrMsg);
-    sqlite3DbFree(db, pVtab->zErrMsg);
-    pVtab->zErrMsg = 0;
-  }
-}
-
 #endif /* SQLITE_OMIT_VIRTUALTABLE */
index 6128f09369f96b8bee693bacdfe05f3d439d3a8a..9b3ab4a0419c2bd768fd4fd2757516cc9f674576 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the SELECT statement.
 #
-# $Id: autovacuum.test,v 1.26 2007/04/07 15:03:17 danielk1977 Exp $
+# $Id: autovacuum.test,v 1.27 2008/08/02 03:50:39 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -643,4 +643,23 @@ do_test autovacuum-7.3 {
   expr {[file size test.db] / 1024}
 } {286}
 
+#------------------------------------------------------------------------
+# Additional tests.
+#
+# Try to determine the autovacuum setting for a database that is locked.
+#
+do_test autovacuum-8.1 {
+  db close
+  sqlite3 db test.db
+  sqlite3 db2 test.db
+  db eval {PRAGMA auto_vacuum}
+} {1}
+do_test autovacuum-8.2 {
+  db eval {BEGIN EXCLUSIVE}
+  catchsql {PRAGMA auto_vacuum} db2
+} {1 {database is locked}}
+catch {db2 close}
+catch {db eval {COMMIT}}
+    
+
 finish_test
index 206c0b95f57e1d9b6384db209e1eb424a9c58f6c..e5aac70da43504e35c7ff4517a65818a2239fdc3 100644 (file)
@@ -12,7 +12,7 @@
 # focus of this file is testing the LIMIT ... OFFSET ... clause
 #  of SELECT statements.
 #
-# $Id: limit.test,v 1.31 2008/01/16 18:20:42 danielk1977 Exp $
+# $Id: limit.test,v 1.32 2008/08/02 03:50:39 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -445,4 +445,28 @@ do_test limit-11.1 {
 } {}
 } ;# ifcapable subquery
 
+# Test error processing.
+#
+do_test limit-12.1 {
+  catchsql {
+     SELECT * FROM t1 LIMIT replace(1)
+  }
+} {1 {wrong number of arguments to function replace()}}
+do_test limit-12.2 {
+  catchsql {
+     SELECT * FROM t1 LIMIT 5 OFFSET replace(1)
+  }
+} {1 {wrong number of arguments to function replace()}}
+do_test limit-12.3 {
+  catchsql {
+     SELECT * FROM t1 LIMIT x
+  }
+} {1 {no such column: x}}
+do_test limit-12.4 {
+  catchsql {
+     SELECT * FROM t1 LIMIT 1 OFFSET x
+  }
+} {1 {no such column: x}}
+
+
 finish_test
index 56aeefafdcdceb408ee21dd6a65b70d5b1c75ed0..e0fecd38f887e863332e8a7fca44140077574676 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this script is extension loading.
 #
-# $Id: loadext.test,v 1.13 2008/06/30 15:09:29 danielk1977 Exp $
+# $Id: loadext.test,v 1.14 2008/08/02 03:50:39 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -253,6 +253,20 @@ do_test loadext-4.3 {
   }
 } {1 {not authorized}}
 
+source $testdir/malloc_common.tcl
 
 
+# Malloc failure in sqlite3_auto_extension and sqlite3_load_extension
+#
+do_malloc_test loadext-5 -tclprep {
+  sqlite3_reset_auto_extension
+} -tclbody {
+  if {[autoinstall_test_functions]==7} {error "out of memory"}
+}
+do_malloc_test loadext-6 -tclbody {
+  db enable_load_extension 1
+  sqlite3_load_extension db $::testextension testloadext_init
+}
+autoinstall_test_functions
+
 finish_test
diff --git a/test/mallocI.test b/test/mallocI.test
new file mode 100644 (file)
index 0000000..ace92dc
--- /dev/null
@@ -0,0 +1,43 @@
+# 2008 August 01
+#
+# 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 malloc failures in various obscure operations.
+# 
+# $Id: mallocI.test,v 1.1 2008/08/02 03:50:39 drh Exp $
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+source $testdir/malloc_common.tcl
+
+# Malloc failures in a view.
+#
+do_malloc_test mallocI-1 -sqlprep {
+  CREATE TABLE t1(a,b,c,d);
+  CREATE VIEW v1 AS SELECT a*b, c*d FROM t1 ORDER BY b-d;
+} -sqlbody {
+  SELECT * FROM v1
+}
+
+# Malloc failure while trying to service a pragma on a TEMP database.
+#
+do_malloc_test mallocI-2 -sqlbody {
+  PRAGMA temp.page_size
+}
+
+# Malloc failure while creating a table from a SELECT statement.
+#
+do_malloc_test mallocI-3 -sqlprep {
+  CREATE TABLE t1(a,b,c);
+} -sqlbody {
+  CREATE TABLE t2 AS SELECT b,c FROM t1;
+}
+
+finish_test
index 4a6bd9172243eb06db64f2ae3b47f5df9c3a09ed..111d802bfa6b9650c941bda5af5273bce78b428c 100644 (file)
@@ -10,7 +10,7 @@
 #***********************************************************************
 # This file implements regression tests for SQLite library.
 #
-# $Id: misc7.test,v 1.22 2008/08/01 15:06:30 drh Exp $
+# $Id: misc7.test,v 1.23 2008/08/02 03:50:40 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -243,7 +243,7 @@ file delete -force test.db-journal
 sqlite3 db test.db
 
 ifcapable explain {
-  do_test misc7-14 {
+  do_test misc7-14.1 {
     execsql {
       CREATE TABLE abc(a PRIMARY KEY, b, c);
     }
@@ -251,11 +251,16 @@ ifcapable explain {
       EXPLAIN QUERY PLAN SELECT * FROM abc AS t2 WHERE rowid = 1;
     }
   } {0 0 {TABLE abc AS t2 USING PRIMARY KEY}}
-  do_test misc7-15 {
+  do_test misc7-14.2 {
     execsql {
       EXPLAIN QUERY PLAN SELECT * FROM abc AS t2 WHERE a = 1;
     }
   } {0 0 {TABLE abc AS t2 WITH INDEX sqlite_autoindex_abc_1}}
+  do_test misc7-14.3 {
+    execsql {
+      EXPLAIN QUERY PLAN SELECT * FROM abc AS t2 ORDER BY a;
+    }
+  } {0 0 {TABLE abc AS t2 WITH INDEX sqlite_autoindex_abc_1 ORDER BY}}
 }
 
 db close
index 1fa0ec63d72ebacaf49112addf805513472bc272..08b730924c3e3ae69d362cbad906cbd38d4469dc 100644 (file)
@@ -12,7 +12,7 @@
 # focus of this file is testing aggregate functions and the
 # GROUP BY and HAVING clauses of SELECT statements.
 #
-# $Id: select5.test,v 1.17 2008/01/16 18:20:42 danielk1977 Exp $
+# $Id: select5.test,v 1.18 2008/08/02 03:50:40 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -122,7 +122,7 @@ do_test select5-4.5 {
 
 # Some tests for queries with a GROUP BY clause but no aggregate functions.
 #
-# Note: The query in test case 5-5.5 are not legal SQL. So if the 
+# Note: The query in test cases 5.1 through 5.5 are not legal SQL. So if the 
 # implementation changes in the future and it returns different results,
 # this is not such a big deal.
 #
@@ -156,6 +156,15 @@ do_test select5-5.5 {
   } 
 } {1 4 6 4}
 
+# Test rendering of columns for the GROUP BY clause.
+#
+do_test select5-5.11 {
+breakpoint
+  execsql {
+    SELECT max(c), b*a, b, a FROM t2 GROUP BY b*a, b, a
+  }
+} {3 2 2 1 5 4 4 1 7 24 4 6}
+
 # NULL compare equal to each other for the purposes of processing
 # the GROUP BY clause.
 #
index aeeb8ba6d752100315550ef5fbcbf415b2a86836..fb97a601cb7477258963fe9cb8d424cecef98b6e 100644 (file)
@@ -12,7 +12,7 @@
 # focus of this file is changing the database page size using a 
 # VACUUM statement.
 #
-# $Id: vacuum3.test,v 1.6 2008/07/12 14:52:21 drh Exp $
+# $Id: vacuum3.test,v 1.7 2008/08/02 03:50:40 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -303,6 +303,15 @@ if {$MEMDEBUG} {
     PRAGMA page_size = 512;
     VACUUM;
   } 
+  do_malloc_test vacuum3-malloc-2 -sqlprep { 
+    PRAGMA encoding=UTF16;
+    CREATE TABLE t1(a, b, c);
+    INSERT INTO t1 VALUES(1, 2, 3);
+    CREATE TABLE t2(x,y,z);
+    INSERT INTO t2 SELECT * FROM t1;
+  } -sqlbody {
+    VACUUM;
+  } 
 }
 
 finish_test