aboutsummaryrefslogtreecommitdiff
path: root/src/printf.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2009-11-25 16:53:37 +0000
committerdrh <drh@noemail.net>2009-11-25 16:53:37 +0000
commit8965b50edffbad6b62dbc65b6a04830f9d5b9548 (patch)
tree6a4905e5c1cee35dc50414de11d482b28acae782 /src/printf.c
parent5ff44379b38b80098029f67c7bf2ec954ea2449d (diff)
downloadsqlite-8965b50edffbad6b62dbc65b6a04830f9d5b9548.tar.gz
sqlite-8965b50edffbad6b62dbc65b6a04830f9d5b9548.zip
Enhance the %q, %Q, and %w printf conversions so that the precisions
specifies the length of the input. FossilOrigin-Name: 3ba773132d3baeb87acaee538b8fb0b0f4293673
Diffstat (limited to 'src/printf.c')
-rw-r--r--src/printf.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/printf.c b/src/printf.c
index 5a790a15d..fdd1222c2 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -645,14 +645,15 @@ void sqlite3VXPrintf(
case etSQLESCAPE:
case etSQLESCAPE2:
case etSQLESCAPE3: {
- int i, j, n, isnull;
+ int i, j, k, n, isnull;
int needQuote;
char ch;
char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
char *escarg = va_arg(ap,char*);
isnull = escarg==0;
if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
- for(i=n=0; (ch=escarg[i])!=0; i++){
+ k = precision;
+ for(i=n=0; (ch=escarg[i])!=0 && k!=0; i++, k--){
if( ch==q ) n++;
}
needQuote = !isnull && xtype==etSQLESCAPE2;
@@ -668,15 +669,17 @@ void sqlite3VXPrintf(
}
j = 0;
if( needQuote ) bufpt[j++] = q;
- for(i=0; (ch=escarg[i])!=0; i++){
- bufpt[j++] = ch;
+ k = i;
+ for(i=0; i<k; i++){
+ bufpt[j++] = ch = escarg[i];
if( ch==q ) bufpt[j++] = ch;
}
if( needQuote ) bufpt[j++] = q;
bufpt[j] = 0;
length = j;
- /* The precision is ignored on %q and %Q */
- /* if( precision>=0 && precision<length ) length = precision; */
+ /* The precision in %q and %Q means how many input characters to
+ ** consume, not the length of the output...
+ ** if( precision>=0 && precision<length ) length = precision; */
break;
}
case etTOKEN: {