/ Check-in [092d5331]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Do not reuse temp registers originally allocated to a subroutine within the main body of the program logic, since if the subroutine is called while the reused temp registers are in use, their values will get clobbered. Candidate fix for ticket [3a77c9714e63330]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 092d53315e50be42b51ef7b3069c82c32a129b6a
User & Date: drh 2011-12-06 13:24:59
Context
2011-12-06
13:46
Add file tkt-3a77c9714e.test, containing tests to verify that the problem documented by ticket [3a77c9714e] has been fixed. check-in: 162421da user: dan tags: trunk
13:24
Do not reuse temp registers originally allocated to a subroutine within the main body of the program logic, since if the subroutine is called while the reused temp registers are in use, their values will get clobbered. Candidate fix for ticket [3a77c9714e63330] check-in: 092d5331 user: drh tags: trunk
00:47
Merge the winGetLastError fixes into trunk. check-in: 5b03ba9d user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

  3758   3758   void sqlite3ReleaseTempRange(Parse *pParse, int iReg, int nReg){
  3759   3759     sqlite3ExprCacheRemove(pParse, iReg, nReg);
  3760   3760     if( nReg>pParse->nRangeReg ){
  3761   3761       pParse->nRangeReg = nReg;
  3762   3762       pParse->iRangeReg = iReg;
  3763   3763     }
  3764   3764   }
         3765  +
         3766  +/*
         3767  +** Mark all temporary registers as being unavailable for reuse.
         3768  +*/
         3769  +void sqlite3ClearTempRegCache(Parse *pParse){
         3770  +  pParse->nTempReg = 0;
         3771  +  pParse->nRangeReg = 0;
         3772  +}

Changes to src/select.c.

  3856   3856         explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
  3857   3857         sqlite3Select(pParse, pSub, &dest);
  3858   3858         pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow;
  3859   3859         if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
  3860   3860         retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn);
  3861   3861         VdbeComment((v, "end %s", pItem->pTab->zName));
  3862   3862         sqlite3VdbeChangeP1(v, topAddr, retAddr);
  3863         -
         3863  +      sqlite3ClearTempRegCache(pParse);
  3864   3864       }
  3865   3865       if( /*pParse->nErr ||*/ db->mallocFailed ){
  3866   3866         goto select_end;
  3867   3867       }
  3868   3868       pParse->nHeight -= sqlite3SelectExprHeight(p);
  3869   3869       pTabList = p->pSrc;
  3870   3870       if( !IgnorableOrderby(pDest) ){

Changes to src/sqliteInt.h.

  2656   2656   int sqlite3KeywordCode(const unsigned char*, int);
  2657   2657   int sqlite3RunParser(Parse*, const char*, char **);
  2658   2658   void sqlite3FinishCoding(Parse*);
  2659   2659   int sqlite3GetTempReg(Parse*);
  2660   2660   void sqlite3ReleaseTempReg(Parse*,int);
  2661   2661   int sqlite3GetTempRange(Parse*,int);
  2662   2662   void sqlite3ReleaseTempRange(Parse*,int,int);
         2663  +void sqlite3ClearTempRegCache(Parse*);
  2663   2664   Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
  2664   2665   Expr *sqlite3Expr(sqlite3*,int,const char*);
  2665   2666   void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
  2666   2667   Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
  2667   2668   Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
  2668   2669   Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
  2669   2670   void sqlite3ExprAssignVarNumber(Parse*, Expr*);