1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

In the printf() library, measure width and precision in characters rather

than bytes if the "!" (alternate-form-2) flag is present on a %s or %z
substitution.

FossilOrigin-Name: ca31c6630422fca70e626dd38aae96296bd8535d491ca52391624a5e7e663636
This commit is contained in:
drh
2018-02-19 17:03:23 +00:00
parent 26f625fbf4
commit 62856465f2
3 changed files with 31 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
C Only\stry\sto\suse\sthe\sgeteuid()\sinterface\son\sunix\sif\sHAVE_FCHOWN\sis\sdefined.\nThis\sfixes\sthe\sbuild\sfor\svxWorks,\swe\sare\stold. C In\sthe\sprintf()\slibrary,\smeasure\swidth\sand\sprecision\sin\scharacters\srather\nthan\sbytes\sif\sthe\s"!"\s(alternate-form-2)\sflag\sis\spresent\son\sa\s%s\sor\s%z\nsubstitution.
D 2018-02-19T16:34:31.891 D 2018-02-19T17:03:23.575
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in 7a3f714b4fcf793108042b7b0a5c720b0b310ec84314d61ba7f3f49f27e550ea F Makefile.in 7a3f714b4fcf793108042b7b0a5c720b0b310ec84314d61ba7f3f49f27e550ea
@@ -484,7 +484,7 @@ F src/pcache1.c 716975564c15eb6679e97f734cec1bfd6c16ac3d4010f05f1f8e509fc7d19880
F src/pragma.c bea56df3ae0637768c0da4fbbb8f2492f780980d95000034a105ff291bf7ca69 F src/pragma.c bea56df3ae0637768c0da4fbbb8f2492f780980d95000034a105ff291bf7ca69
F src/pragma.h bb83728944b42f6d409c77f5838a8edbdb0fe83046c5496ffc9602b40340a324 F src/pragma.h bb83728944b42f6d409c77f5838a8edbdb0fe83046c5496ffc9602b40340a324
F src/prepare.c 259f4e7960c47082c9653f3d5f0c294abd68bb9c3aab86de7630700cba1c20fb F src/prepare.c 259f4e7960c47082c9653f3d5f0c294abd68bb9c3aab86de7630700cba1c20fb
F src/printf.c 9506b4b96e59c0467047155f09015750cb2878aeda3d39e5610c1192ddc3c41c F src/printf.c a94897345b3228d97c6aa06297890b7c62bc47acc86e34d3634d125426d78695
F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
F src/resolve.c bbee7e31d369a18a2f4836644769882e9c5d40ef4a3af911db06410b65cb3730 F src/resolve.c bbee7e31d369a18a2f4836644769882e9c5d40ef4a3af911db06410b65cb3730
F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
@@ -1707,7 +1707,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 88258770adead70fa101c74e266a37bb9aaffac0ba738a4b345617feb8c46477 P 38f654dc117bb11d61407327884b5c913cfaf920547bebc4ce5a4cf983e5c20e
R 2e4bdb0c045376ff7154d29ff239bf61 R 07cd50bae7c4080dd411c728ce9cf3a0
T *branch * printf-enhancement
T *sym-printf-enhancement *
T -sym-trunk *
U drh U drh
Z 37b9f8fa92af1d03e78cb9f20faaf7e7 Z 9d6ee38fe0b61a32cc5a7309de027572

View File

@@ -1 +1 @@
38f654dc117bb11d61407327884b5c913cfaf920547bebc4ce5a4cf983e5c20e ca31c6630422fca70e626dd38aae96296bd8535d491ca52391624a5e7e663636

View File

@@ -654,10 +654,25 @@ void sqlite3VXPrintf(
zExtra = bufpt; zExtra = bufpt;
} }
if( precision>=0 ){ if( precision>=0 ){
if( flag_altform2 ){
/* Set length to the number of bytes needed in order to display
** precision characters */
unsigned char *z = (unsigned char*)bufpt;
while( precision-- > 0 && z[0] ){
SQLITE_SKIP_UTF8(z);
}
length = (int)(z - (unsigned char*)bufpt);
}else{
for(length=0; length<precision && bufpt[length]; length++){} for(length=0; length<precision && bufpt[length]; length++){}
}
}else{ }else{
length = 0x7fffffff & (int)strlen(bufpt); length = 0x7fffffff & (int)strlen(bufpt);
} }
if( flag_altform2 && width>0 ){
/* Adjust width to account for extra bytes in UTF-8 characters */
int ii = length - 1;
while( ii>=0 ) if( (bufpt[ii--] & 0xc0)==0x80 ) width++;
}
break; break;
case etSQLESCAPE: /* Escape ' characters */ case etSQLESCAPE: /* Escape ' characters */
case etSQLESCAPE2: /* Escape ' and enclose in '...' */ case etSQLESCAPE2: /* Escape ' and enclose in '...' */
@@ -700,7 +715,7 @@ void sqlite3VXPrintf(
if( needQuote ) bufpt[j++] = q; if( needQuote ) bufpt[j++] = q;
bufpt[j] = 0; bufpt[j] = 0;
length = j; length = j;
/* The precision in %q and %Q means how many input characters to /* The precision in %q and %Q means how many input bytes to
** consume, not the length of the output... ** consume, not the length of the output...
** if( precision>=0 && precision<length ) length = precision; */ ** if( precision>=0 && precision<length ) length = precision; */
break; break;
@@ -742,7 +757,10 @@ void sqlite3VXPrintf(
/* /*
** The text of the conversion is pointed to by "bufpt" and is ** The text of the conversion is pointed to by "bufpt" and is
** "length" characters long. The field width is "width". Do ** "length" characters long. The field width is "width". Do
** the output. ** the output. Both length and width are in bytes, not characters,
** at this point. If the "!" flag was present on string conversions
** indicating that width and precision should be expressed in characters,
** then the values have been translated prior to reaching this point.
*/ */
width -= length; width -= length;
if( width>0 ){ if( width>0 ){