mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Rewrite the (debugging use only) sqlite3VdbeMemPrettyPrint() function to use
the safer StrAccum interface rather than writing directly into a static string buffer. Perhaps this will address ticket [bbd55a97e66ff50d], which we are unable to reproduce. FossilOrigin-Name: 69f6a7e42f42116d29514239575ee1dc381b5b673da012cb5f3e8cf17922d493
This commit is contained in:
60
src/vdbe.c
60
src/vdbe.c
@@ -481,12 +481,9 @@ static u16 numericType(Mem *pMem){
|
||||
** Write a nice string representation of the contents of cell pMem
|
||||
** into buffer zBuf, length nBuf.
|
||||
*/
|
||||
void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf){
|
||||
char *zCsr = zBuf;
|
||||
void sqlite3VdbeMemPrettyPrint(Mem *pMem, StrAccum *pStr){
|
||||
int f = pMem->flags;
|
||||
|
||||
static const char *const encnames[] = {"(X)", "(8)", "(16LE)", "(16BE)"};
|
||||
|
||||
if( f&MEM_Blob ){
|
||||
int i;
|
||||
char c;
|
||||
@@ -502,57 +499,40 @@ void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf){
|
||||
}else{
|
||||
c = 's';
|
||||
}
|
||||
*(zCsr++) = c;
|
||||
*(zCsr++) = 'x';
|
||||
sqlite3_snprintf(100, zCsr, "%d[", pMem->n);
|
||||
zCsr += sqlite3Strlen30(zCsr);
|
||||
sqlite3_str_appendf(pStr, "%cx", c);
|
||||
for(i=0; i<25 && i<pMem->n; i++){
|
||||
sqlite3_snprintf(100, zCsr, "%02X", ((int)pMem->z[i] & 0xFF));
|
||||
zCsr += sqlite3Strlen30(zCsr);
|
||||
sqlite3_str_appendf(pStr, "%02X", ((int)pMem->z[i] & 0xFF));
|
||||
}
|
||||
*zCsr++ = '|';
|
||||
sqlite3_str_appendf(pStr, "|");
|
||||
for(i=0; i<25 && i<pMem->n; i++){
|
||||
char z = pMem->z[i];
|
||||
if( z<32 || z>126 ) *zCsr++ = '.';
|
||||
else *zCsr++ = z;
|
||||
sqlite3_str_appendchar(pStr, 1, (z<32||z>126)?'.':z);
|
||||
}
|
||||
*(zCsr++) = ']';
|
||||
sqlite3_str_appendf(pStr,"]");
|
||||
if( f & MEM_Zero ){
|
||||
sqlite3_snprintf(100, zCsr,"+%dz",pMem->u.nZero);
|
||||
zCsr += sqlite3Strlen30(zCsr);
|
||||
sqlite3_str_appendf(pStr, "+%dz",pMem->u.nZero);
|
||||
}
|
||||
*zCsr = '\0';
|
||||
}else if( f & MEM_Str ){
|
||||
int j, k;
|
||||
zBuf[0] = ' ';
|
||||
int j;
|
||||
int c;
|
||||
if( f & MEM_Dyn ){
|
||||
zBuf[1] = 'z';
|
||||
c = 'z';
|
||||
assert( (f & (MEM_Static|MEM_Ephem))==0 );
|
||||
}else if( f & MEM_Static ){
|
||||
zBuf[1] = 't';
|
||||
c = 't';
|
||||
assert( (f & (MEM_Dyn|MEM_Ephem))==0 );
|
||||
}else if( f & MEM_Ephem ){
|
||||
zBuf[1] = 'e';
|
||||
c = 'e';
|
||||
assert( (f & (MEM_Static|MEM_Dyn))==0 );
|
||||
}else{
|
||||
zBuf[1] = 's';
|
||||
c = 's';
|
||||
}
|
||||
k = 2;
|
||||
sqlite3_snprintf(100, &zBuf[k], "%d", pMem->n);
|
||||
k += sqlite3Strlen30(&zBuf[k]);
|
||||
zBuf[k++] = '[';
|
||||
sqlite3_str_appendf(pStr, " %c%d[", c, pMem->n);
|
||||
for(j=0; j<25 && j<pMem->n; j++){
|
||||
u8 c = pMem->z[j];
|
||||
if( c>=0x20 && c<0x7f ){
|
||||
zBuf[k++] = c;
|
||||
}else{
|
||||
zBuf[k++] = '.';
|
||||
}
|
||||
sqlite3_str_appendchar(pStr, 1, (c>=0x20&&c<=0x7f) ? c : '.');
|
||||
}
|
||||
zBuf[k++] = ']';
|
||||
sqlite3_snprintf(100,&zBuf[k], encnames[pMem->enc]);
|
||||
k += sqlite3Strlen30(&zBuf[k]);
|
||||
zBuf[k++] = 0;
|
||||
sqlite3_str_appendf(pStr, "]%s", encnames[pMem->enc]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -579,9 +559,11 @@ static void memTracePrint(Mem *p){
|
||||
}else if( sqlite3VdbeMemIsRowSet(p) ){
|
||||
printf(" (rowset)");
|
||||
}else{
|
||||
char zBuf[200];
|
||||
sqlite3VdbeMemPrettyPrint(p, zBuf);
|
||||
printf(" %s", zBuf);
|
||||
StrAccum acc;
|
||||
char zBuf[1000];
|
||||
sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
|
||||
sqlite3VdbeMemPrettyPrint(p, &acc);
|
||||
printf(" %s", sqlite3StrAccumFinish(&acc));
|
||||
}
|
||||
if( p->flags & MEM_Subtype ) printf(" subtype=0x%02x", p->eSubtype);
|
||||
}
|
||||
|
Reference in New Issue
Block a user