SQLite

Check-in [6a6b943736]
Login

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

Overview
Comment:Do a slow-path in GetVarint32() for varints that do not fit in 32 bits. This will only happen when trying to interpret a corrupt database file so speed is not critical. (CVS 5129)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6a6b9437367b66c3b6f710cf3abbdb9841765b21
User & Date: drh 2008-05-13 16:41:50.000
Context
2008-05-13
19:41
On instruction from DRH, only do malloc failure tests for O/S ops on non-Windows systems. Better test fixture code will be introduced in 3.6.0 to add this coverage back in for Windows. (CVS 5130) (check-in: e4aab15004 user: shane tags: trunk)
16:41
Do a slow-path in GetVarint32() for varints that do not fit in 32 bits. This will only happen when trying to interpret a corrupt database file so speed is not critical. (CVS 5129) (check-in: 6a6b943736 user: drh tags: trunk)
13:27
Make the benign-fault setting recursive. Make all malloc failures during a rollback benign since there is nothing we can do about them. (CVS 5128) (check-in: a9d1d93135 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/util.c.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
**
*************************************************************************
** Utility functions used throughout sqlite.
**
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.228 2008/05/11 11:07:07 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
#include <ctype.h>


/*







|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
**
*************************************************************************
** Utility functions used throughout sqlite.
**
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.229 2008/05/13 16:41:50 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
#include <ctype.h>


/*
776
777
778
779
780
781
782
783
784

785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
    a &= (0x7f<<28)|(0x7f<<14)|(0x7f);
    b &= (0x7f<<28)|(0x7f<<14)|(0x7f);
    b = b<<7;
    *v = a | b;
    return 5;
  }

  p++;
  b = b<<14;

  b |= *p;
  // b: p1<<28 | p3<<14 | p5 (unmasked)
  if (!(b&0x80))
  {
    b &= (0x7f<<28)|(0x7f<<14)|(0x7f);
    a &= (0x7f<<28)|(0x7f<<14)|(0x7f);
    a = a<<7;
    *v = a | b;
    return 6;
  }

  p++;
  a = a<<14;
  a |= *p;
  // a: p2<<28 | p4<<14 | p6 (unmasked)
  if (!(a&0x80))
  {
    a &= (0x7f<<28)|(0x7f<<14)|(0x7f);
    b &= (0x7f<<28)|(0x7f<<14)|(0x7f);
    b = b<<7;
    *v = a | b;
    return 7;
  }

  p++;
  b = b<<14;
  b |= *p;
  // b: p3<<28 | p5<<14 | p7 (unmasked)
  if (!(b&0x80))
  {
    b &= (0x7f<<28)|(0x7f<<14)|(0x7f);
    a &= (0x7f<<28)|(0x7f<<14)|(0x7f);
    a = a<<7;
    *v = a | b;
    return 8;
  }

  p++;
  a = a<<14;
  a |= *p;
  // a: p4<<28 | p6<<14 | p8 (unmasked)

  a &= (0x7f<<28)|(0x7f<<14)|(0x7f);
  b &= (0x7f<<28)|(0x7f<<14)|(0x7f);
  b = b<<7;
  *v = a | b;
  return 9;
}

/*
** Return the number of bytes that will be needed to store the given
** 64-bit integer.
*/
int sqlite3VarintLen(u64 v){







|
|
>
|
<
<

<
<
<
<
<
<
|
<
<
|
<
<
|
<
<
|
|
<
<
|
<
<
<
<
<
<
<
<
<
|
|

<
<
<
<
<
<
<
<
<
<
<







776
777
778
779
780
781
782
783
784
785
786


787






788


789


790


791
792


793









794
795
796











797
798
799
800
801
802
803
    a &= (0x7f<<28)|(0x7f<<14)|(0x7f);
    b &= (0x7f<<28)|(0x7f<<14)|(0x7f);
    b = b<<7;
    *v = a | b;
    return 5;
  }

  /* We can only reach this point when reading a corrupt database
  ** file.  In that case we are not in any hurry.  Use the (relatively
  ** slow) general-purpose sqlite3GetVarint() routine to extract the
  ** value. */


  {






    u64 v64;


    int n;





    p -= 4;
    n = sqlite3GetVarint(p, &v64);


    assert( n>5 && n<=9 );









    *v = (u32)v64;
    return n;
  }











}

/*
** Return the number of bytes that will be needed to store the given
** 64-bit integer.
*/
int sqlite3VarintLen(u64 v){