| Index: third_party/sqlite/src/src/printf.c | 
| diff --git a/third_party/sqlite/src/src/printf.c b/third_party/sqlite/src/src/printf.c | 
| index 969950c15484c9e4c8263923fb7b6554885688c8..ede86f12088f4b307c97d9aea9490b58e2974c9f 100644 | 
| --- a/third_party/sqlite/src/src/printf.c | 
| +++ b/third_party/sqlite/src/src/printf.c | 
| @@ -15,26 +15,26 @@ | 
| ** Conversion types fall into various categories as defined by the | 
| ** following enumeration. | 
| */ | 
| -#define etRADIX       1 /* Integer types.  %d, %x, %o, and so forth */ | 
| -#define etFLOAT       2 /* Floating point.  %f */ | 
| -#define etEXP         3 /* Exponentional notation. %e and %E */ | 
| -#define etGENERIC     4 /* Floating or exponential, depending on exponent. %g */ | 
| -#define etSIZE        5 /* Return number of characters processed so far. %n */ | 
| -#define etSTRING      6 /* Strings. %s */ | 
| -#define etDYNSTRING   7 /* Dynamically allocated strings. %z */ | 
| -#define etPERCENT     8 /* Percent symbol. %% */ | 
| -#define etCHARX       9 /* Characters. %c */ | 
| +#define etRADIX       0 /* Integer types.  %d, %x, %o, and so forth */ | 
| +#define etFLOAT       1 /* Floating point.  %f */ | 
| +#define etEXP         2 /* Exponentional notation. %e and %E */ | 
| +#define etGENERIC     3 /* Floating or exponential, depending on exponent. %g */ | 
| +#define etSIZE        4 /* Return number of characters processed so far. %n */ | 
| +#define etSTRING      5 /* Strings. %s */ | 
| +#define etDYNSTRING   6 /* Dynamically allocated strings. %z */ | 
| +#define etPERCENT     7 /* Percent symbol. %% */ | 
| +#define etCHARX       8 /* Characters. %c */ | 
| /* The rest are extensions, not normally found in printf() */ | 
| -#define etSQLESCAPE  10 /* Strings with '\'' doubled.  %q */ | 
| -#define etSQLESCAPE2 11 /* Strings with '\'' doubled and enclosed in '', | 
| +#define etSQLESCAPE   9 /* Strings with '\'' doubled.  %q */ | 
| +#define etSQLESCAPE2 10 /* Strings with '\'' doubled and enclosed in '', | 
| NULL pointers replaced by SQL NULL.  %Q */ | 
| -#define etTOKEN      12 /* a pointer to a Token structure */ | 
| -#define etSRCLIST    13 /* a pointer to a SrcList */ | 
| -#define etPOINTER    14 /* The %p conversion */ | 
| -#define etSQLESCAPE3 15 /* %w -> Strings with '\"' doubled */ | 
| -#define etORDINAL    16 /* %r -> 1st, 2nd, 3rd, 4th, etc.  English only */ | 
| +#define etTOKEN      11 /* a pointer to a Token structure */ | 
| +#define etSRCLIST    12 /* a pointer to a SrcList */ | 
| +#define etPOINTER    13 /* The %p conversion */ | 
| +#define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */ | 
| +#define etORDINAL    15 /* %r -> 1st, 2nd, 3rd, 4th, etc.  English only */ | 
|  | 
| -#define etINVALID     0 /* Any unrecognized conversion type */ | 
| +#define etINVALID    16 /* Any unrecognized conversion type */ | 
|  | 
|  | 
| /* | 
| @@ -59,7 +59,6 @@ typedef struct et_info {   /* Information about each format field */ | 
| ** Allowed values for et_info.flags | 
| */ | 
| #define FLAG_SIGNED  1     /* True if the value to convert is signed */ | 
| -#define FLAG_INTERN  2     /* True if for internal use only */ | 
| #define FLAG_STRING  4     /* Allow infinity precision */ | 
|  | 
|  | 
| @@ -93,11 +92,10 @@ static const et_info fmtinfo[] = { | 
| {  '%',  0, 0, etPERCENT,    0,  0 }, | 
| {  'p', 16, 0, etPOINTER,    0,  1 }, | 
|  | 
| -/* All the rest have the FLAG_INTERN bit set and are thus for internal | 
| -** use only */ | 
| -  {  'T',  0, 2, etTOKEN,      0,  0 }, | 
| -  {  'S',  0, 2, etSRCLIST,    0,  0 }, | 
| -  {  'r', 10, 3, etORDINAL,    0,  0 }, | 
| +  /* All the rest are undocumented and are for internal use only */ | 
| +  {  'T',  0, 0, etTOKEN,      0,  0 }, | 
| +  {  'S',  0, 0, etSRCLIST,    0,  0 }, | 
| +  {  'r', 10, 1, etORDINAL,    0,  0 }, | 
| }; | 
|  | 
| /* | 
| @@ -171,7 +169,6 @@ static char *getTextArg(PrintfArguments *p){ | 
| */ | 
| void sqlite3VXPrintf( | 
| StrAccum *pAccum,          /* Accumulate results here */ | 
| -  u32 bFlags,                /* SQLITE_PRINTF_* flags */ | 
| const char *fmt,           /* Format string */ | 
| va_list ap                 /* arguments */ | 
| ){ | 
| @@ -190,9 +187,8 @@ void sqlite3VXPrintf( | 
| etByte flag_long;          /* True if "l" flag is present */ | 
| etByte flag_longlong;      /* True if the "ll" flag is present */ | 
| etByte done;               /* Loop termination flag */ | 
| -  etByte xtype = 0;          /* Conversion paradigm */ | 
| +  etByte xtype = etINVALID;  /* Conversion paradigm */ | 
| u8 bArgList;               /* True for SQLITE_PRINTF_SQLFUNC */ | 
| -  u8 useIntern;              /* Ok to use internal conversions (ex: %T) */ | 
| char prefix;               /* Prefix character.  "+" or "-" or " " or '\0'. */ | 
| sqlite_uint64 longvalue;   /* Value for integer types */ | 
| LONGDOUBLE_TYPE realvalue; /* Value for real types */ | 
| @@ -211,13 +207,11 @@ void sqlite3VXPrintf( | 
| char buf[etBUFSIZE];       /* Conversion buffer */ | 
|  | 
| bufpt = 0; | 
| -  if( bFlags ){ | 
| -    if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){ | 
| -      pArgList = va_arg(ap, PrintfArguments*); | 
| -    } | 
| -    useIntern = bFlags & SQLITE_PRINTF_INTERNAL; | 
| +  if( (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC)!=0 ){ | 
| +    pArgList = va_arg(ap, PrintfArguments*); | 
| +    bArgList = 1; | 
| }else{ | 
| -    bArgList = useIntern = 0; | 
| +    bArgList = 0; | 
| } | 
| for(; (c=(*fmt))!=0; ++fmt){ | 
| if( c!='%' ){ | 
| @@ -329,11 +323,7 @@ void sqlite3VXPrintf( | 
| for(idx=0; idx<ArraySize(fmtinfo); idx++){ | 
| if( c==fmtinfo[idx].fmttype ){ | 
| infop = &fmtinfo[idx]; | 
| -        if( useIntern || (infop->flags & FLAG_INTERN)==0 ){ | 
| -          xtype = infop->type; | 
| -        }else{ | 
| -          return; | 
| -        } | 
| +        xtype = infop->type; | 
| break; | 
| } | 
| } | 
| @@ -702,7 +692,9 @@ void sqlite3VXPrintf( | 
| break; | 
| } | 
| case etTOKEN: { | 
| -        Token *pToken = va_arg(ap, Token*); | 
| +        Token *pToken; | 
| +        if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return; | 
| +        pToken = va_arg(ap, Token*); | 
| assert( bArgList==0 ); | 
| if( pToken && pToken->n ){ | 
| sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n); | 
| @@ -711,9 +703,13 @@ void sqlite3VXPrintf( | 
| break; | 
| } | 
| case etSRCLIST: { | 
| -        SrcList *pSrc = va_arg(ap, SrcList*); | 
| -        int k = va_arg(ap, int); | 
| -        struct SrcList_item *pItem = &pSrc->a[k]; | 
| +        SrcList *pSrc; | 
| +        int k; | 
| +        struct SrcList_item *pItem; | 
| +        if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return; | 
| +        pSrc = va_arg(ap, SrcList*); | 
| +        k = va_arg(ap, int); | 
| +        pItem = &pSrc->a[k]; | 
| assert( bArgList==0 ); | 
| assert( k>=0 && k<pSrc->nSrc ); | 
| if( pItem->zDatabase ){ | 
| @@ -735,9 +731,13 @@ void sqlite3VXPrintf( | 
| ** the output. | 
| */ | 
| width -= length; | 
| -    if( width>0 && !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' '); | 
| -    sqlite3StrAccumAppend(pAccum, bufpt, length); | 
| -    if( width>0 && flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' '); | 
| +    if( width>0 ){ | 
| +      if( !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' '); | 
| +      sqlite3StrAccumAppend(pAccum, bufpt, length); | 
| +      if( flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' '); | 
| +    }else{ | 
| +      sqlite3StrAccumAppend(pAccum, bufpt, length); | 
| +    } | 
|  | 
| if( zExtra ){ | 
| sqlite3DbFree(pAccum->db, zExtra); | 
| @@ -766,9 +766,9 @@ static int sqlite3StrAccumEnlarge(StrAccum *p, int N){ | 
| setStrAccumError(p, STRACCUM_TOOBIG); | 
| return N; | 
| }else{ | 
| -    char *zOld = p->bMalloced ? p->zText : 0; | 
| +    char *zOld = isMalloced(p) ? p->zText : 0; | 
| i64 szNew = p->nChar; | 
| -    assert( (p->zText==0 || p->zText==p->zBase)==(p->bMalloced==0) ); | 
| +    assert( (p->zText==0 || p->zText==p->zBase)==!isMalloced(p) ); | 
| szNew += N + 1; | 
| if( szNew+p->nChar<=p->mxAlloc ){ | 
| /* Force exponential buffer size growth as long as it does not overflow, | 
| @@ -789,10 +789,10 @@ static int sqlite3StrAccumEnlarge(StrAccum *p, int N){ | 
| } | 
| if( zNew ){ | 
| assert( p->zText!=0 || p->nChar==0 ); | 
| -      if( !p->bMalloced && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); | 
| +      if( !isMalloced(p) && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); | 
| p->zText = zNew; | 
| p->nAlloc = sqlite3DbMallocSize(p->db, zNew); | 
| -      p->bMalloced = 1; | 
| +      p->printfFlags |= SQLITE_PRINTF_MALLOCED; | 
| }else{ | 
| sqlite3StrAccumReset(p); | 
| setStrAccumError(p, STRACCUM_NOMEM); | 
| @@ -810,7 +810,7 @@ void sqlite3AppendChar(StrAccum *p, int N, char c){ | 
| if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){ | 
| return; | 
| } | 
| -  assert( (p->zText==p->zBase)==(p->bMalloced==0) ); | 
| +  assert( (p->zText==p->zBase)==!isMalloced(p) ); | 
| while( (N--)>0 ) p->zText[p->nChar++] = c; | 
| } | 
|  | 
| @@ -828,7 +828,7 @@ static void SQLITE_NOINLINE enlargeAndAppend(StrAccum *p, const char *z, int N){ | 
| memcpy(&p->zText[p->nChar], z, N); | 
| p->nChar += N; | 
| } | 
| -  assert( (p->zText==0 || p->zText==p->zBase)==(p->bMalloced==0) ); | 
| +  assert( (p->zText==0 || p->zText==p->zBase)==!isMalloced(p) ); | 
| } | 
|  | 
| /* | 
| @@ -842,7 +842,7 @@ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ | 
| assert( p->accError==0 || p->nAlloc==0 ); | 
| if( p->nChar+N >= p->nAlloc ){ | 
| enlargeAndAppend(p,z,N); | 
| -  }else{ | 
| +  }else if( N ){ | 
| assert( p->zText ); | 
| p->nChar += N; | 
| memcpy(&p->zText[p->nChar-N], z, N); | 
| @@ -862,18 +862,23 @@ void sqlite3StrAccumAppendAll(StrAccum *p, const char *z){ | 
| ** Return a pointer to the resulting string.  Return a NULL | 
| ** pointer if any kind of error was encountered. | 
| */ | 
| +static SQLITE_NOINLINE char *strAccumFinishRealloc(StrAccum *p){ | 
| +  assert( p->mxAlloc>0 && !isMalloced(p) ); | 
| +  p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 ); | 
| +  if( p->zText ){ | 
| +    memcpy(p->zText, p->zBase, p->nChar+1); | 
| +    p->printfFlags |= SQLITE_PRINTF_MALLOCED; | 
| +  }else{ | 
| +    setStrAccumError(p, STRACCUM_NOMEM); | 
| +  } | 
| +  return p->zText; | 
| +} | 
| char *sqlite3StrAccumFinish(StrAccum *p){ | 
| if( p->zText ){ | 
| -    assert( (p->zText==p->zBase)==(p->bMalloced==0) ); | 
| +    assert( (p->zText==p->zBase)==!isMalloced(p) ); | 
| p->zText[p->nChar] = 0; | 
| -    if( p->mxAlloc>0 && p->bMalloced==0 ){ | 
| -      p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 ); | 
| -      if( p->zText ){ | 
| -        memcpy(p->zText, p->zBase, p->nChar+1); | 
| -        p->bMalloced = 1; | 
| -      }else{ | 
| -        setStrAccumError(p, STRACCUM_NOMEM); | 
| -      } | 
| +    if( p->mxAlloc>0 && !isMalloced(p) ){ | 
| +      return strAccumFinishRealloc(p); | 
| } | 
| } | 
| return p->zText; | 
| @@ -883,10 +888,10 @@ char *sqlite3StrAccumFinish(StrAccum *p){ | 
| ** Reset an StrAccum string.  Reclaim all malloced memory. | 
| */ | 
| void sqlite3StrAccumReset(StrAccum *p){ | 
| -  assert( (p->zText==0 || p->zText==p->zBase)==(p->bMalloced==0) ); | 
| -  if( p->bMalloced ){ | 
| +  assert( (p->zText==0 || p->zText==p->zBase)==!isMalloced(p) ); | 
| +  if( isMalloced(p) ){ | 
| sqlite3DbFree(p->db, p->zText); | 
| -    p->bMalloced = 0; | 
| +    p->printfFlags &= ~SQLITE_PRINTF_MALLOCED; | 
| } | 
| p->zText = 0; | 
| } | 
| @@ -912,7 +917,7 @@ void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){ | 
| p->nAlloc = n; | 
| p->mxAlloc = mx; | 
| p->accError = 0; | 
| -  p->bMalloced = 0; | 
| +  p->printfFlags = 0; | 
| } | 
|  | 
| /* | 
| @@ -926,10 +931,11 @@ char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){ | 
| assert( db!=0 ); | 
| sqlite3StrAccumInit(&acc, db, zBase, sizeof(zBase), | 
| db->aLimit[SQLITE_LIMIT_LENGTH]); | 
| -  sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap); | 
| +  acc.printfFlags = SQLITE_PRINTF_INTERNAL; | 
| +  sqlite3VXPrintf(&acc, zFormat, ap); | 
| z = sqlite3StrAccumFinish(&acc); | 
| if( acc.accError==STRACCUM_NOMEM ){ | 
| -    db->mallocFailed = 1; | 
| +    sqlite3OomFault(db); | 
| } | 
| return z; | 
| } | 
| @@ -966,7 +972,7 @@ char *sqlite3_vmprintf(const char *zFormat, va_list ap){ | 
| if( sqlite3_initialize() ) return 0; | 
| #endif | 
| sqlite3StrAccumInit(&acc, 0, zBase, sizeof(zBase), SQLITE_MAX_LENGTH); | 
| -  sqlite3VXPrintf(&acc, 0, zFormat, ap); | 
| +  sqlite3VXPrintf(&acc, zFormat, ap); | 
| z = sqlite3StrAccumFinish(&acc); | 
| return z; | 
| } | 
| @@ -1011,8 +1017,9 @@ char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){ | 
| } | 
| #endif | 
| sqlite3StrAccumInit(&acc, 0, zBuf, n, 0); | 
| -  sqlite3VXPrintf(&acc, 0, zFormat, ap); | 
| -  return sqlite3StrAccumFinish(&acc); | 
| +  sqlite3VXPrintf(&acc, zFormat, ap); | 
| +  zBuf[acc.nChar] = 0; | 
| +  return zBuf; | 
| } | 
| char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){ | 
| char *z; | 
| @@ -1042,7 +1049,7 @@ static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){ | 
| char zMsg[SQLITE_PRINT_BUF_SIZE*3];    /* Complete log message */ | 
|  | 
| sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0); | 
| -  sqlite3VXPrintf(&acc, 0, zFormat, ap); | 
| +  sqlite3VXPrintf(&acc, zFormat, ap); | 
| sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode, | 
| sqlite3StrAccumFinish(&acc)); | 
| } | 
| @@ -1071,7 +1078,7 @@ void sqlite3DebugPrintf(const char *zFormat, ...){ | 
| char zBuf[500]; | 
| sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); | 
| va_start(ap,zFormat); | 
| -  sqlite3VXPrintf(&acc, 0, zFormat, ap); | 
| +  sqlite3VXPrintf(&acc, zFormat, ap); | 
| va_end(ap); | 
| sqlite3StrAccumFinish(&acc); | 
| fprintf(stdout,"%s", zBuf); | 
| @@ -1084,9 +1091,9 @@ void sqlite3DebugPrintf(const char *zFormat, ...){ | 
| ** variable-argument wrapper around sqlite3VXPrintf().  The bFlags argument | 
| ** can contain the bit SQLITE_PRINTF_INTERNAL enable internal formats. | 
| */ | 
| -void sqlite3XPrintf(StrAccum *p, u32 bFlags, const char *zFormat, ...){ | 
| +void sqlite3XPrintf(StrAccum *p, const char *zFormat, ...){ | 
| va_list ap; | 
| va_start(ap,zFormat); | 
| -  sqlite3VXPrintf(p, bFlags, zFormat, ap); | 
| +  sqlite3VXPrintf(p, zFormat, ap); | 
| va_end(ap); | 
| } | 
|  |