4
** The author disclaims copyright to this source code. In place of
5
** a legal notice, here is a blessing:
7
** May you do good and not evil.
8
** May you find forgiveness for yourself and forgive others.
9
** May you share freely, never taking more than you give.
11
*************************************************************************
12
** Utility functions used throughout sqlite.
14
** This file contains functions for allocating memory, comparing
15
** strings, and stuff like that.
17
** $Id: util.c,v 1.132 2005/03/18 14:03:15 drh Exp $
19
#include "sqliteInt.h"
23
#if SQLITE_MEMDEBUG>2 && defined(__GLIBC__)
25
void print_stack_trace(){
28
int n = backtrace(bt, 30);
30
fprintf(stderr, "STACK: ");
32
fprintf(stderr, "%p ", bt[i]);
34
fprintf(stderr, "\n");
37
#define print_stack_trace()
41
** If malloc() ever fails, this global variable gets set to 1.
42
** This causes the library to abort and never again function.
44
int sqlite3_malloc_failed = 0;
47
** If SQLITE_MEMDEBUG is defined, then use versions of malloc() and
48
** free() that track memory usage and check for buffer overruns.
50
#ifdef SQLITE_MEMDEBUG
53
** For keeping track of the number of mallocs and frees. This
54
** is used to check for memory leaks. The iMallocFail and iMallocReset
55
** values are used to simulate malloc() failures during testing in
56
** order to verify that the library correctly handles an out-of-memory
59
int sqlite3_nMalloc; /* Number of sqliteMalloc() calls */
60
int sqlite3_nFree; /* Number of sqliteFree() calls */
61
int sqlite3_iMallocFail; /* Fail sqliteMalloc() after this many calls */
62
int sqlite3_iMallocReset = -1; /* When iMallocFail reaches 0, set to this */
64
static int memcnt = 0;
68
** Number of 32-bit guard words
73
** Allocate new memory and set it to zero. Return NULL if
74
** no memory is available.
76
void *sqlite3Malloc_(int n, int bZero, char *zFile, int line){
80
if( sqlite3_iMallocFail>=0 ){
81
sqlite3_iMallocFail--;
82
if( sqlite3_iMallocFail==0 ){
83
sqlite3_malloc_failed++;
85
fprintf(stderr,"**** failed to allocate %d bytes at %s:%d\n",
88
sqlite3_iMallocFail = sqlite3_iMallocReset;
93
k = (n+sizeof(int)-1)/sizeof(int);
94
pi = malloc( (N_GUARD*2+1+k)*sizeof(int));
96
if( n>0 ) sqlite3_malloc_failed++;
100
for(i=0; i<N_GUARD; i++) pi[i] = 0xdead1122;
102
for(i=0; i<N_GUARD; i++) pi[k+1+N_GUARD+i] = 0xdead3344;
104
memset(p, bZero==0, n);
105
#if SQLITE_MEMDEBUG>1
107
fprintf(stderr,"%06d malloc %d bytes at 0x%x from %s:%d\n",
108
++memcnt, n, (int)p, zFile,line);
114
** Check to see if the given pointer was obtained from sqliteMalloc()
115
** and is able to hold at least N bytes. Raise an exception if this
118
** This routine is used for testing purposes only.
120
void sqlite3CheckMemory(void *p, int N){
124
for(i=0; i<N_GUARD; i++){
125
assert( pi[i]==0xdead1122 );
128
assert( N>=0 && N<n );
129
k = (n+sizeof(int)-1)/sizeof(int);
130
for(i=0; i<N_GUARD; i++){
131
assert( pi[k+N_GUARD+1+i]==0xdead3344 );
136
** Free memory previously obtained from sqliteMalloc()
138
void sqlite3Free_(void *p, char *zFile, int line){
144
for(i=0; i<N_GUARD; i++){
145
if( pi[i]!=0xdead1122 ){
146
fprintf(stderr,"Low-end memory corruption at 0x%x\n", (int)p);
151
k = (n+sizeof(int)-1)/sizeof(int);
152
for(i=0; i<N_GUARD; i++){
153
if( pi[k+N_GUARD+1+i]!=0xdead3344 ){
154
fprintf(stderr,"High-end memory corruption at 0x%x\n", (int)p);
158
memset(pi, 0xff, (k+N_GUARD*2+1)*sizeof(int));
159
#if SQLITE_MEMDEBUG>1
160
fprintf(stderr,"%06d free %d bytes at 0x%x from %s:%d\n",
161
++memcnt, n, (int)p, zFile,line);
168
** Resize a prior allocation. If p==0, then this routine
169
** works just like sqliteMalloc(). If n==0, then this routine
170
** works just like sqliteFree().
172
void *sqlite3Realloc_(void *oldP, int n, char *zFile, int line){
173
int *oldPi, *pi, i, k, oldN, oldK;
176
return sqlite3Malloc_(n,1,zFile,line);
179
sqlite3Free_(oldP,zFile,line);
184
if( oldPi[0]!=0xdead1122 ){
185
fprintf(stderr,"Low-end memory corruption in realloc at 0x%x\n", (int)oldP);
188
oldN = oldPi[N_GUARD];
189
oldK = (oldN+sizeof(int)-1)/sizeof(int);
190
for(i=0; i<N_GUARD; i++){
191
if( oldPi[oldK+N_GUARD+1+i]!=0xdead3344 ){
192
fprintf(stderr,"High-end memory corruption in realloc at 0x%x\n",
197
k = (n + sizeof(int) - 1)/sizeof(int);
198
pi = malloc( (k+N_GUARD*2+1)*sizeof(int) );
200
if( n>0 ) sqlite3_malloc_failed++;
203
for(i=0; i<N_GUARD; i++) pi[i] = 0xdead1122;
205
for(i=0; i<N_GUARD; i++) pi[k+N_GUARD+1+i] = 0xdead3344;
207
memcpy(p, oldP, n>oldN ? oldN : n);
209
memset(&((char*)p)[oldN], 0x55, n-oldN);
211
memset(oldPi, 0xab, (oldK+N_GUARD+2)*sizeof(int));
213
#if SQLITE_MEMDEBUG>1
215
fprintf(stderr,"%06d realloc %d to %d bytes at 0x%x to 0x%x at %s:%d\n",
216
++memcnt, oldN, n, (int)oldP, (int)p, zFile, line);
222
** Make a copy of a string in memory obtained from sqliteMalloc()
224
char *sqlite3StrDup_(const char *z, char *zFile, int line){
227
zNew = sqlite3Malloc_(strlen(z)+1, 0, zFile, line);
228
if( zNew ) strcpy(zNew, z);
231
char *sqlite3StrNDup_(const char *z, int n, char *zFile, int line){
234
zNew = sqlite3Malloc_(n+1, 0, zFile, line);
243
** A version of sqliteFree that is always a function, not a macro.
245
void sqlite3FreeX(void *p){
248
#endif /* SQLITE_MEMDEBUG */
251
** The following versions of malloc() and free() are for use in a
254
#if !defined(SQLITE_MEMDEBUG)
257
** Allocate new memory and set it to zero. Return NULL if
258
** no memory is available. See also sqliteMallocRaw().
260
void *sqlite3Malloc(int n){
262
if( (p = malloc(n))==0 ){
263
if( n>0 ) sqlite3_malloc_failed++;
271
** Allocate new memory but do not set it to zero. Return NULL if
272
** no memory is available. See also sqliteMalloc().
274
void *sqlite3MallocRaw(int n){
276
if( (p = malloc(n))==0 ){
277
if( n>0 ) sqlite3_malloc_failed++;
283
** Free memory previously obtained from sqliteMalloc()
285
void sqlite3FreeX(void *p){
292
** Resize a prior allocation. If p==0, then this routine
293
** works just like sqliteMalloc(). If n==0, then this routine
294
** works just like sqliteFree().
296
void *sqlite3Realloc(void *p, int n){
299
return sqliteMalloc(n);
307
if( n>0 ) sqlite3_malloc_failed++;
313
** Make a copy of a string in memory obtained from sqliteMalloc()
315
char *sqlite3StrDup(const char *z){
318
zNew = sqliteMallocRaw(strlen(z)+1);
319
if( zNew ) strcpy(zNew, z);
322
char *sqlite3StrNDup(const char *z, int n){
325
zNew = sqliteMallocRaw(n+1);
332
#endif /* !defined(SQLITE_MEMDEBUG) */
335
** Create a string from the 2nd and subsequent arguments (up to the
336
** first NULL argument), store the string in memory obtained from
337
** sqliteMalloc() and make the pointer indicated by the 1st argument
338
** point to that string. The 1st argument must either be NULL or
339
** point to memory obtained from sqliteMalloc().
341
void sqlite3SetString(char **pz, const char *zFirst, ...){
348
nByte = strlen(zFirst) + 1;
349
va_start(ap, zFirst);
350
while( (z = va_arg(ap, const char*))!=0 ){
355
*pz = zResult = sqliteMallocRaw( nByte );
359
strcpy(zResult, zFirst);
360
zResult += strlen(zResult);
361
va_start(ap, zFirst);
362
while( (z = va_arg(ap, const char*))!=0 ){
364
zResult += strlen(zResult);
369
fprintf(stderr,"string at 0x%x is %s\n", (int)*pz, *pz);
375
** Set the most recent error code and error string for the sqlite
376
** handle "db". The error code is set to "err_code".
378
** If it is not NULL, string zFormat specifies the format of the
379
** error string in the style of the printf functions: The following
380
** format characters are allowed:
382
** %s Insert a string
383
** %z A string that should be freed after use
384
** %d Insert an integer
386
** %S Insert the first element of a SrcList
388
** zFormat and any string tokens that follow it are assumed to be
391
** To clear the most recent error for slqite handle "db", sqlite3Error
392
** should be called with err_code set to SQLITE_OK and zFormat set
395
void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){
396
if( db && (db->pErr || (db->pErr = sqlite3ValueNew())) ){
397
db->errCode = err_code;
401
va_start(ap, zFormat);
402
z = sqlite3VMPrintf(zFormat, ap);
404
sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, sqlite3FreeX);
406
sqlite3ValueSetStr(db->pErr, 0, 0, SQLITE_UTF8, SQLITE_STATIC);
412
** Add an error message to pParse->zErrMsg and increment pParse->nErr.
413
** The following formatting characters are allowed:
415
** %s Insert a string
416
** %z A string that should be freed after use
417
** %d Insert an integer
419
** %S Insert the first element of a SrcList
421
** This function should be used to report any error that occurs whilst
422
** compiling an SQL statement (i.e. within sqlite3_prepare()). The
423
** last thing the sqlite3_prepare() function does is copy the error
424
** stored by this function into the database handle using sqlite3Error().
425
** Function sqlite3Error() should be used during statement execution
426
** (sqlite3_step() etc.).
428
void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
431
sqliteFree(pParse->zErrMsg);
432
va_start(ap, zFormat);
433
pParse->zErrMsg = sqlite3VMPrintf(zFormat, ap);
438
** Convert an SQL-style quoted string into a normal string by removing
439
** the quote characters. The conversion is done in-place. If the
440
** input does not begin with a quote character, then this routine
443
** 2002-Feb-14: This routine is extended to remove MS-Access style
444
** brackets from around identifers. For example: "[a-b-c]" becomes
447
void sqlite3Dequote(char *z){
455
case '[': quote = ']'; break;
458
for(i=1, j=0; z[i]; i++){
473
/* An array to map all upper-case characters into their corresponding
474
** lower-case character.
476
const unsigned char sqlite3UpperToLower[] = {
477
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
478
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
479
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
480
54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 97, 98, 99,100,101,102,103,
481
104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,
482
122, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,102,103,104,105,106,107,
483
108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,
484
126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
485
144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,
486
162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,
487
180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,
488
198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
489
216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,
490
234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,
493
#define UpperToLower sqlite3UpperToLower
496
** Some systems have stricmp(). Others have strcasecmp(). Because
497
** there is no consistency, we will define our own.
499
int sqlite3StrICmp(const char *zLeft, const char *zRight){
500
register unsigned char *a, *b;
501
a = (unsigned char *)zLeft;
502
b = (unsigned char *)zRight;
503
while( *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
504
return UpperToLower[*a] - UpperToLower[*b];
506
int sqlite3StrNICmp(const char *zLeft, const char *zRight, int N){
507
register unsigned char *a, *b;
508
a = (unsigned char *)zLeft;
509
b = (unsigned char *)zRight;
510
while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
511
return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
515
** Return TRUE if z is a pure numeric string. Return FALSE if the
516
** string contains any character which is not part of a number. If
517
** the string is numeric and contains the '.' character, set *realnum
518
** to TRUE (otherwise FALSE).
520
** An empty string is considered non-numeric.
522
int sqlite3IsNumber(const char *z, int *realnum, u8 enc){
523
int incr = (enc==SQLITE_UTF8?1:2);
524
if( enc==SQLITE_UTF16BE ) z++;
525
if( *z=='-' || *z=='+' ) z += incr;
526
if( !isdigit(*(u8*)z) ){
530
if( realnum ) *realnum = 0;
531
while( isdigit(*(u8*)z) ){ z += incr; }
534
if( !isdigit(*(u8*)z) ) return 0;
535
while( isdigit(*(u8*)z) ){ z += incr; }
536
if( realnum ) *realnum = 1;
538
if( *z=='e' || *z=='E' ){
540
if( *z=='+' || *z=='-' ) z += incr;
541
if( !isdigit(*(u8*)z) ) return 0;
542
while( isdigit(*(u8*)z) ){ z += incr; }
543
if( realnum ) *realnum = 1;
549
** The string z[] is an ascii representation of a real number.
550
** Convert this string to a double.
552
** This routine assumes that z[] really is a valid number. If it
553
** is not, the result is undefined.
555
** This routine is used instead of the library atof() function because
556
** the library atof() might want to use "," as the decimal point instead
557
** of "." depending on how locale is set. But that would cause problems
558
** for SQL. So this routine always uses "." regardless of locale.
560
double sqlite3AtoF(const char *z, const char **pzEnd){
562
LONGDOUBLE_TYPE v1 = 0.0;
569
while( isdigit(*(u8*)z) ){
570
v1 = v1*10.0 + (*z - '0');
574
LONGDOUBLE_TYPE divisor = 1.0;
576
while( isdigit(*(u8*)z) ){
577
v1 = v1*10.0 + (*z - '0');
583
if( *z=='e' || *z=='E' ){
586
LONGDOUBLE_TYPE scale = 1.0;
594
while( isdigit(*(u8*)z) ){
595
eval = eval*10 + *z - '0';
598
while( eval>=64 ){ scale *= 1.0e+64; eval -= 64; }
599
while( eval>=16 ){ scale *= 1.0e+16; eval -= 16; }
600
while( eval>=4 ){ scale *= 1.0e+4; eval -= 4; }
601
while( eval>=1 ){ scale *= 1.0e+1; eval -= 1; }
608
if( pzEnd ) *pzEnd = z;
609
return sign<0 ? -v1 : v1;
613
** Return TRUE if zNum is a 64-bit signed integer and write
614
** the value of the integer into *pNum. If zNum is not an integer
615
** or is an integer that is too large to be expressed with 64 bits,
616
** then return false. If n>0 and the integer is string is not
617
** exactly n bytes long, return false.
619
** When this routine was originally written it dealt with only
620
** 32-bit numbers. At that time, it was much faster than the
621
** atoi() library routine in RedHat 7.2.
623
int sqlite3atoi64(const char *zNum, i64 *pNum){
630
}else if( *zNum=='+' ){
636
for(i=0; (c=zNum[i])>='0' && c<='9'; i++){
639
*pNum = neg ? -v : v;
640
return c==0 && i>0 &&
641
(i<19 || (i==19 && memcmp(zNum,"9223372036854775807",19)<=0));
645
** The string zNum represents an integer. There might be some other
646
** information following the integer too, but that part is ignored.
647
** If the integer that the prefix of zNum represents will fit in a
648
** 32-bit signed integer, return TRUE. Otherwise return FALSE.
650
** This routine returns FALSE for the string -2147483648 even that
651
** that number will in fact fit in a 32-bit integer. But positive
652
** 2147483648 will not fit in 32 bits. So it seems safer to return
655
static int sqlite3FitsIn32Bits(const char *zNum){
657
if( *zNum=='-' || *zNum=='+' ) zNum++;
658
for(i=0; (c=zNum[i])>='0' && c<='9'; i++){}
659
return i<10 || (i==10 && memcmp(zNum,"2147483647",10)<=0);
663
** If zNum represents an integer that will fit in 32-bits, then set
664
** *pValue to that integer and return true. Otherwise return false.
666
int sqlite3GetInt32(const char *zNum, int *pValue){
667
if( sqlite3FitsIn32Bits(zNum) ){
668
*pValue = atoi(zNum);
675
** The string zNum represents an integer. There might be some other
676
** information following the integer too, but that part is ignored.
677
** If the integer that the prefix of zNum represents will fit in a
678
** 64-bit signed integer, return TRUE. Otherwise return FALSE.
680
** This routine returns FALSE for the string -9223372036854775808 even that
681
** that number will, in theory fit in a 64-bit integer. Positive
682
** 9223373036854775808 will not fit in 64 bits. So it seems safer to return
685
int sqlite3FitsIn64Bits(const char *zNum){
687
if( *zNum=='-' || *zNum=='+' ) zNum++;
688
for(i=0; (c=zNum[i])>='0' && c<='9'; i++){}
689
return i<19 || (i==19 && memcmp(zNum,"9223372036854775807",19)<=0);
694
** Change the sqlite.magic from SQLITE_MAGIC_OPEN to SQLITE_MAGIC_BUSY.
695
** Return an error (non-zero) if the magic was not SQLITE_MAGIC_OPEN
696
** when this routine is called.
698
** This routine is a attempt to detect if two threads use the
699
** same sqlite* pointer at the same time. There is a race
700
** condition so it is possible that the error is not detected.
701
** But usually the problem will be seen. The result will be an
702
** error which can be used to debug the application that is
703
** using SQLite incorrectly.
705
** Ticket #202: If db->magic is not a valid open value, take care not
706
** to modify the db structure at all. It could be that db is a stale
707
** pointer. In other words, it could be that there has been a prior
708
** call to sqlite3_close(db) and db has been deallocated. And we do
709
** not want to write into deallocated memory.
711
int sqlite3SafetyOn(sqlite3 *db){
712
if( db->magic==SQLITE_MAGIC_OPEN ){
713
db->magic = SQLITE_MAGIC_BUSY;
715
}else if( db->magic==SQLITE_MAGIC_BUSY || db->magic==SQLITE_MAGIC_ERROR ){
716
db->magic = SQLITE_MAGIC_ERROR;
717
db->flags |= SQLITE_Interrupt;
723
** Change the magic from SQLITE_MAGIC_BUSY to SQLITE_MAGIC_OPEN.
724
** Return an error (non-zero) if the magic was not SQLITE_MAGIC_BUSY
725
** when this routine is called.
727
int sqlite3SafetyOff(sqlite3 *db){
728
if( db->magic==SQLITE_MAGIC_BUSY ){
729
db->magic = SQLITE_MAGIC_OPEN;
731
}else if( db->magic==SQLITE_MAGIC_OPEN || db->magic==SQLITE_MAGIC_ERROR ){
732
db->magic = SQLITE_MAGIC_ERROR;
733
db->flags |= SQLITE_Interrupt;
739
** Check to make sure we have a valid db pointer. This test is not
740
** foolproof but it does provide some measure of protection against
741
** misuse of the interface such as passing in db pointers that are
742
** NULL or which have been previously closed. If this routine returns
743
** TRUE it means that the db pointer is invalid and should not be
744
** dereferenced for any reason. The calling function should invoke
745
** SQLITE_MISUSE immediately.
747
int sqlite3SafetyCheck(sqlite3 *db){
749
if( db==0 ) return 1;
751
if( magic!=SQLITE_MAGIC_CLOSED &&
752
magic!=SQLITE_MAGIC_OPEN &&
753
magic!=SQLITE_MAGIC_BUSY ) return 1;
758
** The variable-length integer encoding is as follows:
761
** A = 0xxxxxxx 7 bits of data and one flag bit
762
** B = 1xxxxxxx 7 bits of data and one flag bit
763
** C = xxxxxxxx 8 bits of data
772
** 56 bits - BBBBBBBA
773
** 64 bits - BBBBBBBBC
777
** Write a 64-bit variable-length integer to memory starting at p[0].
778
** The length of data write will be between 1 and 9 bytes. The number
779
** of bytes written is returned.
781
** A variable-length integer consists of the lower 7 bits of each byte
782
** for all bytes that have the 8th bit set and one byte with the 8th
783
** bit clear. Except, if we get to the 9th byte, it stores the full
784
** 8 bits and is the last byte.
786
int sqlite3PutVarint(unsigned char *p, u64 v){
789
if( v & (((u64)0xff000000)<<32) ){
793
p[i] = (v & 0x7f) | 0x80;
800
buf[n++] = (v & 0x7f) | 0x80;
805
for(i=0, j=n-1; j>=0; j--, i++){
812
** Read a 64-bit variable-length integer from memory starting at p[0].
813
** Return the number of bytes read. The value is stored in *v.
815
int sqlite3GetVarint(const unsigned char *p, u64 *v){
820
if( ((c = p[0]) & 0x80)==0 ){
825
if( ((c = p[1]) & 0x80)==0 ){
829
x = (x<<7) | (c&0x7f);
830
if( ((c = p[2]) & 0x80)==0 ){
834
x = (x<<7) | (c&0x7f);
835
if( ((c = p[3]) & 0x80)==0 ){
839
x64 = (x<<7) | (c&0x7f);
847
x64 = (x64<<7) | (c&0x7f);
848
}while( (c & 0x80)!=0 );
854
** Read a 32-bit variable-length integer from memory starting at p[0].
855
** Return the number of bytes read. The value is stored in *v.
857
int sqlite3GetVarint32(const unsigned char *p, u32 *v){
861
if( ((signed char*)p)[0]>=0 ){
866
if( ((signed char*)p)[1]>=0 ){
870
x = (x<<7) | (p[1] & 0x7f);
873
x = (x<<7) | ((c = p[n++])&0x7f);
874
}while( (c & 0x80)!=0 && n<9 );
880
** Return the number of bytes that will be needed to store the given
883
int sqlite3VarintLen(u64 v){
888
}while( v!=0 && i<9 );
892
#if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC) \
893
|| defined(SQLITE_TEST)
895
** Translate a single byte of Hex into an integer.
897
static int hexToInt(int h){
898
if( h>='0' && h<='9' ){
900
}else if( h>='a' && h<='f' ){
903
assert( h>='A' && h<='F' );
907
#endif /* !SQLITE_OMIT_BLOB_LITERAL || SQLITE_HAS_CODEC || SQLITE_TEST */
909
#if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC)
911
** Convert a BLOB literal of the form "x'hhhhhh'" into its binary
912
** value. Return a pointer to its binary value. Space to hold the
913
** binary value has been obtained from malloc and must be freed by
914
** the calling routine.
916
void *sqlite3HexToBlob(const char *z){
922
zBlob = (char *)sqliteMalloc(n/2);
924
zBlob[i/2] = (hexToInt(z[i])<<4) | hexToInt(z[i+1]);
928
#endif /* !SQLITE_OMIT_BLOB_LITERAL || SQLITE_HAS_CODEC */
930
#if defined(SQLITE_TEST)
932
** Convert text generated by the "%p" conversion format back into
935
void *sqlite3TextToPtr(const char *z){
939
if( z[0]=='0' && z[1]=='x' ){
944
v = (v<<4) + hexToInt(*z);
947
if( sizeof(p)==sizeof(v) ){
950
assert( sizeof(p)==sizeof(v2) );