drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | ** The "printf" code that follows dates from the 1980's. It is in |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 3 | ** the public domain. |
drh | e84a306 | 2004-02-02 12:29:25 +0000 | [diff] [blame] | 4 | ** |
| 5 | ************************************************************************** |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 6 | ** |
drh | ed1fddf | 2011-10-12 18:52:59 +0000 | [diff] [blame] | 7 | ** This file contains code for a set of "printf"-like routines. These |
| 8 | ** routines format strings much like the printf() from the standard C |
| 9 | ** library, though the implementation here has enhancements to support |
mistachkin | f5b5f9b | 2015-06-08 17:42:57 +0000 | [diff] [blame] | 10 | ** SQLite. |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 11 | */ |
| 12 | #include "sqliteInt.h" |
drh | 7c68d60 | 2000-10-11 19:28:51 +0000 | [diff] [blame] | 13 | |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 14 | /* |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 15 | ** Conversion types fall into various categories as defined by the |
| 16 | ** following enumeration. |
| 17 | */ |
drh | ad5a9d7 | 2016-05-05 11:53:12 +0000 | [diff] [blame] | 18 | #define etRADIX 0 /* Integer types. %d, %x, %o, and so forth */ |
| 19 | #define etFLOAT 1 /* Floating point. %f */ |
| 20 | #define etEXP 2 /* Exponentional notation. %e and %E */ |
| 21 | #define etGENERIC 3 /* Floating or exponential, depending on exponent. %g */ |
| 22 | #define etSIZE 4 /* Return number of characters processed so far. %n */ |
| 23 | #define etSTRING 5 /* Strings. %s */ |
| 24 | #define etDYNSTRING 6 /* Dynamically allocated strings. %z */ |
| 25 | #define etPERCENT 7 /* Percent symbol. %% */ |
| 26 | #define etCHARX 8 /* Characters. %c */ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 27 | /* The rest are extensions, not normally found in printf() */ |
drh | ad5a9d7 | 2016-05-05 11:53:12 +0000 | [diff] [blame] | 28 | #define etSQLESCAPE 9 /* Strings with '\'' doubled. %q */ |
| 29 | #define etSQLESCAPE2 10 /* Strings with '\'' doubled and enclosed in '', |
chw | 0cfcf3f | 2002-06-16 04:55:48 +0000 | [diff] [blame] | 30 | NULL pointers replaced by SQL NULL. %Q */ |
drh | ad5a9d7 | 2016-05-05 11:53:12 +0000 | [diff] [blame] | 31 | #define etTOKEN 11 /* a pointer to a Token structure */ |
| 32 | #define etSRCLIST 12 /* a pointer to a SrcList */ |
| 33 | #define etPOINTER 13 /* The %p conversion */ |
| 34 | #define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */ |
| 35 | #define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */ |
drh | e84a306 | 2004-02-02 12:29:25 +0000 | [diff] [blame] | 36 | |
drh | ad5a9d7 | 2016-05-05 11:53:12 +0000 | [diff] [blame] | 37 | #define etINVALID 16 /* Any unrecognized conversion type */ |
drh | 874ba04 | 2009-04-08 16:10:04 +0000 | [diff] [blame] | 38 | |
drh | e84a306 | 2004-02-02 12:29:25 +0000 | [diff] [blame] | 39 | |
| 40 | /* |
| 41 | ** An "etByte" is an 8-bit unsigned value. |
| 42 | */ |
| 43 | typedef unsigned char etByte; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 44 | |
| 45 | /* |
| 46 | ** Each builtin conversion character (ex: the 'd' in "%d") is described |
| 47 | ** by an instance of the following structure |
| 48 | */ |
| 49 | typedef struct et_info { /* Information about each format field */ |
drh | e84a306 | 2004-02-02 12:29:25 +0000 | [diff] [blame] | 50 | char fmttype; /* The format field code letter */ |
| 51 | etByte base; /* The base for radix conversion */ |
| 52 | etByte flags; /* One or more of FLAG_ constants below */ |
| 53 | etByte type; /* Conversion paradigm */ |
drh | 76ff3a0 | 2004-09-24 22:32:30 +0000 | [diff] [blame] | 54 | etByte charset; /* Offset into aDigits[] of the digits string */ |
| 55 | etByte prefix; /* Offset into aPrefix[] of the prefix string */ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 56 | } et_info; |
| 57 | |
| 58 | /* |
drh | e84a306 | 2004-02-02 12:29:25 +0000 | [diff] [blame] | 59 | ** Allowed values for et_info.flags |
| 60 | */ |
| 61 | #define FLAG_SIGNED 1 /* True if the value to convert is signed */ |
drh | 4794f73 | 2004-11-05 17:17:50 +0000 | [diff] [blame] | 62 | #define FLAG_STRING 4 /* Allow infinity precision */ |
drh | e84a306 | 2004-02-02 12:29:25 +0000 | [diff] [blame] | 63 | |
| 64 | |
| 65 | /* |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 66 | ** The following table is searched linearly, so it is good to put the |
| 67 | ** most frequently used conversion types first. |
| 68 | */ |
drh | 76ff3a0 | 2004-09-24 22:32:30 +0000 | [diff] [blame] | 69 | static const char aDigits[] = "0123456789ABCDEF0123456789abcdef"; |
| 70 | static const char aPrefix[] = "-x0\000X0"; |
drh | 5719628 | 2004-10-06 15:41:16 +0000 | [diff] [blame] | 71 | static const et_info fmtinfo[] = { |
drh | 76ff3a0 | 2004-09-24 22:32:30 +0000 | [diff] [blame] | 72 | { 'd', 10, 1, etRADIX, 0, 0 }, |
drh | 4794f73 | 2004-11-05 17:17:50 +0000 | [diff] [blame] | 73 | { 's', 0, 4, etSTRING, 0, 0 }, |
drh | 557cc60 | 2005-08-13 12:59:14 +0000 | [diff] [blame] | 74 | { 'g', 0, 1, etGENERIC, 30, 0 }, |
drh | 153c62c | 2007-08-24 03:51:33 +0000 | [diff] [blame] | 75 | { 'z', 0, 4, etDYNSTRING, 0, 0 }, |
drh | 4794f73 | 2004-11-05 17:17:50 +0000 | [diff] [blame] | 76 | { 'q', 0, 4, etSQLESCAPE, 0, 0 }, |
| 77 | { 'Q', 0, 4, etSQLESCAPE2, 0, 0 }, |
danielk1977 | f3b863e | 2007-06-24 06:32:17 +0000 | [diff] [blame] | 78 | { 'w', 0, 4, etSQLESCAPE3, 0, 0 }, |
drh | 76ff3a0 | 2004-09-24 22:32:30 +0000 | [diff] [blame] | 79 | { 'c', 0, 0, etCHARX, 0, 0 }, |
| 80 | { 'o', 8, 0, etRADIX, 0, 2 }, |
| 81 | { 'u', 10, 0, etRADIX, 0, 0 }, |
| 82 | { 'x', 16, 0, etRADIX, 16, 1 }, |
| 83 | { 'X', 16, 0, etRADIX, 0, 4 }, |
drh | b37df7b | 2005-10-13 02:09:49 +0000 | [diff] [blame] | 84 | #ifndef SQLITE_OMIT_FLOATING_POINT |
drh | 76ff3a0 | 2004-09-24 22:32:30 +0000 | [diff] [blame] | 85 | { 'f', 0, 1, etFLOAT, 0, 0 }, |
| 86 | { 'e', 0, 1, etEXP, 30, 0 }, |
| 87 | { 'E', 0, 1, etEXP, 14, 0 }, |
drh | 76ff3a0 | 2004-09-24 22:32:30 +0000 | [diff] [blame] | 88 | { 'G', 0, 1, etGENERIC, 14, 0 }, |
drh | b37df7b | 2005-10-13 02:09:49 +0000 | [diff] [blame] | 89 | #endif |
drh | 76ff3a0 | 2004-09-24 22:32:30 +0000 | [diff] [blame] | 90 | { 'i', 10, 1, etRADIX, 0, 0 }, |
| 91 | { 'n', 0, 0, etSIZE, 0, 0 }, |
| 92 | { '%', 0, 0, etPERCENT, 0, 0 }, |
| 93 | { 'p', 16, 0, etPOINTER, 0, 1 }, |
drh | 7e3ff5d | 2009-04-08 11:49:42 +0000 | [diff] [blame] | 94 | |
drh | 8236f68 | 2017-01-04 00:26:28 +0000 | [diff] [blame] | 95 | /* All the rest are undocumented and are for internal use only */ |
| 96 | { 'T', 0, 0, etTOKEN, 0, 0 }, |
| 97 | { 'S', 0, 0, etSRCLIST, 0, 0 }, |
| 98 | { 'r', 10, 1, etORDINAL, 0, 0 }, |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 99 | }; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 100 | |
| 101 | /* |
drh | b37df7b | 2005-10-13 02:09:49 +0000 | [diff] [blame] | 102 | ** If SQLITE_OMIT_FLOATING_POINT is defined, then none of the floating point |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 103 | ** conversions will work. |
| 104 | */ |
drh | b37df7b | 2005-10-13 02:09:49 +0000 | [diff] [blame] | 105 | #ifndef SQLITE_OMIT_FLOATING_POINT |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 106 | /* |
| 107 | ** "*val" is a double such that 0.1 <= *val < 10.0 |
| 108 | ** Return the ascii code for the leading digit of *val, then |
| 109 | ** multiply "*val" by 10.0 to renormalize. |
| 110 | ** |
| 111 | ** Example: |
| 112 | ** input: *val = 3.14159 |
| 113 | ** output: *val = 1.4159 function return = '3' |
| 114 | ** |
| 115 | ** The counter *cnt is incremented each time. After counter exceeds |
| 116 | ** 16 (the number of significant digits in a 64-bit float) '0' is |
| 117 | ** always returned. |
| 118 | */ |
drh | ea67883 | 2008-12-10 19:26:22 +0000 | [diff] [blame] | 119 | static char et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 120 | int digit; |
drh | 384eef3 | 2004-01-07 03:04:27 +0000 | [diff] [blame] | 121 | LONGDOUBLE_TYPE d; |
drh | 72b3fbc | 2012-06-19 03:11:25 +0000 | [diff] [blame] | 122 | if( (*cnt)<=0 ) return '0'; |
| 123 | (*cnt)--; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 124 | digit = (int)*val; |
| 125 | d = digit; |
| 126 | digit += '0'; |
| 127 | *val = (*val - d)*10.0; |
drh | ea67883 | 2008-12-10 19:26:22 +0000 | [diff] [blame] | 128 | return (char)digit; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 129 | } |
drh | b37df7b | 2005-10-13 02:09:49 +0000 | [diff] [blame] | 130 | #endif /* SQLITE_OMIT_FLOATING_POINT */ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 131 | |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 132 | /* |
drh | a6353a3 | 2013-12-09 19:03:26 +0000 | [diff] [blame] | 133 | ** Set the StrAccum object to an error mode. |
| 134 | */ |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 135 | static void setStrAccumError(StrAccum *p, u8 eError){ |
drh | c049057 | 2015-05-02 11:45:53 +0000 | [diff] [blame] | 136 | assert( eError==STRACCUM_NOMEM || eError==STRACCUM_TOOBIG ); |
drh | a6353a3 | 2013-12-09 19:03:26 +0000 | [diff] [blame] | 137 | p->accError = eError; |
| 138 | p->nAlloc = 0; |
| 139 | } |
| 140 | |
| 141 | /* |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 142 | ** Extra argument values from a PrintfArguments object |
| 143 | */ |
| 144 | static sqlite3_int64 getIntArg(PrintfArguments *p){ |
| 145 | if( p->nArg<=p->nUsed ) return 0; |
| 146 | return sqlite3_value_int64(p->apArg[p->nUsed++]); |
| 147 | } |
| 148 | static double getDoubleArg(PrintfArguments *p){ |
| 149 | if( p->nArg<=p->nUsed ) return 0.0; |
| 150 | return sqlite3_value_double(p->apArg[p->nUsed++]); |
| 151 | } |
| 152 | static char *getTextArg(PrintfArguments *p){ |
| 153 | if( p->nArg<=p->nUsed ) return 0; |
| 154 | return (char*)sqlite3_value_text(p->apArg[p->nUsed++]); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | /* |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 159 | ** On machines with a small stack size, you can redefine the |
drh | ed1fddf | 2011-10-12 18:52:59 +0000 | [diff] [blame] | 160 | ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired. |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 161 | */ |
| 162 | #ifndef SQLITE_PRINT_BUF_SIZE |
drh | 59eedf7 | 2011-10-11 17:54:54 +0000 | [diff] [blame] | 163 | # define SQLITE_PRINT_BUF_SIZE 70 |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 164 | #endif |
| 165 | #define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 166 | |
| 167 | /* |
drh | ed1fddf | 2011-10-12 18:52:59 +0000 | [diff] [blame] | 168 | ** Render a string given by "fmt" into the StrAccum object. |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 169 | */ |
drh | f089aa4 | 2008-07-08 19:34:06 +0000 | [diff] [blame] | 170 | void sqlite3VXPrintf( |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 171 | StrAccum *pAccum, /* Accumulate results here */ |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 172 | const char *fmt, /* Format string */ |
| 173 | va_list ap /* arguments */ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 174 | ){ |
drh | e84a306 | 2004-02-02 12:29:25 +0000 | [diff] [blame] | 175 | int c; /* Next character in the format string */ |
| 176 | char *bufpt; /* Pointer to the conversion buffer */ |
| 177 | int precision; /* Precision of the current field */ |
| 178 | int length; /* Length of the field */ |
| 179 | int idx; /* A general purpose loop counter */ |
drh | e84a306 | 2004-02-02 12:29:25 +0000 | [diff] [blame] | 180 | int width; /* Width of the current field */ |
| 181 | etByte flag_leftjustify; /* True if "-" flag is present */ |
| 182 | etByte flag_plussign; /* True if "+" flag is present */ |
| 183 | etByte flag_blanksign; /* True if " " flag is present */ |
| 184 | etByte flag_alternateform; /* True if "#" flag is present */ |
drh | 531fe87 | 2005-08-13 13:40:42 +0000 | [diff] [blame] | 185 | etByte flag_altform2; /* True if "!" flag is present */ |
drh | e84a306 | 2004-02-02 12:29:25 +0000 | [diff] [blame] | 186 | etByte flag_zeropad; /* True if field width constant starts with zero */ |
| 187 | etByte flag_long; /* True if "l" flag is present */ |
drh | a34b676 | 2004-05-07 13:30:42 +0000 | [diff] [blame] | 188 | etByte flag_longlong; /* True if the "ll" flag is present */ |
drh | 3e9aeec | 2005-08-13 13:39:02 +0000 | [diff] [blame] | 189 | etByte done; /* Loop termination flag */ |
drh | ad5a9d7 | 2016-05-05 11:53:12 +0000 | [diff] [blame] | 190 | etByte xtype = etINVALID; /* Conversion paradigm */ |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 191 | u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */ |
drh | ed1fddf | 2011-10-12 18:52:59 +0000 | [diff] [blame] | 192 | char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ |
drh | 27436af | 2006-03-28 23:57:17 +0000 | [diff] [blame] | 193 | sqlite_uint64 longvalue; /* Value for integer types */ |
drh | 384eef3 | 2004-01-07 03:04:27 +0000 | [diff] [blame] | 194 | LONGDOUBLE_TYPE realvalue; /* Value for real types */ |
drh | 5719628 | 2004-10-06 15:41:16 +0000 | [diff] [blame] | 195 | const et_info *infop; /* Pointer to the appropriate info structure */ |
drh | 59eedf7 | 2011-10-11 17:54:54 +0000 | [diff] [blame] | 196 | char *zOut; /* Rendering buffer */ |
| 197 | int nOut; /* Size of the rendering buffer */ |
drh | af8f513 | 2014-10-29 18:20:18 +0000 | [diff] [blame] | 198 | char *zExtra = 0; /* Malloced memory used by some conversion */ |
drh | b37df7b | 2005-10-13 02:09:49 +0000 | [diff] [blame] | 199 | #ifndef SQLITE_OMIT_FLOATING_POINT |
drh | 557cc60 | 2005-08-13 12:59:14 +0000 | [diff] [blame] | 200 | int exp, e2; /* exponent of real numbers */ |
drh | ed1fddf | 2011-10-12 18:52:59 +0000 | [diff] [blame] | 201 | int nsd; /* Number of significant digits returned */ |
drh | e84a306 | 2004-02-02 12:29:25 +0000 | [diff] [blame] | 202 | double rounder; /* Used for rounding floating point values */ |
| 203 | etByte flag_dp; /* True if decimal point should be shown */ |
| 204 | etByte flag_rtz; /* True if trailing zeros should be removed */ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 205 | #endif |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 206 | PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */ |
drh | ed1fddf | 2011-10-12 18:52:59 +0000 | [diff] [blame] | 207 | char buf[etBUFSIZE]; /* Conversion buffer */ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 208 | |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 209 | bufpt = 0; |
drh | 8236f68 | 2017-01-04 00:26:28 +0000 | [diff] [blame] | 210 | if( (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC)!=0 ){ |
| 211 | pArgList = va_arg(ap, PrintfArguments*); |
| 212 | bArgList = 1; |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 213 | }else{ |
drh | 8236f68 | 2017-01-04 00:26:28 +0000 | [diff] [blame] | 214 | bArgList = 0; |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 215 | } |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 216 | for(; (c=(*fmt))!=0; ++fmt){ |
| 217 | if( c!='%' ){ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 218 | bufpt = (char *)fmt; |
drh | 760b159 | 2014-09-18 01:50:09 +0000 | [diff] [blame] | 219 | #if HAVE_STRCHRNUL |
| 220 | fmt = strchrnul(fmt, '%'); |
| 221 | #else |
| 222 | do{ fmt++; }while( *fmt && *fmt != '%' ); |
| 223 | #endif |
drh | a70a073 | 2014-03-17 14:24:27 +0000 | [diff] [blame] | 224 | sqlite3StrAccumAppend(pAccum, bufpt, (int)(fmt - bufpt)); |
drh | 760b159 | 2014-09-18 01:50:09 +0000 | [diff] [blame] | 225 | if( *fmt==0 ) break; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 226 | } |
| 227 | if( (c=(*++fmt))==0 ){ |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 228 | sqlite3StrAccumAppend(pAccum, "%", 1); |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 229 | break; |
| 230 | } |
| 231 | /* Find out what flags are present */ |
| 232 | flag_leftjustify = flag_plussign = flag_blanksign = |
drh | 557cc60 | 2005-08-13 12:59:14 +0000 | [diff] [blame] | 233 | flag_alternateform = flag_altform2 = flag_zeropad = 0; |
drh | 3e9aeec | 2005-08-13 13:39:02 +0000 | [diff] [blame] | 234 | done = 0; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 235 | do{ |
| 236 | switch( c ){ |
drh | 3e9aeec | 2005-08-13 13:39:02 +0000 | [diff] [blame] | 237 | case '-': flag_leftjustify = 1; break; |
| 238 | case '+': flag_plussign = 1; break; |
| 239 | case ' ': flag_blanksign = 1; break; |
| 240 | case '#': flag_alternateform = 1; break; |
| 241 | case '!': flag_altform2 = 1; break; |
| 242 | case '0': flag_zeropad = 1; break; |
| 243 | default: done = 1; break; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 244 | } |
drh | 3e9aeec | 2005-08-13 13:39:02 +0000 | [diff] [blame] | 245 | }while( !done && (c=(*++fmt))!=0 ); |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 246 | /* Get the field width */ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 247 | if( c=='*' ){ |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 248 | if( bArgList ){ |
| 249 | width = (int)getIntArg(pArgList); |
| 250 | }else{ |
| 251 | width = va_arg(ap,int); |
| 252 | } |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 253 | if( width<0 ){ |
| 254 | flag_leftjustify = 1; |
drh | b6f47de | 2015-04-07 15:39:29 +0000 | [diff] [blame] | 255 | width = width >= -2147483647 ? -width : 0; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 256 | } |
| 257 | c = *++fmt; |
| 258 | }else{ |
drh | b6f47de | 2015-04-07 15:39:29 +0000 | [diff] [blame] | 259 | unsigned wx = 0; |
drh | 17a6893 | 2001-01-31 13:28:08 +0000 | [diff] [blame] | 260 | while( c>='0' && c<='9' ){ |
drh | b6f47de | 2015-04-07 15:39:29 +0000 | [diff] [blame] | 261 | wx = wx*10 + c - '0'; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 262 | c = *++fmt; |
| 263 | } |
drh | b6f47de | 2015-04-07 15:39:29 +0000 | [diff] [blame] | 264 | testcase( wx>0x7fffffff ); |
| 265 | width = wx & 0x7fffffff; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 266 | } |
drh | c386ef4 | 2015-11-30 22:52:14 +0000 | [diff] [blame] | 267 | assert( width>=0 ); |
| 268 | #ifdef SQLITE_PRINTF_PRECISION_LIMIT |
| 269 | if( width>SQLITE_PRINTF_PRECISION_LIMIT ){ |
| 270 | width = SQLITE_PRINTF_PRECISION_LIMIT; |
| 271 | } |
| 272 | #endif |
dan | 8c06914 | 2015-04-07 14:38:57 +0000 | [diff] [blame] | 273 | |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 274 | /* Get the precision */ |
| 275 | if( c=='.' ){ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 276 | c = *++fmt; |
| 277 | if( c=='*' ){ |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 278 | if( bArgList ){ |
| 279 | precision = (int)getIntArg(pArgList); |
| 280 | }else{ |
| 281 | precision = va_arg(ap,int); |
| 282 | } |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 283 | c = *++fmt; |
drh | b6f47de | 2015-04-07 15:39:29 +0000 | [diff] [blame] | 284 | if( precision<0 ){ |
| 285 | precision = precision >= -2147483647 ? -precision : -1; |
| 286 | } |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 287 | }else{ |
drh | b6f47de | 2015-04-07 15:39:29 +0000 | [diff] [blame] | 288 | unsigned px = 0; |
drh | 17a6893 | 2001-01-31 13:28:08 +0000 | [diff] [blame] | 289 | while( c>='0' && c<='9' ){ |
drh | b6f47de | 2015-04-07 15:39:29 +0000 | [diff] [blame] | 290 | px = px*10 + c - '0'; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 291 | c = *++fmt; |
| 292 | } |
drh | b6f47de | 2015-04-07 15:39:29 +0000 | [diff] [blame] | 293 | testcase( px>0x7fffffff ); |
| 294 | precision = px & 0x7fffffff; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 295 | } |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 296 | }else{ |
| 297 | precision = -1; |
| 298 | } |
drh | c386ef4 | 2015-11-30 22:52:14 +0000 | [diff] [blame] | 299 | assert( precision>=(-1) ); |
| 300 | #ifdef SQLITE_PRINTF_PRECISION_LIMIT |
| 301 | if( precision>SQLITE_PRINTF_PRECISION_LIMIT ){ |
| 302 | precision = SQLITE_PRINTF_PRECISION_LIMIT; |
| 303 | } |
| 304 | #endif |
| 305 | |
| 306 | |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 307 | /* Get the conversion type modifier */ |
| 308 | if( c=='l' ){ |
| 309 | flag_long = 1; |
| 310 | c = *++fmt; |
drh | a34b676 | 2004-05-07 13:30:42 +0000 | [diff] [blame] | 311 | if( c=='l' ){ |
| 312 | flag_longlong = 1; |
| 313 | c = *++fmt; |
| 314 | }else{ |
| 315 | flag_longlong = 0; |
| 316 | } |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 317 | }else{ |
drh | a34b676 | 2004-05-07 13:30:42 +0000 | [diff] [blame] | 318 | flag_long = flag_longlong = 0; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 319 | } |
| 320 | /* Fetch the info entry for the field */ |
drh | 874ba04 | 2009-04-08 16:10:04 +0000 | [diff] [blame] | 321 | infop = &fmtinfo[0]; |
| 322 | xtype = etINVALID; |
danielk1977 | 00e1361 | 2008-11-17 19:18:54 +0000 | [diff] [blame] | 323 | for(idx=0; idx<ArraySize(fmtinfo); idx++){ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 324 | if( c==fmtinfo[idx].fmttype ){ |
| 325 | infop = &fmtinfo[idx]; |
drh | 8236f68 | 2017-01-04 00:26:28 +0000 | [diff] [blame] | 326 | xtype = infop->type; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 327 | break; |
| 328 | } |
| 329 | } |
drh | 43617e9 | 2006-03-06 20:55:46 +0000 | [diff] [blame] | 330 | |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 331 | /* |
| 332 | ** At this point, variables are initialized as follows: |
| 333 | ** |
| 334 | ** flag_alternateform TRUE if a '#' is present. |
drh | 3e9aeec | 2005-08-13 13:39:02 +0000 | [diff] [blame] | 335 | ** flag_altform2 TRUE if a '!' is present. |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 336 | ** flag_plussign TRUE if a '+' is present. |
| 337 | ** flag_leftjustify TRUE if a '-' is present or if the |
| 338 | ** field width was negative. |
| 339 | ** flag_zeropad TRUE if the width began with 0. |
| 340 | ** flag_long TRUE if the letter 'l' (ell) prefixed |
| 341 | ** the conversion character. |
drh | a34b676 | 2004-05-07 13:30:42 +0000 | [diff] [blame] | 342 | ** flag_longlong TRUE if the letter 'll' (ell ell) prefixed |
| 343 | ** the conversion character. |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 344 | ** flag_blanksign TRUE if a ' ' is present. |
| 345 | ** width The specified field width. This is |
| 346 | ** always non-negative. Zero is the default. |
| 347 | ** precision The specified precision. The default |
| 348 | ** is -1. |
| 349 | ** xtype The class of the conversion. |
| 350 | ** infop Pointer to the appropriate info struct. |
| 351 | */ |
| 352 | switch( xtype ){ |
drh | fe63d1c | 2004-09-08 20:13:04 +0000 | [diff] [blame] | 353 | case etPOINTER: |
| 354 | flag_longlong = sizeof(char*)==sizeof(i64); |
| 355 | flag_long = sizeof(char*)==sizeof(long int); |
| 356 | /* Fall through into the next case */ |
drh | 9a99334 | 2007-12-13 02:45:31 +0000 | [diff] [blame] | 357 | case etORDINAL: |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 358 | case etRADIX: |
drh | e84a306 | 2004-02-02 12:29:25 +0000 | [diff] [blame] | 359 | if( infop->flags & FLAG_SIGNED ){ |
drh | e970767 | 2004-06-25 01:10:48 +0000 | [diff] [blame] | 360 | i64 v; |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 361 | if( bArgList ){ |
| 362 | v = getIntArg(pArgList); |
| 363 | }else if( flag_longlong ){ |
drh | eeb23a4 | 2009-05-04 20:20:16 +0000 | [diff] [blame] | 364 | v = va_arg(ap,i64); |
| 365 | }else if( flag_long ){ |
| 366 | v = va_arg(ap,long int); |
| 367 | }else{ |
| 368 | v = va_arg(ap,int); |
| 369 | } |
drh | e970767 | 2004-06-25 01:10:48 +0000 | [diff] [blame] | 370 | if( v<0 ){ |
drh | 158b9cb | 2011-03-05 20:59:46 +0000 | [diff] [blame] | 371 | if( v==SMALLEST_INT64 ){ |
| 372 | longvalue = ((u64)1)<<63; |
| 373 | }else{ |
| 374 | longvalue = -v; |
| 375 | } |
drh | e970767 | 2004-06-25 01:10:48 +0000 | [diff] [blame] | 376 | prefix = '-'; |
danielk1977 | cfcdaef | 2004-05-12 07:33:33 +0000 | [diff] [blame] | 377 | }else{ |
drh | e970767 | 2004-06-25 01:10:48 +0000 | [diff] [blame] | 378 | longvalue = v; |
| 379 | if( flag_plussign ) prefix = '+'; |
danielk1977 | cfcdaef | 2004-05-12 07:33:33 +0000 | [diff] [blame] | 380 | else if( flag_blanksign ) prefix = ' '; |
| 381 | else prefix = 0; |
| 382 | } |
drh | e970767 | 2004-06-25 01:10:48 +0000 | [diff] [blame] | 383 | }else{ |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 384 | if( bArgList ){ |
| 385 | longvalue = (u64)getIntArg(pArgList); |
| 386 | }else if( flag_longlong ){ |
drh | eeb23a4 | 2009-05-04 20:20:16 +0000 | [diff] [blame] | 387 | longvalue = va_arg(ap,u64); |
| 388 | }else if( flag_long ){ |
| 389 | longvalue = va_arg(ap,unsigned long int); |
| 390 | }else{ |
| 391 | longvalue = va_arg(ap,unsigned int); |
| 392 | } |
drh | e970767 | 2004-06-25 01:10:48 +0000 | [diff] [blame] | 393 | prefix = 0; |
| 394 | } |
| 395 | if( longvalue==0 ) flag_alternateform = 0; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 396 | if( flag_zeropad && precision<width-(prefix!=0) ){ |
| 397 | precision = width-(prefix!=0); |
drh | 9adf9ac | 2002-05-15 11:44:13 +0000 | [diff] [blame] | 398 | } |
drh | 59eedf7 | 2011-10-11 17:54:54 +0000 | [diff] [blame] | 399 | if( precision<etBUFSIZE-10 ){ |
| 400 | nOut = etBUFSIZE; |
| 401 | zOut = buf; |
| 402 | }else{ |
| 403 | nOut = precision + 10; |
| 404 | zOut = zExtra = sqlite3Malloc( nOut ); |
| 405 | if( zOut==0 ){ |
drh | a6353a3 | 2013-12-09 19:03:26 +0000 | [diff] [blame] | 406 | setStrAccumError(pAccum, STRACCUM_NOMEM); |
drh | 59eedf7 | 2011-10-11 17:54:54 +0000 | [diff] [blame] | 407 | return; |
| 408 | } |
| 409 | } |
| 410 | bufpt = &zOut[nOut-1]; |
drh | 9a99334 | 2007-12-13 02:45:31 +0000 | [diff] [blame] | 411 | if( xtype==etORDINAL ){ |
drh | 43f6e06 | 2007-12-13 17:50:22 +0000 | [diff] [blame] | 412 | static const char zOrd[] = "thstndrd"; |
drh | ea67883 | 2008-12-10 19:26:22 +0000 | [diff] [blame] | 413 | int x = (int)(longvalue % 10); |
drh | 43f6e06 | 2007-12-13 17:50:22 +0000 | [diff] [blame] | 414 | if( x>=4 || (longvalue/10)%10==1 ){ |
| 415 | x = 0; |
| 416 | } |
drh | 59eedf7 | 2011-10-11 17:54:54 +0000 | [diff] [blame] | 417 | *(--bufpt) = zOrd[x*2+1]; |
| 418 | *(--bufpt) = zOrd[x*2]; |
drh | 9a99334 | 2007-12-13 02:45:31 +0000 | [diff] [blame] | 419 | } |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 420 | { |
drh | 0e68209 | 2014-03-17 15:06:57 +0000 | [diff] [blame] | 421 | const char *cset = &aDigits[infop->charset]; |
| 422 | u8 base = infop->base; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 423 | do{ /* Convert to ascii */ |
| 424 | *(--bufpt) = cset[longvalue%base]; |
| 425 | longvalue = longvalue/base; |
| 426 | }while( longvalue>0 ); |
drh | 9adf9ac | 2002-05-15 11:44:13 +0000 | [diff] [blame] | 427 | } |
drh | 59eedf7 | 2011-10-11 17:54:54 +0000 | [diff] [blame] | 428 | length = (int)(&zOut[nOut-1]-bufpt); |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 429 | for(idx=precision-length; idx>0; idx--){ |
| 430 | *(--bufpt) = '0'; /* Zero pad */ |
drh | 9adf9ac | 2002-05-15 11:44:13 +0000 | [diff] [blame] | 431 | } |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 432 | if( prefix ) *(--bufpt) = prefix; /* Add sign */ |
| 433 | if( flag_alternateform && infop->prefix ){ /* Add "0" or "0x" */ |
drh | 76ff3a0 | 2004-09-24 22:32:30 +0000 | [diff] [blame] | 434 | const char *pre; |
| 435 | char x; |
| 436 | pre = &aPrefix[infop->prefix]; |
drh | af005fb | 2008-07-09 16:51:51 +0000 | [diff] [blame] | 437 | for(; (x=(*pre))!=0; pre++) *(--bufpt) = x; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 438 | } |
drh | 59eedf7 | 2011-10-11 17:54:54 +0000 | [diff] [blame] | 439 | length = (int)(&zOut[nOut-1]-bufpt); |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 440 | break; |
| 441 | case etFLOAT: |
| 442 | case etEXP: |
| 443 | case etGENERIC: |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 444 | if( bArgList ){ |
| 445 | realvalue = getDoubleArg(pArgList); |
| 446 | }else{ |
| 447 | realvalue = va_arg(ap,double); |
| 448 | } |
drh | 69ef703 | 2010-03-04 17:11:31 +0000 | [diff] [blame] | 449 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 450 | length = 0; |
| 451 | #else |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 452 | if( precision<0 ) precision = 6; /* Set default precision */ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 453 | if( realvalue<0.0 ){ |
| 454 | realvalue = -realvalue; |
| 455 | prefix = '-'; |
drh | 9adf9ac | 2002-05-15 11:44:13 +0000 | [diff] [blame] | 456 | }else{ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 457 | if( flag_plussign ) prefix = '+'; |
| 458 | else if( flag_blanksign ) prefix = ' '; |
| 459 | else prefix = 0; |
drh | 9adf9ac | 2002-05-15 11:44:13 +0000 | [diff] [blame] | 460 | } |
drh | 3e9aeec | 2005-08-13 13:39:02 +0000 | [diff] [blame] | 461 | if( xtype==etGENERIC && precision>0 ) precision--; |
drh | a30d22a | 2015-04-07 13:28:41 +0000 | [diff] [blame] | 462 | testcase( precision>0xfff ); |
drh | 74b4227 | 2015-04-07 12:41:17 +0000 | [diff] [blame] | 463 | for(idx=precision&0xfff, rounder=0.5; idx>0; idx--, rounder*=0.1){} |
drh | 3e9aeec | 2005-08-13 13:39:02 +0000 | [diff] [blame] | 464 | if( xtype==etFLOAT ) realvalue += rounder; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 465 | /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */ |
| 466 | exp = 0; |
drh | ea67883 | 2008-12-10 19:26:22 +0000 | [diff] [blame] | 467 | if( sqlite3IsNaN((double)realvalue) ){ |
drh | 53c1402 | 2007-05-10 17:23:11 +0000 | [diff] [blame] | 468 | bufpt = "NaN"; |
| 469 | length = 3; |
| 470 | break; |
| 471 | } |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 472 | if( realvalue>0.0 ){ |
drh | 72b3fbc | 2012-06-19 03:11:25 +0000 | [diff] [blame] | 473 | LONGDOUBLE_TYPE scale = 1.0; |
drh | 4ef9413 | 2012-06-19 03:35:05 +0000 | [diff] [blame] | 474 | while( realvalue>=1e100*scale && exp<=350 ){ scale *= 1e100;exp+=100;} |
drh | 2a8f671 | 2015-09-02 21:00:48 +0000 | [diff] [blame] | 475 | while( realvalue>=1e10*scale && exp<=350 ){ scale *= 1e10; exp+=10; } |
drh | 72b3fbc | 2012-06-19 03:11:25 +0000 | [diff] [blame] | 476 | while( realvalue>=10.0*scale && exp<=350 ){ scale *= 10.0; exp++; } |
| 477 | realvalue /= scale; |
drh | 93a960a | 2008-07-10 00:32:42 +0000 | [diff] [blame] | 478 | while( realvalue<1e-8 ){ realvalue *= 1e8; exp-=8; } |
| 479 | while( realvalue<1.0 ){ realvalue *= 10.0; exp--; } |
drh | af005fb | 2008-07-09 16:51:51 +0000 | [diff] [blame] | 480 | if( exp>350 ){ |
drh | 2a8f671 | 2015-09-02 21:00:48 +0000 | [diff] [blame] | 481 | bufpt = buf; |
| 482 | buf[0] = prefix; |
| 483 | memcpy(buf+(prefix!=0),"Inf",4); |
| 484 | length = 3+(prefix!=0); |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 485 | break; |
| 486 | } |
drh | 9adf9ac | 2002-05-15 11:44:13 +0000 | [diff] [blame] | 487 | } |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 488 | bufpt = buf; |
| 489 | /* |
| 490 | ** If the field type is etGENERIC, then convert to either etEXP |
| 491 | ** or etFLOAT, as appropriate. |
| 492 | */ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 493 | if( xtype!=etFLOAT ){ |
| 494 | realvalue += rounder; |
| 495 | if( realvalue>=10.0 ){ realvalue *= 0.1; exp++; } |
| 496 | } |
| 497 | if( xtype==etGENERIC ){ |
| 498 | flag_rtz = !flag_alternateform; |
| 499 | if( exp<-4 || exp>precision ){ |
| 500 | xtype = etEXP; |
| 501 | }else{ |
| 502 | precision = precision - exp; |
| 503 | xtype = etFLOAT; |
| 504 | } |
drh | 9adf9ac | 2002-05-15 11:44:13 +0000 | [diff] [blame] | 505 | }else{ |
drh | 72b3fbc | 2012-06-19 03:11:25 +0000 | [diff] [blame] | 506 | flag_rtz = flag_altform2; |
drh | 9adf9ac | 2002-05-15 11:44:13 +0000 | [diff] [blame] | 507 | } |
drh | 557cc60 | 2005-08-13 12:59:14 +0000 | [diff] [blame] | 508 | if( xtype==etEXP ){ |
| 509 | e2 = 0; |
| 510 | }else{ |
| 511 | e2 = exp; |
| 512 | } |
drh | 74b4227 | 2015-04-07 12:41:17 +0000 | [diff] [blame] | 513 | if( MAX(e2,0)+(i64)precision+(i64)width > etBUFSIZE - 15 ){ |
| 514 | bufpt = zExtra |
| 515 | = sqlite3Malloc( MAX(e2,0)+(i64)precision+(i64)width+15 ); |
drh | 59eedf7 | 2011-10-11 17:54:54 +0000 | [diff] [blame] | 516 | if( bufpt==0 ){ |
drh | a6353a3 | 2013-12-09 19:03:26 +0000 | [diff] [blame] | 517 | setStrAccumError(pAccum, STRACCUM_NOMEM); |
drh | 59eedf7 | 2011-10-11 17:54:54 +0000 | [diff] [blame] | 518 | return; |
| 519 | } |
| 520 | } |
| 521 | zOut = bufpt; |
drh | 72b3fbc | 2012-06-19 03:11:25 +0000 | [diff] [blame] | 522 | nsd = 16 + flag_altform2*10; |
drh | ea67883 | 2008-12-10 19:26:22 +0000 | [diff] [blame] | 523 | flag_dp = (precision>0 ?1:0) | flag_alternateform | flag_altform2; |
drh | 557cc60 | 2005-08-13 12:59:14 +0000 | [diff] [blame] | 524 | /* The sign in front of the number */ |
| 525 | if( prefix ){ |
| 526 | *(bufpt++) = prefix; |
| 527 | } |
| 528 | /* Digits prior to the decimal point */ |
| 529 | if( e2<0 ){ |
| 530 | *(bufpt++) = '0'; |
| 531 | }else{ |
| 532 | for(; e2>=0; e2--){ |
| 533 | *(bufpt++) = et_getdigit(&realvalue,&nsd); |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 534 | } |
drh | 9adf9ac | 2002-05-15 11:44:13 +0000 | [diff] [blame] | 535 | } |
drh | 557cc60 | 2005-08-13 12:59:14 +0000 | [diff] [blame] | 536 | /* The decimal point */ |
| 537 | if( flag_dp ){ |
| 538 | *(bufpt++) = '.'; |
| 539 | } |
| 540 | /* "0" digits after the decimal point but before the first |
| 541 | ** significant digit of the number */ |
drh | af005fb | 2008-07-09 16:51:51 +0000 | [diff] [blame] | 542 | for(e2++; e2<0; precision--, e2++){ |
| 543 | assert( precision>0 ); |
drh | 557cc60 | 2005-08-13 12:59:14 +0000 | [diff] [blame] | 544 | *(bufpt++) = '0'; |
| 545 | } |
| 546 | /* Significant digits after the decimal point */ |
| 547 | while( (precision--)>0 ){ |
| 548 | *(bufpt++) = et_getdigit(&realvalue,&nsd); |
| 549 | } |
| 550 | /* Remove trailing zeros and the "." if no digits follow the "." */ |
| 551 | if( flag_rtz && flag_dp ){ |
drh | 3e9aeec | 2005-08-13 13:39:02 +0000 | [diff] [blame] | 552 | while( bufpt[-1]=='0' ) *(--bufpt) = 0; |
drh | 59eedf7 | 2011-10-11 17:54:54 +0000 | [diff] [blame] | 553 | assert( bufpt>zOut ); |
drh | 3e9aeec | 2005-08-13 13:39:02 +0000 | [diff] [blame] | 554 | if( bufpt[-1]=='.' ){ |
drh | 557cc60 | 2005-08-13 12:59:14 +0000 | [diff] [blame] | 555 | if( flag_altform2 ){ |
| 556 | *(bufpt++) = '0'; |
| 557 | }else{ |
| 558 | *(--bufpt) = 0; |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | /* Add the "eNNN" suffix */ |
drh | 59eedf7 | 2011-10-11 17:54:54 +0000 | [diff] [blame] | 563 | if( xtype==etEXP ){ |
drh | 557cc60 | 2005-08-13 12:59:14 +0000 | [diff] [blame] | 564 | *(bufpt++) = aDigits[infop->charset]; |
| 565 | if( exp<0 ){ |
| 566 | *(bufpt++) = '-'; exp = -exp; |
| 567 | }else{ |
| 568 | *(bufpt++) = '+'; |
| 569 | } |
| 570 | if( exp>=100 ){ |
drh | ea67883 | 2008-12-10 19:26:22 +0000 | [diff] [blame] | 571 | *(bufpt++) = (char)((exp/100)+'0'); /* 100's digit */ |
drh | 557cc60 | 2005-08-13 12:59:14 +0000 | [diff] [blame] | 572 | exp %= 100; |
| 573 | } |
drh | ea67883 | 2008-12-10 19:26:22 +0000 | [diff] [blame] | 574 | *(bufpt++) = (char)(exp/10+'0'); /* 10's digit */ |
| 575 | *(bufpt++) = (char)(exp%10+'0'); /* 1's digit */ |
drh | 557cc60 | 2005-08-13 12:59:14 +0000 | [diff] [blame] | 576 | } |
| 577 | *bufpt = 0; |
| 578 | |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 579 | /* The converted number is in buf[] and zero terminated. Output it. |
| 580 | ** Note that the number is in the usual order, not reversed as with |
| 581 | ** integer conversions. */ |
drh | 59eedf7 | 2011-10-11 17:54:54 +0000 | [diff] [blame] | 582 | length = (int)(bufpt-zOut); |
| 583 | bufpt = zOut; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 584 | |
| 585 | /* Special case: Add leading zeros if the flag_zeropad flag is |
| 586 | ** set and we are not left justified */ |
| 587 | if( flag_zeropad && !flag_leftjustify && length < width){ |
| 588 | int i; |
| 589 | int nPad = width - length; |
| 590 | for(i=width; i>=nPad; i--){ |
| 591 | bufpt[i] = bufpt[i-nPad]; |
| 592 | } |
| 593 | i = prefix!=0; |
| 594 | while( nPad-- ) bufpt[i++] = '0'; |
| 595 | length = width; |
| 596 | } |
drh | 69ef703 | 2010-03-04 17:11:31 +0000 | [diff] [blame] | 597 | #endif /* !defined(SQLITE_OMIT_FLOATING_POINT) */ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 598 | break; |
| 599 | case etSIZE: |
drh | fc6ee9d | 2013-12-17 15:58:42 +0000 | [diff] [blame] | 600 | if( !bArgList ){ |
| 601 | *(va_arg(ap,int*)) = pAccum->nChar; |
| 602 | } |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 603 | length = width = 0; |
| 604 | break; |
| 605 | case etPERCENT: |
| 606 | buf[0] = '%'; |
| 607 | bufpt = buf; |
| 608 | length = 1; |
| 609 | break; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 610 | case etCHARX: |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 611 | if( bArgList ){ |
drh | fc6ee9d | 2013-12-17 15:58:42 +0000 | [diff] [blame] | 612 | bufpt = getTextArg(pArgList); |
| 613 | c = bufpt ? bufpt[0] : 0; |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 614 | }else{ |
| 615 | c = va_arg(ap,int); |
| 616 | } |
drh | af8f513 | 2014-10-29 18:20:18 +0000 | [diff] [blame] | 617 | if( precision>1 ){ |
| 618 | width -= precision-1; |
| 619 | if( width>1 && !flag_leftjustify ){ |
| 620 | sqlite3AppendChar(pAccum, width-1, ' '); |
| 621 | width = 0; |
| 622 | } |
| 623 | sqlite3AppendChar(pAccum, precision-1, c); |
drh | 9adf9ac | 2002-05-15 11:44:13 +0000 | [diff] [blame] | 624 | } |
drh | af8f513 | 2014-10-29 18:20:18 +0000 | [diff] [blame] | 625 | length = 1; |
| 626 | buf[0] = c; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 627 | bufpt = buf; |
| 628 | break; |
| 629 | case etSTRING: |
drh | d93d8a8 | 2003-06-16 03:08:18 +0000 | [diff] [blame] | 630 | case etDYNSTRING: |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 631 | if( bArgList ){ |
| 632 | bufpt = getTextArg(pArgList); |
drh | 2a8f671 | 2015-09-02 21:00:48 +0000 | [diff] [blame] | 633 | xtype = etSTRING; |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 634 | }else{ |
| 635 | bufpt = va_arg(ap,char*); |
| 636 | } |
drh | d93d8a8 | 2003-06-16 03:08:18 +0000 | [diff] [blame] | 637 | if( bufpt==0 ){ |
| 638 | bufpt = ""; |
drh | 2a8f671 | 2015-09-02 21:00:48 +0000 | [diff] [blame] | 639 | }else if( xtype==etDYNSTRING ){ |
drh | d93d8a8 | 2003-06-16 03:08:18 +0000 | [diff] [blame] | 640 | zExtra = bufpt; |
| 641 | } |
drh | e509094 | 2008-04-29 15:22:27 +0000 | [diff] [blame] | 642 | if( precision>=0 ){ |
| 643 | for(length=0; length<precision && bufpt[length]; length++){} |
| 644 | }else{ |
drh | ea67883 | 2008-12-10 19:26:22 +0000 | [diff] [blame] | 645 | length = sqlite3Strlen30(bufpt); |
drh | e509094 | 2008-04-29 15:22:27 +0000 | [diff] [blame] | 646 | } |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 647 | break; |
drh | 2a8f671 | 2015-09-02 21:00:48 +0000 | [diff] [blame] | 648 | case etSQLESCAPE: /* Escape ' characters */ |
| 649 | case etSQLESCAPE2: /* Escape ' and enclose in '...' */ |
| 650 | case etSQLESCAPE3: { /* Escape " characters */ |
drh | 8965b50 | 2009-11-25 16:53:37 +0000 | [diff] [blame] | 651 | int i, j, k, n, isnull; |
drh | 5eba8c0 | 2005-08-19 02:26:27 +0000 | [diff] [blame] | 652 | int needQuote; |
drh | ea67883 | 2008-12-10 19:26:22 +0000 | [diff] [blame] | 653 | char ch; |
danielk1977 | f3b863e | 2007-06-24 06:32:17 +0000 | [diff] [blame] | 654 | char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */ |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 655 | char *escarg; |
| 656 | |
| 657 | if( bArgList ){ |
| 658 | escarg = getTextArg(pArgList); |
| 659 | }else{ |
| 660 | escarg = va_arg(ap,char*); |
| 661 | } |
danielk1977 | f011300 | 2006-01-24 12:09:17 +0000 | [diff] [blame] | 662 | isnull = escarg==0; |
| 663 | if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)"); |
drh | 8965b50 | 2009-11-25 16:53:37 +0000 | [diff] [blame] | 664 | k = precision; |
dan | 60d4a30 | 2010-03-04 17:58:45 +0000 | [diff] [blame] | 665 | for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){ |
danielk1977 | f3b863e | 2007-06-24 06:32:17 +0000 | [diff] [blame] | 666 | if( ch==q ) n++; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 667 | } |
drh | 5eba8c0 | 2005-08-19 02:26:27 +0000 | [diff] [blame] | 668 | needQuote = !isnull && xtype==etSQLESCAPE2; |
drh | 2a8f671 | 2015-09-02 21:00:48 +0000 | [diff] [blame] | 669 | n += i + 3; |
drh | 5eba8c0 | 2005-08-19 02:26:27 +0000 | [diff] [blame] | 670 | if( n>etBUFSIZE ){ |
drh | e5ae573 | 2008-06-15 02:51:47 +0000 | [diff] [blame] | 671 | bufpt = zExtra = sqlite3Malloc( n ); |
drh | d164fd3 | 2008-11-20 18:20:28 +0000 | [diff] [blame] | 672 | if( bufpt==0 ){ |
drh | a6353a3 | 2013-12-09 19:03:26 +0000 | [diff] [blame] | 673 | setStrAccumError(pAccum, STRACCUM_NOMEM); |
drh | d164fd3 | 2008-11-20 18:20:28 +0000 | [diff] [blame] | 674 | return; |
| 675 | } |
drh | 5eba8c0 | 2005-08-19 02:26:27 +0000 | [diff] [blame] | 676 | }else{ |
| 677 | bufpt = buf; |
| 678 | } |
| 679 | j = 0; |
danielk1977 | f3b863e | 2007-06-24 06:32:17 +0000 | [diff] [blame] | 680 | if( needQuote ) bufpt[j++] = q; |
drh | 8965b50 | 2009-11-25 16:53:37 +0000 | [diff] [blame] | 681 | k = i; |
| 682 | for(i=0; i<k; i++){ |
| 683 | bufpt[j++] = ch = escarg[i]; |
danielk1977 | f3b863e | 2007-06-24 06:32:17 +0000 | [diff] [blame] | 684 | if( ch==q ) bufpt[j++] = ch; |
drh | 5eba8c0 | 2005-08-19 02:26:27 +0000 | [diff] [blame] | 685 | } |
danielk1977 | f3b863e | 2007-06-24 06:32:17 +0000 | [diff] [blame] | 686 | if( needQuote ) bufpt[j++] = q; |
drh | 5eba8c0 | 2005-08-19 02:26:27 +0000 | [diff] [blame] | 687 | bufpt[j] = 0; |
| 688 | length = j; |
drh | 8965b50 | 2009-11-25 16:53:37 +0000 | [diff] [blame] | 689 | /* The precision in %q and %Q means how many input characters to |
| 690 | ** consume, not the length of the output... |
| 691 | ** if( precision>=0 && precision<length ) length = precision; */ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 692 | break; |
drh | 5eba8c0 | 2005-08-19 02:26:27 +0000 | [diff] [blame] | 693 | } |
drh | 5f96843 | 2004-02-21 19:02:30 +0000 | [diff] [blame] | 694 | case etTOKEN: { |
drh | 8236f68 | 2017-01-04 00:26:28 +0000 | [diff] [blame] | 695 | Token *pToken; |
| 696 | if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return; |
| 697 | pToken = va_arg(ap, Token*); |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 698 | assert( bArgList==0 ); |
drh | a9ab481 | 2013-12-11 11:00:44 +0000 | [diff] [blame] | 699 | if( pToken && pToken->n ){ |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 700 | sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n); |
drh | ad6d946 | 2004-09-19 02:15:24 +0000 | [diff] [blame] | 701 | } |
drh | 5f96843 | 2004-02-21 19:02:30 +0000 | [diff] [blame] | 702 | length = width = 0; |
| 703 | break; |
| 704 | } |
| 705 | case etSRCLIST: { |
drh | 8236f68 | 2017-01-04 00:26:28 +0000 | [diff] [blame] | 706 | SrcList *pSrc; |
| 707 | int k; |
| 708 | struct SrcList_item *pItem; |
| 709 | if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return; |
| 710 | pSrc = va_arg(ap, SrcList*); |
| 711 | k = va_arg(ap, int); |
| 712 | pItem = &pSrc->a[k]; |
drh | a5c1416 | 2013-12-17 15:03:06 +0000 | [diff] [blame] | 713 | assert( bArgList==0 ); |
drh | 5f96843 | 2004-02-21 19:02:30 +0000 | [diff] [blame] | 714 | assert( k>=0 && k<pSrc->nSrc ); |
drh | 93a960a | 2008-07-10 00:32:42 +0000 | [diff] [blame] | 715 | if( pItem->zDatabase ){ |
drh | a6353a3 | 2013-12-09 19:03:26 +0000 | [diff] [blame] | 716 | sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase); |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 717 | sqlite3StrAccumAppend(pAccum, ".", 1); |
drh | 5f96843 | 2004-02-21 19:02:30 +0000 | [diff] [blame] | 718 | } |
drh | a6353a3 | 2013-12-09 19:03:26 +0000 | [diff] [blame] | 719 | sqlite3StrAccumAppendAll(pAccum, pItem->zName); |
drh | 5f96843 | 2004-02-21 19:02:30 +0000 | [diff] [blame] | 720 | length = width = 0; |
| 721 | break; |
| 722 | } |
drh | 874ba04 | 2009-04-08 16:10:04 +0000 | [diff] [blame] | 723 | default: { |
| 724 | assert( xtype==etINVALID ); |
| 725 | return; |
| 726 | } |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 727 | }/* End switch over the format type */ |
| 728 | /* |
| 729 | ** The text of the conversion is pointed to by "bufpt" and is |
| 730 | ** "length" characters long. The field width is "width". Do |
| 731 | ** the output. |
| 732 | */ |
drh | a70a073 | 2014-03-17 14:24:27 +0000 | [diff] [blame] | 733 | width -= length; |
drh | 8236f68 | 2017-01-04 00:26:28 +0000 | [diff] [blame] | 734 | if( width>0 ){ |
| 735 | if( !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' '); |
| 736 | sqlite3StrAccumAppend(pAccum, bufpt, length); |
| 737 | if( flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' '); |
| 738 | }else{ |
| 739 | sqlite3StrAccumAppend(pAccum, bufpt, length); |
| 740 | } |
drh | a70a073 | 2014-03-17 14:24:27 +0000 | [diff] [blame] | 741 | |
drh | af8f513 | 2014-10-29 18:20:18 +0000 | [diff] [blame] | 742 | if( zExtra ){ |
drh | 96ceaf8 | 2015-11-14 22:04:22 +0000 | [diff] [blame] | 743 | sqlite3DbFree(pAccum->db, zExtra); |
drh | af8f513 | 2014-10-29 18:20:18 +0000 | [diff] [blame] | 744 | zExtra = 0; |
| 745 | } |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 746 | }/* End for loop over the format string */ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 747 | } /* End of function */ |
| 748 | |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 749 | /* |
drh | a70a073 | 2014-03-17 14:24:27 +0000 | [diff] [blame] | 750 | ** Enlarge the memory allocation on a StrAccum object so that it is |
| 751 | ** able to accept at least N more bytes of text. |
| 752 | ** |
| 753 | ** Return the number of bytes of text that StrAccum is able to accept |
| 754 | ** after the attempted enlargement. The value returned might be zero. |
| 755 | */ |
| 756 | static int sqlite3StrAccumEnlarge(StrAccum *p, int N){ |
| 757 | char *zNew; |
drh | a30d22a | 2015-04-07 13:28:41 +0000 | [diff] [blame] | 758 | assert( p->nChar+(i64)N >= p->nAlloc ); /* Only called if really needed */ |
drh | a70a073 | 2014-03-17 14:24:27 +0000 | [diff] [blame] | 759 | if( p->accError ){ |
| 760 | testcase(p->accError==STRACCUM_TOOBIG); |
| 761 | testcase(p->accError==STRACCUM_NOMEM); |
| 762 | return 0; |
| 763 | } |
drh | c049057 | 2015-05-02 11:45:53 +0000 | [diff] [blame] | 764 | if( p->mxAlloc==0 ){ |
drh | a70a073 | 2014-03-17 14:24:27 +0000 | [diff] [blame] | 765 | N = p->nAlloc - p->nChar - 1; |
| 766 | setStrAccumError(p, STRACCUM_TOOBIG); |
| 767 | return N; |
| 768 | }else{ |
drh | 5f4a686 | 2016-01-30 12:50:25 +0000 | [diff] [blame] | 769 | char *zOld = isMalloced(p) ? p->zText : 0; |
drh | a70a073 | 2014-03-17 14:24:27 +0000 | [diff] [blame] | 770 | i64 szNew = p->nChar; |
drh | 5f4a686 | 2016-01-30 12:50:25 +0000 | [diff] [blame] | 771 | assert( (p->zText==0 || p->zText==p->zBase)==!isMalloced(p) ); |
drh | a70a073 | 2014-03-17 14:24:27 +0000 | [diff] [blame] | 772 | szNew += N + 1; |
drh | 7b4d780 | 2014-11-03 14:46:29 +0000 | [diff] [blame] | 773 | if( szNew+p->nChar<=p->mxAlloc ){ |
| 774 | /* Force exponential buffer size growth as long as it does not overflow, |
| 775 | ** to avoid having to call this routine too often */ |
| 776 | szNew += p->nChar; |
| 777 | } |
drh | a70a073 | 2014-03-17 14:24:27 +0000 | [diff] [blame] | 778 | if( szNew > p->mxAlloc ){ |
| 779 | sqlite3StrAccumReset(p); |
| 780 | setStrAccumError(p, STRACCUM_TOOBIG); |
| 781 | return 0; |
| 782 | }else{ |
| 783 | p->nAlloc = (int)szNew; |
| 784 | } |
drh | c049057 | 2015-05-02 11:45:53 +0000 | [diff] [blame] | 785 | if( p->db ){ |
drh | a70a073 | 2014-03-17 14:24:27 +0000 | [diff] [blame] | 786 | zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc); |
| 787 | }else{ |
drh | f3cdcdc | 2015-04-29 16:50:28 +0000 | [diff] [blame] | 788 | zNew = sqlite3_realloc64(zOld, p->nAlloc); |
drh | a70a073 | 2014-03-17 14:24:27 +0000 | [diff] [blame] | 789 | } |
| 790 | if( zNew ){ |
drh | 7ef4d1c | 2014-05-31 15:39:53 +0000 | [diff] [blame] | 791 | assert( p->zText!=0 || p->nChar==0 ); |
drh | 5f4a686 | 2016-01-30 12:50:25 +0000 | [diff] [blame] | 792 | if( !isMalloced(p) && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); |
drh | a70a073 | 2014-03-17 14:24:27 +0000 | [diff] [blame] | 793 | p->zText = zNew; |
drh | 7f5a7ec | 2014-11-03 13:24:12 +0000 | [diff] [blame] | 794 | p->nAlloc = sqlite3DbMallocSize(p->db, zNew); |
drh | 5f4a686 | 2016-01-30 12:50:25 +0000 | [diff] [blame] | 795 | p->printfFlags |= SQLITE_PRINTF_MALLOCED; |
drh | a70a073 | 2014-03-17 14:24:27 +0000 | [diff] [blame] | 796 | }else{ |
| 797 | sqlite3StrAccumReset(p); |
| 798 | setStrAccumError(p, STRACCUM_NOMEM); |
| 799 | return 0; |
| 800 | } |
| 801 | } |
| 802 | return N; |
| 803 | } |
| 804 | |
| 805 | /* |
drh | af8f513 | 2014-10-29 18:20:18 +0000 | [diff] [blame] | 806 | ** Append N copies of character c to the given string buffer. |
drh | a70a073 | 2014-03-17 14:24:27 +0000 | [diff] [blame] | 807 | */ |
drh | af8f513 | 2014-10-29 18:20:18 +0000 | [diff] [blame] | 808 | void sqlite3AppendChar(StrAccum *p, int N, char c){ |
drh | a30d22a | 2015-04-07 13:28:41 +0000 | [diff] [blame] | 809 | testcase( p->nChar + (i64)N > 0x7fffffff ); |
| 810 | if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){ |
| 811 | return; |
| 812 | } |
drh | 5f4a686 | 2016-01-30 12:50:25 +0000 | [diff] [blame] | 813 | assert( (p->zText==p->zBase)==!isMalloced(p) ); |
drh | af8f513 | 2014-10-29 18:20:18 +0000 | [diff] [blame] | 814 | while( (N--)>0 ) p->zText[p->nChar++] = c; |
drh | a70a073 | 2014-03-17 14:24:27 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | /* |
| 818 | ** The StrAccum "p" is not large enough to accept N new bytes of z[]. |
| 819 | ** So enlarge if first, then do the append. |
| 820 | ** |
| 821 | ** This is a helper routine to sqlite3StrAccumAppend() that does special-case |
| 822 | ** work (enlarging the buffer) using tail recursion, so that the |
| 823 | ** sqlite3StrAccumAppend() routine can use fast calling semantics. |
| 824 | */ |
drh | 172087f | 2014-08-22 15:40:20 +0000 | [diff] [blame] | 825 | static void SQLITE_NOINLINE enlargeAndAppend(StrAccum *p, const char *z, int N){ |
drh | a70a073 | 2014-03-17 14:24:27 +0000 | [diff] [blame] | 826 | N = sqlite3StrAccumEnlarge(p, N); |
| 827 | if( N>0 ){ |
| 828 | memcpy(&p->zText[p->nChar], z, N); |
| 829 | p->nChar += N; |
| 830 | } |
drh | 5f4a686 | 2016-01-30 12:50:25 +0000 | [diff] [blame] | 831 | assert( (p->zText==0 || p->zText==p->zBase)==!isMalloced(p) ); |
drh | a70a073 | 2014-03-17 14:24:27 +0000 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | /* |
| 835 | ** Append N bytes of text from z to the StrAccum object. Increase the |
| 836 | ** size of the memory allocation for StrAccum if necessary. |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 837 | */ |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 838 | void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ |
drh | 3457338 | 2015-04-15 05:38:35 +0000 | [diff] [blame] | 839 | assert( z!=0 || N==0 ); |
drh | a6353a3 | 2013-12-09 19:03:26 +0000 | [diff] [blame] | 840 | assert( p->zText!=0 || p->nChar==0 || p->accError ); |
| 841 | assert( N>=0 ); |
| 842 | assert( p->accError==0 || p->nAlloc==0 ); |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 843 | if( p->nChar+N >= p->nAlloc ){ |
drh | a70a073 | 2014-03-17 14:24:27 +0000 | [diff] [blame] | 844 | enlargeAndAppend(p,z,N); |
dan | 895decf | 2016-12-30 14:15:56 +0000 | [diff] [blame] | 845 | }else if( N ){ |
drh | 172087f | 2014-08-22 15:40:20 +0000 | [diff] [blame] | 846 | assert( p->zText ); |
| 847 | p->nChar += N; |
| 848 | memcpy(&p->zText[p->nChar-N], z, N); |
drh | 5f96843 | 2004-02-21 19:02:30 +0000 | [diff] [blame] | 849 | } |
drh | 483750b | 2003-01-29 18:46:51 +0000 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | /* |
drh | a6353a3 | 2013-12-09 19:03:26 +0000 | [diff] [blame] | 853 | ** Append the complete text of zero-terminated string z[] to the p string. |
| 854 | */ |
| 855 | void sqlite3StrAccumAppendAll(StrAccum *p, const char *z){ |
mistachkin | 53cd964 | 2013-12-11 02:21:19 +0000 | [diff] [blame] | 856 | sqlite3StrAccumAppend(p, z, sqlite3Strlen30(z)); |
drh | a6353a3 | 2013-12-09 19:03:26 +0000 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | |
| 860 | /* |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 861 | ** Finish off a string by making sure it is zero-terminated. |
| 862 | ** Return a pointer to the resulting string. Return a NULL |
| 863 | ** pointer if any kind of error was encountered. |
drh | 5f96843 | 2004-02-21 19:02:30 +0000 | [diff] [blame] | 864 | */ |
drh | 043e586 | 2016-11-25 15:11:26 +0000 | [diff] [blame] | 865 | static SQLITE_NOINLINE char *strAccumFinishRealloc(StrAccum *p){ |
| 866 | assert( p->mxAlloc>0 && !isMalloced(p) ); |
| 867 | p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 ); |
| 868 | if( p->zText ){ |
| 869 | memcpy(p->zText, p->zBase, p->nChar+1); |
| 870 | p->printfFlags |= SQLITE_PRINTF_MALLOCED; |
| 871 | }else{ |
| 872 | setStrAccumError(p, STRACCUM_NOMEM); |
| 873 | } |
| 874 | return p->zText; |
| 875 | } |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 876 | char *sqlite3StrAccumFinish(StrAccum *p){ |
| 877 | if( p->zText ){ |
drh | 5f4a686 | 2016-01-30 12:50:25 +0000 | [diff] [blame] | 878 | assert( (p->zText==p->zBase)==!isMalloced(p) ); |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 879 | p->zText[p->nChar] = 0; |
drh | 5f4a686 | 2016-01-30 12:50:25 +0000 | [diff] [blame] | 880 | if( p->mxAlloc>0 && !isMalloced(p) ){ |
drh | 043e586 | 2016-11-25 15:11:26 +0000 | [diff] [blame] | 881 | return strAccumFinishRealloc(p); |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 882 | } |
| 883 | } |
| 884 | return p->zText; |
| 885 | } |
| 886 | |
| 887 | /* |
| 888 | ** Reset an StrAccum string. Reclaim all malloced memory. |
| 889 | */ |
| 890 | void sqlite3StrAccumReset(StrAccum *p){ |
drh | 5f4a686 | 2016-01-30 12:50:25 +0000 | [diff] [blame] | 891 | assert( (p->zText==0 || p->zText==p->zBase)==!isMalloced(p) ); |
| 892 | if( isMalloced(p) ){ |
drh | c049057 | 2015-05-02 11:45:53 +0000 | [diff] [blame] | 893 | sqlite3DbFree(p->db, p->zText); |
drh | 5f4a686 | 2016-01-30 12:50:25 +0000 | [diff] [blame] | 894 | p->printfFlags &= ~SQLITE_PRINTF_MALLOCED; |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 895 | } |
drh | f089aa4 | 2008-07-08 19:34:06 +0000 | [diff] [blame] | 896 | p->zText = 0; |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | /* |
drh | c049057 | 2015-05-02 11:45:53 +0000 | [diff] [blame] | 900 | ** Initialize a string accumulator. |
| 901 | ** |
| 902 | ** p: The accumulator to be initialized. |
| 903 | ** db: Pointer to a database connection. May be NULL. Lookaside |
| 904 | ** memory is used if not NULL. db->mallocFailed is set appropriately |
| 905 | ** when not NULL. |
| 906 | ** zBase: An initial buffer. May be NULL in which case the initial buffer |
| 907 | ** is malloced. |
| 908 | ** n: Size of zBase in bytes. If total space requirements never exceed |
| 909 | ** n then no memory allocations ever occur. |
| 910 | ** mx: Maximum number of bytes to accumulate. If mx==0 then no memory |
| 911 | ** allocations will ever occur. |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 912 | */ |
drh | c049057 | 2015-05-02 11:45:53 +0000 | [diff] [blame] | 913 | void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){ |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 914 | p->zText = p->zBase = zBase; |
drh | c049057 | 2015-05-02 11:45:53 +0000 | [diff] [blame] | 915 | p->db = db; |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 916 | p->nChar = 0; |
| 917 | p->nAlloc = n; |
drh | bb4957f | 2008-03-20 14:03:29 +0000 | [diff] [blame] | 918 | p->mxAlloc = mx; |
drh | b49bc86 | 2013-08-21 21:12:10 +0000 | [diff] [blame] | 919 | p->accError = 0; |
drh | 5f4a686 | 2016-01-30 12:50:25 +0000 | [diff] [blame] | 920 | p->printfFlags = 0; |
drh | 5f96843 | 2004-02-21 19:02:30 +0000 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | /* |
| 924 | ** Print into memory obtained from sqliteMalloc(). Use the internal |
| 925 | ** %-conversion extensions. |
| 926 | */ |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 927 | char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){ |
| 928 | char *z; |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 929 | char zBase[SQLITE_PRINT_BUF_SIZE]; |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 930 | StrAccum acc; |
drh | bc6160b | 2009-04-08 15:45:31 +0000 | [diff] [blame] | 931 | assert( db!=0 ); |
drh | c049057 | 2015-05-02 11:45:53 +0000 | [diff] [blame] | 932 | sqlite3StrAccumInit(&acc, db, zBase, sizeof(zBase), |
drh | bc6160b | 2009-04-08 15:45:31 +0000 | [diff] [blame] | 933 | db->aLimit[SQLITE_LIMIT_LENGTH]); |
drh | 5f4a686 | 2016-01-30 12:50:25 +0000 | [diff] [blame] | 934 | acc.printfFlags = SQLITE_PRINTF_INTERNAL; |
| 935 | sqlite3VXPrintf(&acc, zFormat, ap); |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 936 | z = sqlite3StrAccumFinish(&acc); |
drh | b49bc86 | 2013-08-21 21:12:10 +0000 | [diff] [blame] | 937 | if( acc.accError==STRACCUM_NOMEM ){ |
drh | 4a642b6 | 2016-02-05 01:55:27 +0000 | [diff] [blame] | 938 | sqlite3OomFault(db); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 939 | } |
| 940 | return z; |
drh | 5f96843 | 2004-02-21 19:02:30 +0000 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | /* |
| 944 | ** Print into memory obtained from sqliteMalloc(). Use the internal |
| 945 | ** %-conversion extensions. |
| 946 | */ |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 947 | char *sqlite3MPrintf(sqlite3 *db, const char *zFormat, ...){ |
drh | 5f96843 | 2004-02-21 19:02:30 +0000 | [diff] [blame] | 948 | va_list ap; |
| 949 | char *z; |
drh | 5f96843 | 2004-02-21 19:02:30 +0000 | [diff] [blame] | 950 | va_start(ap, zFormat); |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 951 | z = sqlite3VMPrintf(db, zFormat, ap); |
drh | 5f96843 | 2004-02-21 19:02:30 +0000 | [diff] [blame] | 952 | va_end(ap); |
| 953 | return z; |
| 954 | } |
| 955 | |
| 956 | /* |
drh | 28dd479 | 2006-06-26 21:35:44 +0000 | [diff] [blame] | 957 | ** Print into memory obtained from sqlite3_malloc(). Omit the internal |
| 958 | ** %-conversion extensions. |
| 959 | */ |
| 960 | char *sqlite3_vmprintf(const char *zFormat, va_list ap){ |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 961 | char *z; |
drh | 28dd479 | 2006-06-26 21:35:44 +0000 | [diff] [blame] | 962 | char zBase[SQLITE_PRINT_BUF_SIZE]; |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 963 | StrAccum acc; |
drh | 9ca9573 | 2014-10-24 00:35:58 +0000 | [diff] [blame] | 964 | |
| 965 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 966 | if( zFormat==0 ){ |
| 967 | (void)SQLITE_MISUSE_BKPT; |
| 968 | return 0; |
| 969 | } |
| 970 | #endif |
drh | ff1590e | 2008-07-14 12:52:53 +0000 | [diff] [blame] | 971 | #ifndef SQLITE_OMIT_AUTOINIT |
| 972 | if( sqlite3_initialize() ) return 0; |
| 973 | #endif |
drh | c049057 | 2015-05-02 11:45:53 +0000 | [diff] [blame] | 974 | sqlite3StrAccumInit(&acc, 0, zBase, sizeof(zBase), SQLITE_MAX_LENGTH); |
drh | 5f4a686 | 2016-01-30 12:50:25 +0000 | [diff] [blame] | 975 | sqlite3VXPrintf(&acc, zFormat, ap); |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 976 | z = sqlite3StrAccumFinish(&acc); |
| 977 | return z; |
drh | 28dd479 | 2006-06-26 21:35:44 +0000 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | /* |
| 981 | ** Print into memory obtained from sqlite3_malloc()(). Omit the internal |
| 982 | ** %-conversion extensions. |
drh | 483750b | 2003-01-29 18:46:51 +0000 | [diff] [blame] | 983 | */ |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 984 | char *sqlite3_mprintf(const char *zFormat, ...){ |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 985 | va_list ap; |
drh | 5f96843 | 2004-02-21 19:02:30 +0000 | [diff] [blame] | 986 | char *z; |
drh | ff1590e | 2008-07-14 12:52:53 +0000 | [diff] [blame] | 987 | #ifndef SQLITE_OMIT_AUTOINIT |
| 988 | if( sqlite3_initialize() ) return 0; |
| 989 | #endif |
drh | 28dd479 | 2006-06-26 21:35:44 +0000 | [diff] [blame] | 990 | va_start(ap, zFormat); |
drh | b3738b6 | 2007-03-31 15:02:49 +0000 | [diff] [blame] | 991 | z = sqlite3_vmprintf(zFormat, ap); |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 992 | va_end(ap); |
drh | 5f96843 | 2004-02-21 19:02:30 +0000 | [diff] [blame] | 993 | return z; |
drh | a18c568 | 2000-10-08 22:20:57 +0000 | [diff] [blame] | 994 | } |
| 995 | |
drh | 93a5c6b | 2003-12-23 02:17:35 +0000 | [diff] [blame] | 996 | /* |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 997 | ** sqlite3_snprintf() works like snprintf() except that it ignores the |
drh | 93a5c6b | 2003-12-23 02:17:35 +0000 | [diff] [blame] | 998 | ** current locale settings. This is important for SQLite because we |
| 999 | ** are not able to use a "," as the decimal point in place of "." as |
| 1000 | ** specified by some locales. |
drh | db26d4c | 2011-01-05 12:20:09 +0000 | [diff] [blame] | 1001 | ** |
| 1002 | ** Oops: The first two arguments of sqlite3_snprintf() are backwards |
| 1003 | ** from the snprintf() standard. Unfortunately, it is too late to change |
| 1004 | ** this without breaking compatibility, so we just have to live with the |
| 1005 | ** mistake. |
| 1006 | ** |
| 1007 | ** sqlite3_vsnprintf() is the varargs version. |
drh | 93a5c6b | 2003-12-23 02:17:35 +0000 | [diff] [blame] | 1008 | */ |
drh | db26d4c | 2011-01-05 12:20:09 +0000 | [diff] [blame] | 1009 | char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){ |
| 1010 | StrAccum acc; |
| 1011 | if( n<=0 ) return zBuf; |
drh | 9ca9573 | 2014-10-24 00:35:58 +0000 | [diff] [blame] | 1012 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 1013 | if( zBuf==0 || zFormat==0 ) { |
| 1014 | (void)SQLITE_MISUSE_BKPT; |
drh | 96c707a | 2015-02-13 16:36:14 +0000 | [diff] [blame] | 1015 | if( zBuf ) zBuf[0] = 0; |
drh | 9ca9573 | 2014-10-24 00:35:58 +0000 | [diff] [blame] | 1016 | return zBuf; |
| 1017 | } |
| 1018 | #endif |
drh | c049057 | 2015-05-02 11:45:53 +0000 | [diff] [blame] | 1019 | sqlite3StrAccumInit(&acc, 0, zBuf, n, 0); |
drh | 5f4a686 | 2016-01-30 12:50:25 +0000 | [diff] [blame] | 1020 | sqlite3VXPrintf(&acc, zFormat, ap); |
drh | e9bb566 | 2016-11-25 15:47:53 +0000 | [diff] [blame] | 1021 | zBuf[acc.nChar] = 0; |
| 1022 | return zBuf; |
drh | db26d4c | 2011-01-05 12:20:09 +0000 | [diff] [blame] | 1023 | } |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1024 | char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){ |
drh | 5f96843 | 2004-02-21 19:02:30 +0000 | [diff] [blame] | 1025 | char *z; |
drh | 93a5c6b | 2003-12-23 02:17:35 +0000 | [diff] [blame] | 1026 | va_list ap; |
drh | 93a5c6b | 2003-12-23 02:17:35 +0000 | [diff] [blame] | 1027 | va_start(ap,zFormat); |
drh | db26d4c | 2011-01-05 12:20:09 +0000 | [diff] [blame] | 1028 | z = sqlite3_vsnprintf(n, zBuf, zFormat, ap); |
drh | 93a5c6b | 2003-12-23 02:17:35 +0000 | [diff] [blame] | 1029 | va_end(ap); |
drh | 5f96843 | 2004-02-21 19:02:30 +0000 | [diff] [blame] | 1030 | return z; |
drh | 93a5c6b | 2003-12-23 02:17:35 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
drh | 3f28070 | 2010-02-18 18:45:09 +0000 | [diff] [blame] | 1033 | /* |
drh | 7c0c460 | 2010-03-03 22:25:18 +0000 | [diff] [blame] | 1034 | ** This is the routine that actually formats the sqlite3_log() message. |
| 1035 | ** We house it in a separate routine from sqlite3_log() to avoid using |
| 1036 | ** stack space on small-stack systems when logging is disabled. |
| 1037 | ** |
| 1038 | ** sqlite3_log() must render into a static buffer. It cannot dynamically |
| 1039 | ** allocate memory because it might be called while the memory allocator |
| 1040 | ** mutex is held. |
drh | a8dbd52 | 2015-07-14 22:43:37 +0000 | [diff] [blame] | 1041 | ** |
| 1042 | ** sqlite3VXPrintf() might ask for *temporary* memory allocations for |
| 1043 | ** certain format characters (%q) or for very large precisions or widths. |
| 1044 | ** Care must be taken that any sqlite3_log() calls that occur while the |
| 1045 | ** memory mutex is held do not use these mechanisms. |
drh | 7c0c460 | 2010-03-03 22:25:18 +0000 | [diff] [blame] | 1046 | */ |
| 1047 | static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){ |
drh | a64fa91 | 2010-03-04 00:53:32 +0000 | [diff] [blame] | 1048 | StrAccum acc; /* String accumulator */ |
| 1049 | char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */ |
drh | 7c0c460 | 2010-03-03 22:25:18 +0000 | [diff] [blame] | 1050 | |
drh | c049057 | 2015-05-02 11:45:53 +0000 | [diff] [blame] | 1051 | sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0); |
drh | 5f4a686 | 2016-01-30 12:50:25 +0000 | [diff] [blame] | 1052 | sqlite3VXPrintf(&acc, zFormat, ap); |
drh | 7c0c460 | 2010-03-03 22:25:18 +0000 | [diff] [blame] | 1053 | sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode, |
| 1054 | sqlite3StrAccumFinish(&acc)); |
| 1055 | } |
| 1056 | |
| 1057 | /* |
drh | 3f28070 | 2010-02-18 18:45:09 +0000 | [diff] [blame] | 1058 | ** Format and write a message to the log if logging is enabled. |
| 1059 | */ |
drh | a756466 | 2010-02-22 19:32:31 +0000 | [diff] [blame] | 1060 | void sqlite3_log(int iErrCode, const char *zFormat, ...){ |
drh | 3f28070 | 2010-02-18 18:45:09 +0000 | [diff] [blame] | 1061 | va_list ap; /* Vararg list */ |
drh | 7c0c460 | 2010-03-03 22:25:18 +0000 | [diff] [blame] | 1062 | if( sqlite3GlobalConfig.xLog ){ |
drh | 3f28070 | 2010-02-18 18:45:09 +0000 | [diff] [blame] | 1063 | va_start(ap, zFormat); |
drh | 7c0c460 | 2010-03-03 22:25:18 +0000 | [diff] [blame] | 1064 | renderLogMsg(iErrCode, zFormat, ap); |
drh | 3f28070 | 2010-02-18 18:45:09 +0000 | [diff] [blame] | 1065 | va_end(ap); |
drh | 3f28070 | 2010-02-18 18:45:09 +0000 | [diff] [blame] | 1066 | } |
| 1067 | } |
| 1068 | |
mistachkin | 02b0e26 | 2015-04-16 03:37:19 +0000 | [diff] [blame] | 1069 | #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
drh | e54ca3f | 2004-06-07 01:52:14 +0000 | [diff] [blame] | 1070 | /* |
| 1071 | ** A version of printf() that understands %lld. Used for debugging. |
| 1072 | ** The printf() built into some versions of windows does not understand %lld |
| 1073 | ** and segfaults if you give it a long long int. |
| 1074 | */ |
| 1075 | void sqlite3DebugPrintf(const char *zFormat, ...){ |
| 1076 | va_list ap; |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 1077 | StrAccum acc; |
drh | e54ca3f | 2004-06-07 01:52:14 +0000 | [diff] [blame] | 1078 | char zBuf[500]; |
drh | c049057 | 2015-05-02 11:45:53 +0000 | [diff] [blame] | 1079 | sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 1080 | va_start(ap,zFormat); |
drh | 5f4a686 | 2016-01-30 12:50:25 +0000 | [diff] [blame] | 1081 | sqlite3VXPrintf(&acc, zFormat, ap); |
drh | e54ca3f | 2004-06-07 01:52:14 +0000 | [diff] [blame] | 1082 | va_end(ap); |
drh | bed8e7e | 2007-12-08 17:55:35 +0000 | [diff] [blame] | 1083 | sqlite3StrAccumFinish(&acc); |
drh | 485f003 | 2007-01-26 19:23:33 +0000 | [diff] [blame] | 1084 | fprintf(stdout,"%s", zBuf); |
drh | 2ac3ee9 | 2004-06-07 16:27:46 +0000 | [diff] [blame] | 1085 | fflush(stdout); |
drh | e54ca3f | 2004-06-07 01:52:14 +0000 | [diff] [blame] | 1086 | } |
| 1087 | #endif |
drh | c7bc4fd | 2009-11-25 18:03:42 +0000 | [diff] [blame] | 1088 | |
drh | 4fa4a54 | 2014-09-30 12:33:33 +0000 | [diff] [blame] | 1089 | |
drh | c7bc4fd | 2009-11-25 18:03:42 +0000 | [diff] [blame] | 1090 | /* |
drh | d37bea5 | 2015-09-02 15:37:50 +0000 | [diff] [blame] | 1091 | ** variable-argument wrapper around sqlite3VXPrintf(). The bFlags argument |
| 1092 | ** can contain the bit SQLITE_PRINTF_INTERNAL enable internal formats. |
drh | c7bc4fd | 2009-11-25 18:03:42 +0000 | [diff] [blame] | 1093 | */ |
drh | 5f4a686 | 2016-01-30 12:50:25 +0000 | [diff] [blame] | 1094 | void sqlite3XPrintf(StrAccum *p, const char *zFormat, ...){ |
drh | c7bc4fd | 2009-11-25 18:03:42 +0000 | [diff] [blame] | 1095 | va_list ap; |
| 1096 | va_start(ap,zFormat); |
drh | 5f4a686 | 2016-01-30 12:50:25 +0000 | [diff] [blame] | 1097 | sqlite3VXPrintf(p, zFormat, ap); |
drh | c7bc4fd | 2009-11-25 18:03:42 +0000 | [diff] [blame] | 1098 | va_end(ap); |
| 1099 | } |