/ Check-in [b821b6ed]
Login

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

Overview
Comment:Fix an out-of-memory NULL pointer defer in the code generator. Ticket #2843. (CVS 4630)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b821b6ed176b4259e1d4b56c8eb548933b6f530a
User & Date: drh 2007-12-14 15:12:21
Context
2007-12-14
16:11
Fix a typo in the previous check-in. Also simplify a line in select.c. (CVS 4631) check-in: 86f45d7b user: drh tags: trunk
15:12
Fix an out-of-memory NULL pointer defer in the code generator. Ticket #2843. (CVS 4630) check-in: b821b6ed user: drh tags: trunk
2007-12-13
21:54
Change all instances of "it's" in comments to either "its" or "it is", as appropriate, in case the comments are ever again read by a pedantic grammarian. Ticket #2840. (CVS 4629) check-in: 4e91a267 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/expr.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
....
2318
2319
2320
2321
2322
2323
2324

2325
2326
2327
2328
2329
2330
2331

2332
2333
2334
2335
2336
2337
2338
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.319 2007/12/13 21:54:11 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** Return the 'affinity' of the expression pExpr if any.
**
................................................................................
** so that it will make use of the cached result on subsequent evaluations
** rather than evaluate the whole expression again.  Trivial expressions are
** not cached.  If the expression is cached, its result is stored in a 
** memory location.
*/
void sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr){
  Vdbe *v = pParse->pVdbe;

  int iMem;
  int addr1, addr2;
  if( v==0 ) return;
  addr1 = sqlite3VdbeCurrentAddr(v);
  sqlite3ExprCode(pParse, pExpr);
  addr2 = sqlite3VdbeCurrentAddr(v);
  if( addr2>addr1+1 || sqlite3VdbeGetOp(v, addr1)->opcode==OP_Function ){

    iMem = pExpr->iTable = pParse->nMem++;
    sqlite3VdbeAddOp(v, OP_MemStore, iMem, 0);
    pExpr->op = TK_REGISTER;
  }
}
#endif








|







 







>






|
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
....
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.320 2007/12/14 15:12:21 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** Return the 'affinity' of the expression pExpr if any.
**
................................................................................
** so that it will make use of the cached result on subsequent evaluations
** rather than evaluate the whole expression again.  Trivial expressions are
** not cached.  If the expression is cached, its result is stored in a 
** memory location.
*/
void sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr){
  Vdbe *v = pParse->pVdbe;
  VdbeOp *pOp;
  int iMem;
  int addr1, addr2;
  if( v==0 ) return;
  addr1 = sqlite3VdbeCurrentAddr(v);
  sqlite3ExprCode(pParse, pExpr);
  addr2 = sqlite3VdbeCurrentAddr(v);
  if( addr2>addr1+1
   || ((pOp = sqlite3VdbeGetOp(v, addr1))!=0 && pOp->opcode==OP_Function) ){
    iMem = pExpr->iTable = pParse->nMem++;
    sqlite3VdbeAddOp(v, OP_MemStore, iMem, 0);
    pExpr->op = TK_REGISTER;
  }
}
#endif

Changes to src/insert.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
106
107
108
109
110
111
112

113
114
115
116
117
118
119
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
**
** $Id: insert.c,v 1.195 2007/12/12 17:42:53 danielk1977 Exp $
*/
#include "sqliteInt.h"

/*
** Set P3 of the most recently inserted opcode to a column affinity
** string for index pIdx. A column affinity string has one character
** for each column in the table, according to the affinity of the column:
................................................................................
** run without using temporary table for the results of the SELECT. 
*/
static int readsTable(Vdbe *v, int iStartAddr, int iDb, Table *pTab){
  int i;
  int iEnd = sqlite3VdbeCurrentAddr(v);
  for(i=iStartAddr; i<iEnd; i++){
    VdbeOp *pOp = sqlite3VdbeGetOp(v, i);

    if( pOp->opcode==OP_OpenRead ){
      VdbeOp *pPrior = &pOp[-1];
      int tnum = pOp->p2;
      assert( i>iStartAddr );
      assert( pPrior->opcode==OP_Integer );
      if( pPrior->p1==iDb ){
        Index *pIndex;







|







 







>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
**
** $Id: insert.c,v 1.196 2007/12/14 15:12:21 drh Exp $
*/
#include "sqliteInt.h"

/*
** Set P3 of the most recently inserted opcode to a column affinity
** string for index pIdx. A column affinity string has one character
** for each column in the table, according to the affinity of the column:
................................................................................
** run without using temporary table for the results of the SELECT. 
*/
static int readsTable(Vdbe *v, int iStartAddr, int iDb, Table *pTab){
  int i;
  int iEnd = sqlite3VdbeCurrentAddr(v);
  for(i=iStartAddr; i<iEnd; i++){
    VdbeOp *pOp = sqlite3VdbeGetOp(v, i);
    assert( pOp==0 );
    if( pOp->opcode==OP_OpenRead ){
      VdbeOp *pPrior = &pOp[-1];
      int tnum = pOp->p2;
      assert( i>iStartAddr );
      assert( pPrior->opcode==OP_Integer );
      if( pPrior->p1==iDb ){
        Index *pIndex;

Changes to test/mallocF.test.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
56
57
58
59
60
61
62
63












64
#    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 {
................................................................................
  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







|







 








>
>
>
>
>
>
>
>
>
>
>
>

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#    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.2 2007/12/14 15:12:21 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Only run these tests if memory debugging is turned on.
#
ifcapable !memdebug {
................................................................................
  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
}

# Ticket #2843
#
set PREP {
  CREATE TABLE t1(x);
  CREATE TRIGGER r1 BEFORE INSERT ON t1 BEGIN
    SELECT 'hello';
  END;
}
do_malloc_test mallocF-4 -sqlprep $PREP -sqlbody {
  INSERT INTO t1 VALUES(random());
}

finish_test