diff options
author | danielk1977 <danielk1977@noemail.net> | 2007-08-30 11:48:31 +0000 |
---|---|---|
committer | danielk1977 <danielk1977@noemail.net> | 2007-08-30 11:48:31 +0000 |
commit | 7751940d6ee088b5682f4b1b0bcdd6eaaa850e9a (patch) | |
tree | d16f3df33060f317443c486078b070be9015437c /src/printf.c | |
parent | eacb6c59bc089ec465f2e1b30f8f89966c50ea40 (diff) | |
download | sqlite-7751940d6ee088b5682f4b1b0bcdd6eaaa850e9a.tar.gz sqlite-7751940d6ee088b5682f4b1b0bcdd6eaaa850e9a.zip |
Fixes for failures in fuzz_malloc.test. (CVS 4334)
FossilOrigin-Name: d3e502263808c1fe0487fda02f16adcbb1279183
Diffstat (limited to 'src/printf.c')
-rw-r--r-- | src/printf.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/printf.c b/src/printf.c index d59c8fd7f..109e3ad47 100644 --- a/src/printf.c +++ b/src/printf.c @@ -718,6 +718,7 @@ struct sgMprintf { int nTotal; /* Output size if unconstrained */ int nAlloc; /* Amount of space allocated in zText */ void *(*xRealloc)(void*,int); /* Function used to realloc memory */ + int iMallocFailed; /* True if xRealloc() has failed */ }; /* @@ -728,6 +729,7 @@ struct sgMprintf { */ static void mout(void *arg, const char *zNewText, int nNewChar){ struct sgMprintf *pM = (struct sgMprintf*)arg; + if( pM->iMallocFailed ) return; pM->nTotal += nNewChar; if( pM->zText ){ if( pM->nChar + nNewChar + 1 > pM->nAlloc ){ @@ -738,6 +740,8 @@ static void mout(void *arg, const char *zNewText, int nNewChar){ if( pM->zText==pM->zBase ){ pM->zText = pM->xRealloc(0, nAlloc); if( pM->zText==0 ){ + pM->nAlloc = 0; + pM->iMallocFailed = 0; return; }else if( pM->nChar ){ memcpy(pM->zText, pM->zBase, pM->nChar); @@ -748,8 +752,10 @@ static void mout(void *arg, const char *zNewText, int nNewChar){ if( zNew ){ pM->zText = zNew; }else{ + pM->iMallocFailed = 0; pM->xRealloc(pM->zText, 0); pM->zText = 0; + pM->nAlloc = 0; return; } } @@ -781,6 +787,7 @@ static char *base_vprintf( sM.nChar = sM.nTotal = 0; sM.nAlloc = nInitBuf; sM.xRealloc = xRealloc; + sM.iMallocFailed = 0; vxprintf(mout, &sM, useInternal, zFormat, ap); if( xRealloc ){ if( sM.zText==sM.zBase ){ |