/ Check-in [7c599bae]
Login

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

Overview
Comment:Fix a bug in DELETE that might cause a segfault when deleting more than 40940 rows of data all at once. (CVS 2620)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:7c599bae33ba4eb10fc486ae3dab76330ce69936
User & Date: drh 2005-08-24 16:13:52
Context
2005-08-24
16:54
Remove a stray C++ style comment causing problems for some compilers. (CVS 2621) check-in: aa7dd3f2 user: drh tags: trunk
16:13
Fix a bug in DELETE that might cause a segfault when deleting more than 40940 rows of data all at once. (CVS 2620) check-in: 7c599bae user: drh tags: trunk
11:14
Version 3.2.4 (CVS 2619) check-in: 8cef2c1a user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/vdbefifo.c.

17
18
19
20
21
22
23



24
25
26
27
28
29
30
..
73
74
75
76
77
78
79

80

81
82
83
84
85
86
87

/*
** Allocate a new FifoPage and return a pointer to it.  Return NULL if
** we run out of memory.  Leave space on the page for nEntry entries.
*/
static FifoPage *allocatePage(int nEntry){
  FifoPage *pPage;



  pPage = sqliteMallocRaw( sizeof(FifoPage) + sizeof(i64)*(nEntry-1) );
  if( pPage ){
    pPage->nSlot = nEntry;
    pPage->iWrite = 0;
    pPage->iRead = 0;
    pPage->pNext = 0;
  }
................................................................................
  if( pFifo->nEntry==0 ){
    return SQLITE_DONE;
  }
  assert( pFifo->nEntry>0 );
  pPage = pFifo->pFirst;
  assert( pPage!=0 );
  assert( pPage->iWrite>pPage->iRead );

  assert( pPage->iRead<pPage->nSlot );

  *pVal = pPage->aSlot[pPage->iRead++];
  pFifo->nEntry--;
  if( pPage->iRead>=pPage->iWrite ){
    pFifo->pFirst = pPage->pNext;
    sqliteFree(pPage);
    if( pFifo->nEntry==0 ){
      assert( pFifo->pLast==pPage );







>
>
>







 







>

>







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
..
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

/*
** Allocate a new FifoPage and return a pointer to it.  Return NULL if
** we run out of memory.  Leave space on the page for nEntry entries.
*/
static FifoPage *allocatePage(int nEntry){
  FifoPage *pPage;
  if( nEntry>32767 ){
    nEntry = 32767;
  }
  pPage = sqliteMallocRaw( sizeof(FifoPage) + sizeof(i64)*(nEntry-1) );
  if( pPage ){
    pPage->nSlot = nEntry;
    pPage->iWrite = 0;
    pPage->iRead = 0;
    pPage->pNext = 0;
  }
................................................................................
  if( pFifo->nEntry==0 ){
    return SQLITE_DONE;
  }
  assert( pFifo->nEntry>0 );
  pPage = pFifo->pFirst;
  assert( pPage!=0 );
  assert( pPage->iWrite>pPage->iRead );
  assert( pPage->iWrite<=pPage->nSlot );
  assert( pPage->iRead<pPage->nSlot );
  assert( pPage->iRead>=0 );
  *pVal = pPage->aSlot[pPage->iRead++];
  pFifo->nEntry--;
  if( pPage->iRead>=pPage->iWrite ){
    pFifo->pFirst = pPage->pNext;
    sqliteFree(pPage);
    if( pFifo->nEntry==0 ){
      assert( pFifo->pLast==pPage );

Added test/delete3.test.



















































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 2005 August 24
#
# 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 file implements regression tests for SQLite library.  The
# focus of this script is a test of the DELETE command where a
# large number of rows are deleted.
#

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

# Create a table that contains a large number of rows.
#
do_test delete3-1.1 {
  execsql {
    CREATE TABLE t1(x integer primary key);
    BEGIN;
    INSERT INTO t1 VALUES(1);
    INSERT INTO t1 VALUES(2);
    INSERT INTO t1 SELECT x+2 FROM t1;
    INSERT INTO t1 SELECT x+4 FROM t1;
    INSERT INTO t1 SELECT x+8 FROM t1;
    INSERT INTO t1 SELECT x+16 FROM t1;
    INSERT INTO t1 SELECT x+32 FROM t1;
    INSERT INTO t1 SELECT x+64 FROM t1;
    INSERT INTO t1 SELECT x+128 FROM t1;
    INSERT INTO t1 SELECT x+256 FROM t1;
    INSERT INTO t1 SELECT x+512 FROM t1;
    INSERT INTO t1 SELECT x+1024 FROM t1;
    INSERT INTO t1 SELECT x+2048 FROM t1;
    INSERT INTO t1 SELECT x+4096 FROM t1;
    INSERT INTO t1 SELECT x+8192 FROM t1;
    INSERT INTO t1 SELECT x+16384 FROM t1;
    INSERT INTO t1 SELECT x+32768 FROM t1;
    INSERT INTO t1 SELECT x+65536 FROM t1;
    INSERT INTO t1 SELECT x+131072 FROM t1;
    INSERT INTO t1 SELECT x+262144 FROM t1;
    COMMIT;
    SELECT count(*) FROM t1;	
  }
} {524288}
do_test delete3-1.2 {
  execsql {
    DELETE FROM t1 WHERE x%2==0;
    SELECT count(*) FROM t1;
  }
} {262144}
integrity_check delete3-1.3

finish_test