]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix a bug in where.c where a non-temp register was being incorrectly deallocated...
authordanielk1977 <danielk1977@noemail.net>
Wed, 1 Oct 2008 08:43:03 +0000 (08:43 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Wed, 1 Oct 2008 08:43:03 +0000 (08:43 +0000)
FossilOrigin-Name: 59d2e89e2181c26b18eac68ccc80ea3018f70a5e

manifest
manifest.uuid
src/where.c
test/where.test

index ff742b0cd25848ae47dfa31776dc3f0b72cd4320..cb4cd734487fec9eade8fb1193db93cd8d9a829f 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\ssome\stestcase()\sand\sassert()\smacros\sto\sbtree.c\sto\said\swith\stesting\nrecent\schanges.\s(CVS\s5757)
-D 2008-09-30T17:18:17
+C Fix\sa\sbug\sin\swhere.c\swhere\sa\snon-temp\sregister\swas\sbeing\sincorrectly\sdeallocated.\sTicket\s#3408.\s(CVS\s5758)
+D 2008-10-01T08:43:03
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in e4ab842f9a64ef61d57093539a8aab76b12810db
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -199,7 +199,7 @@ F src/vdbefifo.c 20fda2a7c4c0bcee1b90eb7e545fefcdbf2e1de7
 F src/vdbemem.c ead88713b852576e2a924bc4ae696964bfbaec0a
 F src/vtab.c 527c180e9c5fca417c9167d02af4b5039f892b4b
 F src/walker.c 488c2660e13224ff70c0c82761118efb547f8f0d
-F src/where.c a9958b26cc87ea1446fbe6d004a7959b8d5d75c1
+F src/where.c 75b7f45bc02832445c244e2c6df4f7f5653148be
 F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/alias.test c321c114a8a31a33e3cbda910fa39949f5d9dcb2
@@ -606,7 +606,7 @@ F test/vtabC.test 9f2d9eb84bf65e606d6616f20977c5a32a11f548
 F test/vtab_alter.test 3a299749fee97ca3d53bd55717f536e4a2284856
 F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8
 F test/vtab_shared.test c19b2555b807ef2ee014c882cdda5bc8d84fcf48
-F test/where.test ea8e56f3c7b18fa4d250d32a08ffab44c0ff64ba
+F test/where.test 7dcfe573d4a5c6c4b7670271d02c006f2c7414b8
 F test/where2.test 7012c0ad022a54430dd22c98288d3f4d6599dbcf
 F test/where3.test 97d3936e6a443b968f1a61cdcc0f673252000e94
 F test/where4.test e9b9e2f2f98f00379e6031db6a6fca29bae782a2
@@ -637,7 +637,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 0f3c56330b43fb7c9dc43a444ca38bace9397ede
-R 5a3edf18f89485bee6c0db5078617fd9
-U drh
-Z 6d8b0066d3b484307b936dd03d86c312
+P fb461b78dfc2501fafa8bce03da5487fdfdff959
+R f17efdf67307b7c45c0bdb0de383022f
+U danielk1977
+Z c0645d23ba10337cccb6560748424fb4
index 73ec9a101e4bbe388bca9eb3c0ab7bd5c7b67309..eba23f86390263ace4eef704f3febd7bd445023d 100644 (file)
@@ -1 +1 @@
-fb461b78dfc2501fafa8bce03da5487fdfdff959
\ No newline at end of file
+59d2e89e2181c26b18eac68ccc80ea3018f70a5e
\ No newline at end of file
index 12ddd7ceb9117a2d1dbaa3ba693d662fbd7a54da..08dc448aa01d87921757ad0f38283d73c0930cf5 100644 (file)
@@ -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.322 2008/09/06 14:19:11 danielk1977 Exp $
+** $Id: where.c,v 1.323 2008/10/01 08:43:03 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 
@@ -1784,9 +1784,7 @@ static int codeEqualityTerm(
   Vdbe *v = pParse->pVdbe;
   int iReg;                  /* Register holding results */
 
-  if( iTarget<=0 ){
-    iReg = iTarget = sqlite3GetTempReg(pParse);
-  }
+  assert( iTarget>0 );
   if( pX->op==TK_EQ ){
     iReg = sqlite3ExprCodeTarget(pParse, pX->pRight, iTarget);
   }else if( pX->op==TK_ISNULL ){
@@ -2414,16 +2412,17 @@ WhereInfo *sqlite3WhereBegin(
       **          construct.
       */
       int r1;
+      int rtmp = sqlite3GetTempReg(pParse);
       pTerm = findTerm(&wc, iCur, -1, notReady, WO_EQ|WO_IN, 0);
       assert( pTerm!=0 );
       assert( pTerm->pExpr!=0 );
       assert( pTerm->leftCursor==iCur );
       assert( omitTable==0 );
-      r1 = codeEqualityTerm(pParse, pTerm, pLevel, 0);
+      r1 = codeEqualityTerm(pParse, pTerm, pLevel, rtmp);
       nxt = pLevel->nxt;
       sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, nxt);
       sqlite3VdbeAddOp3(v, OP_NotExists, iCur, nxt, r1);
-      sqlite3ReleaseTempReg(pParse, r1);
+      sqlite3ReleaseTempReg(pParse, rtmp);
       VdbeComment((v, "pk"));
       pLevel->op = OP_Noop;
     }else if( pLevel->flags & WHERE_ROWID_RANGE ){
index 06219f610fefbcc66de54110326f49af0a7f0e21..874a2b31d7a062e9519a18acf41233c5fe977a85 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the use of indices in WHERE clases.
 #
-# $Id: where.test,v 1.47 2008/09/01 15:52:11 drh Exp $
+# $Id: where.test,v 1.48 2008/10/01 08:43:03 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -1155,6 +1155,50 @@ do_test where-15.1 {
   }
 } {}
 
+# Ticket #3408.
+# 
+# The branch of code in where.c that generated rowid lookups was
+# incorrectly deallocating a constant register, meaning that if the 
+# vdbe code ran more than once, the second time around the constant
+# value may have been clobbered by some other value.
+# 
+do_test where-16.1 {
+  execsql {
+    CREATE TABLE a1(id INTEGER PRIMARY KEY, v);
+    CREATE TABLE a2(id INTEGER PRIMARY KEY, v);
+    INSERT INTO a1 VALUES(1, 'one');
+    INSERT INTO a1 VALUES(2, 'two');
+    INSERT INTO a2 VALUES(1, 'one');
+    INSERT INTO a2 VALUES(2, 'two');
+  }
+} {}
+do_test where-16.2 {
+  execsql {
+    SELECT * FROM a2 CROSS JOIN a1 WHERE a1.id=1 AND a1.v='one';
+  }
+} {1 one 1 one 2 two 1 one}
+
+# The actual problem reported in #3408.
+do_test where-16.3 {
+  execsql {
+    CREATE TEMP TABLE foo(idx INTEGER);
+    INSERT INTO foo VALUES(1);
+    INSERT INTO foo VALUES(1);
+    INSERT INTO foo VALUES(1);
+    INSERT INTO foo VALUES(2);
+    INSERT INTO foo VALUES(2);
+    CREATE TEMP TABLE bar(stuff INTEGER);
+    INSERT INTO bar VALUES(100);
+    INSERT INTO bar VALUES(200);
+    INSERT INTO bar VALUES(300);
+  }
+} {}
+do_test where-16.4 {
+  execsql {
+    SELECT bar.RowID id FROM foo, bar WHERE foo.idx = bar.RowID AND id = 2;
+  }
+} {2 2}
+
 integrity_check {where-99.0}
 
 finish_test