diff options
author | danielk1977 <danielk1977@noemail.net> | 2007-09-01 09:02:53 +0000 |
---|---|---|
committer | danielk1977 <danielk1977@noemail.net> | 2007-09-01 09:02:53 +0000 |
commit | ca0c89715e462ad7190c22c1ba30c85d077263f0 (patch) | |
tree | 0d8a87d18da3f03f45031f0ce55120fb670362b8 /src/printf.c | |
parent | 95c8a54c7d4488b5bdd6fb73196bf1463e7556e9 (diff) | |
download | sqlite-ca0c89715e462ad7190c22c1ba30c85d077263f0.tar.gz sqlite-ca0c89715e462ad7190c22c1ba30c85d077263f0.zip |
Fix a problem handling a malloc() failure in printf.c. Also some other things to improve test coverage. (CVS 4361)
FossilOrigin-Name: 595bfe72f053bc6ecb58bb9044a4cdc53d30b404
Diffstat (limited to 'src/printf.c')
-rw-r--r-- | src/printf.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/printf.c b/src/printf.c index 109e3ad47..bea91e211 100644 --- a/src/printf.c +++ b/src/printf.c @@ -741,7 +741,7 @@ static void mout(void *arg, const char *zNewText, int nNewChar){ pM->zText = pM->xRealloc(0, nAlloc); if( pM->zText==0 ){ pM->nAlloc = 0; - pM->iMallocFailed = 0; + pM->iMallocFailed = 1; return; }else if( pM->nChar ){ memcpy(pM->zText, pM->zBase, pM->nChar); @@ -752,7 +752,7 @@ static void mout(void *arg, const char *zNewText, int nNewChar){ if( zNew ){ pM->zText = zNew; }else{ - pM->iMallocFailed = 0; + pM->iMallocFailed = 1; pM->xRealloc(pM->zText, 0); pM->zText = 0; pM->nAlloc = 0; @@ -789,7 +789,8 @@ static char *base_vprintf( sM.xRealloc = xRealloc; sM.iMallocFailed = 0; vxprintf(mout, &sM, useInternal, zFormat, ap); - if( xRealloc ){ + assert(sM.iMallocFailed==0 || sM.zText==0); + if( xRealloc && !sM.iMallocFailed ){ if( sM.zText==sM.zBase ){ sM.zText = xRealloc(0, sM.nChar+1); if( sM.zText ){ |