Fix the %c format character in sqlite3VXPrintf() so that it correctly handles precisions larger than 70.

FossilOrigin-Name: 839a6df9f98b90fb593534a62145d9c913540bae
This commit is contained in:
drh 2014-11-12 14:12:28 +00:00
parent 51a205410c
commit 5a2c8c885c
5 changed files with 50 additions and 25 deletions

View File

@ -1,5 +1,5 @@
C Make\ssure\sthat\sNULL\sresults\sfrom\sOP_Column\sare\sfully\sand\scompletely\sNULL\sand\sdo\snot\shave\sthe\sMEM_Ephem\sbit\sset.\sFix\sfor\sticket\s[094d39a4c95ee4].
D 2014-11-12T14:07:28.525
C Fix\sthe\s%c\sformat\scharacter\sin\ssqlite3VXPrintf()\sso\sthat\sit\scorrectly\shandles\sprecisions\slarger\sthan\s70.
D 2014-11-12T14:12:28.051
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in cf57f673d77606ab0f2d9627ca52a9ba1464146a
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -223,7 +223,7 @@ F src/pcache.h 9b559127b83f84ff76d735c8262f04853be0c59a
F src/pcache1.c e412cb585f777c840ddce0500eddc5c6043c2bb5
F src/pragma.c 3f3e959390a10c0131676f0e307acce372777e0f
F src/prepare.c 6ef0cf2f9274982988ed6b7cab1be23147e94196
F src/printf.c 090fac0f779c93c8a95089a125339686648835e4
F src/printf.c d83b573624f3f6bc12b800af7fd55ce90be70659
F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece
F src/resolve.c a3466128b52a86c466e47ac1a19e2174f7b5cf89
F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e
@ -232,7 +232,7 @@ F src/shell.c 18ee8bbe9502d8848072dc2eddd1ea09254ba494
F src/sqlite.h.in 4a5e5158c189d2bcd45c7c4607c2c0eb6d25c153
F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad
F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d
F src/sqliteInt.h f7812f74f2d0c6041ef6b91a99c5a45f775dd408
F src/sqliteInt.h c97db3c4d20b34c050a801c93451ef18e4f22de1
F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
F src/status.c 961d5926e5a8fda611d385ec22c226b8635cd1cb
F src/table.c 2e99ef7ef16187e17033d9398dc962ce22dab5cb
@ -768,7 +768,7 @@ F test/permutations.test cef25f5e8499a15846eccd06785f17f4180407ab
F test/pragma.test 19d0241a007bcdd77fc2606ec60fc60357e7fc8b
F test/pragma2.test aea7b3d82c76034a2df2b38a13745172ddc0bc13
F test/printf.test ec9870c4dce8686a37818e0bf1aba6e6a1863552
F test/printf2.test bed79b4c3e5da08ba88ad637c0bf62586843cfb1
F test/printf2.test b4acd4bf8734243257f01ddefa17c4fb090acc8a
F test/progress.test a282973d1d17f08071bc58a77d6b80f2a81c354d
F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc
F test/queryonly.test 5f653159e0f552f0552d43259890c1089391dcca
@ -1204,8 +1204,8 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P d4b2d5d066891e06f2bf4337902b44b000fa9fd2
Q +42705fd7d892c4fdfb95fbbb468c99569beece25
R 55a6f98cd186254776492ca00fba4393
P e1017745e183f5d7429ce787ec2feef946a24f0f
Q +08a27440f19b7fc884464832e6105af1bf008172
R 3a2fc5ef3a825f22ce8bbd1b4d69c828
U drh
Z efc3d14840732f527ab6a674cff641f8
Z 3e707181121665e3dbca925048596208

View File

@ -1 +1 @@
e1017745e183f5d7429ce787ec2feef946a24f0f
839a6df9f98b90fb593534a62145d9c913540bae

View File

@ -212,7 +212,7 @@ void sqlite3VXPrintf(
const et_info *infop; /* Pointer to the appropriate info structure */
char *zOut; /* Rendering buffer */
int nOut; /* Size of the rendering buffer */
char *zExtra; /* Malloced memory used by some conversion */
char *zExtra = 0; /* Malloced memory used by some conversion */
#ifndef SQLITE_OMIT_FLOATING_POINT
int exp, e2; /* exponent of real numbers */
int nsd; /* Number of significant digits returned */
@ -329,7 +329,6 @@ void sqlite3VXPrintf(
break;
}
}
zExtra = 0;
/*
** At this point, variables are initialized as follows:
@ -620,13 +619,16 @@ void sqlite3VXPrintf(
}else{
c = va_arg(ap,int);
}
buf[0] = (char)c;
if( precision>=0 ){
for(idx=1; idx<precision; idx++) buf[idx] = (char)c;
length = precision;
}else{
length =1;
if( precision>1 ){
width -= precision-1;
if( width>1 && !flag_leftjustify ){
sqlite3AppendChar(pAccum, width-1, ' ');
width = 0;
}
sqlite3AppendChar(pAccum, precision-1, c);
}
length = 1;
buf[0] = c;
bufpt = buf;
break;
case etSTRING:
@ -727,11 +729,14 @@ void sqlite3VXPrintf(
** the output.
*/
width -= length;
if( width>0 && !flag_leftjustify ) sqlite3AppendSpace(pAccum, width);
if( width>0 && !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
sqlite3StrAccumAppend(pAccum, bufpt, length);
if( width>0 && flag_leftjustify ) sqlite3AppendSpace(pAccum, width);
if( width>0 && flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
if( zExtra ) sqlite3_free(zExtra);
if( zExtra ){
sqlite3_free(zExtra);
zExtra = 0;
}
}/* End for loop over the format string */
} /* End of function */
@ -784,11 +789,11 @@ static int sqlite3StrAccumEnlarge(StrAccum *p, int N){
}
/*
** Append N space characters to the given string buffer.
** Append N copies of character c to the given string buffer.
*/
void sqlite3AppendSpace(StrAccum *p, int N){
void sqlite3AppendChar(StrAccum *p, int N, char c){
if( p->nChar+N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ) return;
while( (N--)>0 ) p->zText[p->nChar++] = ' ';
while( (N--)>0 ) p->zText[p->nChar++] = c;
}
/*

View File

@ -3539,7 +3539,7 @@ int sqlite3OpenTempDatabase(Parse *);
void sqlite3StrAccumInit(StrAccum*, char*, int, int);
void sqlite3StrAccumAppend(StrAccum*,const char*,int);
void sqlite3StrAccumAppendAll(StrAccum*,const char*);
void sqlite3AppendSpace(StrAccum*,int);
void sqlite3AppendChar(StrAccum*,int,char);
char *sqlite3StrAccumFinish(StrAccum*);
void sqlite3StrAccumReset(StrAccum*);
void sqlite3SelectDestInit(SelectDest*,int,int);

View File

@ -95,5 +95,25 @@ do_execsql_test printf2-2.3 {
SELECT printf('%s=(%d/%g/%s)',a) FROM t1 ORDER BY a;
} {-1=(0/0/) 1=(0/0/) 1.5=(0/0/) abc=(0/0/)}
# The precision of the %c conversion causes the character to repeat.
#
do_execsql_test printf2-3.1 {
SELECT printf('|%110.100c|','*');
} {{| ****************************************************************************************************|}}
do_execsql_test printf2-3.2 {
SELECT printf('|%-110.100c|','*');
} {{|**************************************************************************************************** |}}
do_execsql_test printf2-3.3 {
SELECT printf('|%9.8c|%-9.8c|','*','*');
} {{| ********|******** |}}
do_execsql_test printf2-3.4 {
SELECT printf('|%8.8c|%-8.8c|','*','*');
} {|********|********|}
do_execsql_test printf2-3.5 {
SELECT printf('|%7.8c|%-7.8c|','*','*');
} {|********|********|}
finish_test