SQLite

Check-in [7bc4f5543f]
Login

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

Overview
Comment:Fix a bug in the btree code for reading varints greater than 2^32. (CVS 1349)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7bc4f5543fbfa9f3fe6e9479a1f85fbaf6c95af4
User & Date: danielk1977 2004-05-11 02:10:07.000
Context
2004-05-11
03:11
Internal symbols MEM_Dyn and MEM_AggCtx were defined as the same bit pattern. Change MEM_AggCtx to 0x1000. (CVS 1350) (check-in: 2fffd133a5 user: danielk1977 tags: trunk)
02:10
Fix a bug in the btree code for reading varints greater than 2^32. (CVS 1349) (check-in: 7bc4f5543f user: danielk1977 tags: trunk)
01:18
Update the main.mk makefile so that it builds everything again. (CVS 1348) (check-in: e6e52fc2e6 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/btree.c.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
** 2004 April 6
**
** 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.
**
*************************************************************************
** $Id: btree.c,v 1.125 2004/05/11 00:58:56 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
**
**     Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
**     "Sorting And Searching", pages 473-480. Addison-Wesley
**     Publishing Company, Reading, Massachusetts.











|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
** 2004 April 6
**
** 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.
**
*************************************************************************
** $Id: btree.c,v 1.126 2004/05/11 02:10:07 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
**
**     Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
**     "Sorting And Searching", pages 473-480. Addison-Wesley
**     Publishing Company, Reading, Massachusetts.
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
** Read a variable-length integer.  Store the result in *pResult.
** Return the number of bytes in the integer.
*/
static unsigned int getVarint(unsigned char *p, u64 *pResult){
  u64 x = p[0] & 0x7f;
  int n = 0;
  while( (p[n++]&0x80)!=0 ){
    x |= (p[n]&0x7f)<<(n*7);
  }
  *pResult = x;
  return n;
}

/*
** Write a variable length integer with value v into p[].  Return







|







305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
** Read a variable-length integer.  Store the result in *pResult.
** Return the number of bytes in the integer.
*/
static unsigned int getVarint(unsigned char *p, u64 *pResult){
  u64 x = p[0] & 0x7f;
  int n = 0;
  while( (p[n++]&0x80)!=0 ){
    x |= ((u64)(p[n]&0x7f))<<(n*7);
  }
  *pResult = x;
  return n;
}

/*
** Write a variable length integer with value v into p[].  Return
Changes to src/test3.c.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
**    May you share freely, never taking more than you give.
**
*************************************************************************
** Code for testing the btree.c module in SQLite.  This code
** is not included in the SQLite library.  It is used for automated
** testing of the SQLite library.
**
** $Id: test3.c,v 1.35 2004/05/11 00:58:56 drh Exp $
*/
#include "sqliteInt.h"
#include "pager.h"
#include "btree.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
**    May you share freely, never taking more than you give.
**
*************************************************************************
** Code for testing the btree.c module in SQLite.  This code
** is not included in the SQLite library.  It is used for automated
** testing of the SQLite library.
**
** $Id: test3.c,v 1.36 2004/05/11 02:10:07 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "pager.h"
#include "btree.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>
682
683
684
685
686
687
688

689
690







691
692
693
694
695
696
697
  if( argc!=4 ){
    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
       " ID KEY DATA\"", 0);
    return TCL_ERROR;
  }
  if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
  if( sqlite3BtreeFlags(pCur) & BTREE_INTKEY ){

    int iKey;
    if( Tcl_GetInt(interp, argv[2], &iKey) ) return TCL_ERROR;







    rc = sqlite3BtreeInsert(pCur, 0, iKey, argv[3], strlen(argv[3]));
  }else{
    rc = sqlite3BtreeInsert(pCur, argv[2], strlen(argv[2]),
                         argv[3], strlen(argv[3]));
  }
  if( rc ){
    Tcl_AppendResult(interp, errorName(rc), 0);







>


>
>
>
>
>
>
>







682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
  if( argc!=4 ){
    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
       " ID KEY DATA\"", 0);
    return TCL_ERROR;
  }
  if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
  if( sqlite3BtreeFlags(pCur) & BTREE_INTKEY ){
/*
    int iKey;
    if( Tcl_GetInt(interp, argv[2], &iKey) ) return TCL_ERROR;
*/
    i64 iKey;
    Tcl_Obj *obj = Tcl_NewStringObj(argv[2], -1);
    Tcl_IncrRefCount(obj);
    if( Tcl_GetWideIntFromObj(interp, obj, &iKey) ) return TCL_ERROR;
    Tcl_DecrRefCount(obj);

    rc = sqlite3BtreeInsert(pCur, 0, iKey, argv[3], strlen(argv[3]));
  }else{
    rc = sqlite3BtreeInsert(pCur, argv[2], strlen(argv[2]),
                         argv[3], strlen(argv[3]));
  }
  if( rc ){
    Tcl_AppendResult(interp, errorName(rc), 0);
Changes to src/vdbe.c.
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
**
** Various scripts scan this source file in order to generate HTML
** documentation, headers files, or other derived files.  The formatting
** of the code in this file is, therefore, important.  See other comments
** in this file for details.  If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.275 2004/05/11 00:28:43 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
#include "vdbeInt.h"

/*







|







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
**
** Various scripts scan this source file in order to generate HTML
** documentation, headers files, or other derived files.  The formatting
** of the code in this file is, therefore, important.  See other comments
** in this file for details.  If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.276 2004/05/11 02:10:07 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
#include "vdbeInt.h"

/*
3207
3208
3209
3210
3211
3212
3213
3214

3215
3216
3217
3218
3219
3220
3221
    }else{
      assert( pNos->flags & MEM_Int );

      /* If the table is an INTKEY table, set nKey to the value of
      ** the integer key, and zKey to NULL.
      */
      if( pC->intKey ){
        nKey = pNos->i;

        zKey = 0;
      }else{
        /* TODO: can this happen? zKey is not correctly byte-ordered here! */
        assert(!"TODO");
        nKey = sizeof(i64);
        zKey = (char*)&iKey;
      }







|
>







3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
    }else{
      assert( pNos->flags & MEM_Int );

      /* If the table is an INTKEY table, set nKey to the value of
      ** the integer key, and zKey to NULL.
      */
      if( pC->intKey ){
        nKey = intToKey(pNos->i);
        assert( keyToInt(nKey)==pNos->i );
        zKey = 0;
      }else{
        /* TODO: can this happen? zKey is not correctly byte-ordered here! */
        assert(!"TODO");
        nKey = sizeof(i64);
        zKey = (char*)&iKey;
      }