Fossil SCM
Fix the non-standard %q format specifier in Fossil's custom printf() implementation so that the precision refers to the number of input characters, not the number of output characters.
Commit
0971536165b064ee6dc643c6782a2a20ef86938138e334e348de29be04861869
Parent
d62593b7878adf1…
1 file changed
+1
-1
+1
-1
| --- src/printf.c | ||
| +++ src/printf.c | ||
| @@ -774,10 +774,11 @@ | ||
| 774 | 774 | char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote characters */ |
| 775 | 775 | char *escarg = va_arg(ap,char*); |
| 776 | 776 | isnull = escarg==0; |
| 777 | 777 | if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)"); |
| 778 | 778 | if( limit<0 ) limit = strlen(escarg); |
| 779 | + if( precision>=0 && precision<limit ) limit = precision; | |
| 779 | 780 | for(i=n=0; i<limit; i++){ |
| 780 | 781 | if( escarg[i]==q ) n++; |
| 781 | 782 | } |
| 782 | 783 | needQuote = !isnull && xtype==etSQLESCAPE2; |
| 783 | 784 | n += i + 1 + needQuote*2; |
| @@ -793,11 +794,10 @@ | ||
| 793 | 794 | if( ch==q ) bufpt[j++] = ch; |
| 794 | 795 | } |
| 795 | 796 | if( needQuote ) bufpt[j++] = q; |
| 796 | 797 | bufpt[j] = 0; |
| 797 | 798 | length = j; |
| 798 | - if( precision>=0 && precision<length ) length = precision; | |
| 799 | 799 | break; |
| 800 | 800 | } |
| 801 | 801 | case etHTMLIZE: { |
| 802 | 802 | int limit = flag_alternateform ? va_arg(ap,int) : -1; |
| 803 | 803 | char *zMem = va_arg(ap,char*); |
| 804 | 804 |
| --- src/printf.c | |
| +++ src/printf.c | |
| @@ -774,10 +774,11 @@ | |
| 774 | char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote characters */ |
| 775 | char *escarg = va_arg(ap,char*); |
| 776 | isnull = escarg==0; |
| 777 | if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)"); |
| 778 | if( limit<0 ) limit = strlen(escarg); |
| 779 | for(i=n=0; i<limit; i++){ |
| 780 | if( escarg[i]==q ) n++; |
| 781 | } |
| 782 | needQuote = !isnull && xtype==etSQLESCAPE2; |
| 783 | n += i + 1 + needQuote*2; |
| @@ -793,11 +794,10 @@ | |
| 793 | if( ch==q ) bufpt[j++] = ch; |
| 794 | } |
| 795 | if( needQuote ) bufpt[j++] = q; |
| 796 | bufpt[j] = 0; |
| 797 | length = j; |
| 798 | if( precision>=0 && precision<length ) length = precision; |
| 799 | break; |
| 800 | } |
| 801 | case etHTMLIZE: { |
| 802 | int limit = flag_alternateform ? va_arg(ap,int) : -1; |
| 803 | char *zMem = va_arg(ap,char*); |
| 804 |
| --- src/printf.c | |
| +++ src/printf.c | |
| @@ -774,10 +774,11 @@ | |
| 774 | char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote characters */ |
| 775 | char *escarg = va_arg(ap,char*); |
| 776 | isnull = escarg==0; |
| 777 | if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)"); |
| 778 | if( limit<0 ) limit = strlen(escarg); |
| 779 | if( precision>=0 && precision<limit ) limit = precision; |
| 780 | for(i=n=0; i<limit; i++){ |
| 781 | if( escarg[i]==q ) n++; |
| 782 | } |
| 783 | needQuote = !isnull && xtype==etSQLESCAPE2; |
| 784 | n += i + 1 + needQuote*2; |
| @@ -793,11 +794,10 @@ | |
| 794 | if( ch==q ) bufpt[j++] = ch; |
| 795 | } |
| 796 | if( needQuote ) bufpt[j++] = q; |
| 797 | bufpt[j] = 0; |
| 798 | length = j; |
| 799 | break; |
| 800 | } |
| 801 | case etHTMLIZE: { |
| 802 | int limit = flag_alternateform ? va_arg(ap,int) : -1; |
| 803 | char *zMem = va_arg(ap,char*); |
| 804 |