Index: third_party/sqlite/src/src/util.c |
diff --git a/third_party/sqlite/src/src/util.c b/third_party/sqlite/src/src/util.c |
index 9bb8d89157764c3cb98e7b5dfe3ca304e891cc3f..b4c5e62bb308f772a675057b63effab6e269b9e0 100644 |
--- a/third_party/sqlite/src/src/util.c |
+++ b/third_party/sqlite/src/src/util.c |
@@ -17,7 +17,7 @@ |
*/ |
#include "sqliteInt.h" |
#include <stdarg.h> |
-#ifdef SQLITE_HAVE_ISNAN |
+#if HAVE_ISNAN || SQLITE_HAVE_ISNAN |
# include <math.h> |
#endif |
@@ -58,7 +58,7 @@ int sqlite3FaultSim(int iTest){ |
*/ |
int sqlite3IsNaN(double x){ |
int rc; /* The value return */ |
-#if !defined(SQLITE_HAVE_ISNAN) |
+#if !SQLITE_HAVE_ISNAN && !HAVE_ISNAN |
/* |
** Systems that support the isnan() library function should probably |
** make use of it by compiling with -DSQLITE_HAVE_ISNAN. But we have |
@@ -88,9 +88,9 @@ int sqlite3IsNaN(double x){ |
volatile double y = x; |
volatile double z = y; |
rc = (y!=z); |
-#else /* if defined(SQLITE_HAVE_ISNAN) */ |
+#else /* if HAVE_ISNAN */ |
rc = isnan(x); |
-#endif /* SQLITE_HAVE_ISNAN */ |
+#endif /* HAVE_ISNAN */ |
testcase( rc ); |
return rc; |
} |
@@ -105,10 +105,8 @@ int sqlite3IsNaN(double x){ |
** than 1GiB) the value returned might be less than the true string length. |
*/ |
int sqlite3Strlen30(const char *z){ |
- const char *z2 = z; |
if( z==0 ) return 0; |
- while( *z2 ){ z2++; } |
- return 0x3fffffff & (int)(z2 - z); |
+ return 0x3fffffff & (int)strlen(z); |
} |
/* |
@@ -251,6 +249,11 @@ int sqlite3Dequote(char *z){ |
*/ |
int sqlite3_stricmp(const char *zLeft, const char *zRight){ |
register unsigned char *a, *b; |
+ if( zLeft==0 ){ |
+ return zRight ? -1 : 0; |
+ }else if( zRight==0 ){ |
+ return 1; |
+ } |
a = (unsigned char *)zLeft; |
b = (unsigned char *)zRight; |
while( *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } |
@@ -258,6 +261,11 @@ int sqlite3_stricmp(const char *zLeft, const char *zRight){ |
} |
int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){ |
register unsigned char *a, *b; |
+ if( zLeft==0 ){ |
+ return zRight ? -1 : 0; |
+ }else if( zRight==0 ){ |
+ return 1; |
+ } |
a = (unsigned char *)zLeft; |
b = (unsigned char *)zRight; |
while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } |
@@ -547,7 +555,8 @@ int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){ |
testcase( i==18 ); |
testcase( i==19 ); |
testcase( i==20 ); |
- if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) || i>19*incr || nonNum ){ |
+ if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) |
+ || i>19*incr || nonNum ){ |
/* zNum is empty or contains non-numeric text or is longer |
** than 19 digits (thus guaranteeing that it is too large) */ |
return 1; |
@@ -645,6 +654,7 @@ int sqlite3GetInt32(const char *zNum, int *pValue){ |
} |
} |
#endif |
+ while( zNum[0]=='0' ) zNum++; |
for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){ |
v = v*10 + c; |
} |
@@ -835,7 +845,8 @@ u8 sqlite3GetVarint(const unsigned char *p, u64 *v){ |
/* a: p0<<28 | p2<<14 | p4 (unmasked) */ |
if (!(a&0x80)) |
{ |
- /* we can skip these cause they were (effectively) done above in calc'ing s */ |
+ /* we can skip these cause they were (effectively) done above |
+ ** while calculating s */ |
/* a &= (0x7f<<28)|(0x7f<<14)|(0x7f); */ |
/* b &= (0x7f<<14)|(0x7f); */ |
b = b<<7; |
@@ -1056,11 +1067,8 @@ u8 sqlite3GetVarint32(const unsigned char *p, u32 *v){ |
** 64-bit integer. |
*/ |
int sqlite3VarintLen(u64 v){ |
- int i = 0; |
- do{ |
- i++; |
- v >>= 7; |
- }while( v!=0 && ALWAYS(i<9) ); |
+ int i; |
+ for(i=1; (v >>= 7)!=0; i++){ assert( i<9 ); } |
return i; |
} |
@@ -1069,14 +1077,40 @@ int sqlite3VarintLen(u64 v){ |
** Read or write a four-byte big-endian integer value. |
*/ |
u32 sqlite3Get4byte(const u8 *p){ |
+#if SQLITE_BYTEORDER==4321 |
+ u32 x; |
+ memcpy(&x,p,4); |
+ return x; |
+#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ |
+ && defined(__GNUC__) && GCC_VERSION>=4003000 |
+ u32 x; |
+ memcpy(&x,p,4); |
+ return __builtin_bswap32(x); |
+#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ |
+ && defined(_MSC_VER) && _MSC_VER>=1300 |
+ u32 x; |
+ memcpy(&x,p,4); |
+ return _byteswap_ulong(x); |
+#else |
testcase( p[0]&0x80 ); |
return ((unsigned)p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]; |
+#endif |
} |
void sqlite3Put4byte(unsigned char *p, u32 v){ |
+#if SQLITE_BYTEORDER==4321 |
+ memcpy(p,&v,4); |
+#elif SQLITE_BYTEORDER==1234 && defined(__GNUC__) && GCC_VERSION>=4003000 |
+ u32 x = __builtin_bswap32(v); |
+ memcpy(p,&x,4); |
+#elif SQLITE_BYTEORDER==1234 && defined(_MSC_VER) && _MSC_VER>=1300 |
+ u32 x = _byteswap_ulong(v); |
+ memcpy(p,&x,4); |
+#else |
p[0] = (u8)(v>>24); |
p[1] = (u8)(v>>16); |
p[2] = (u8)(v>>8); |
p[3] = (u8)v; |
+#endif |
} |