diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/btree.c | 3 | ||||
-rw-r--r-- | src/util.c | 12 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/btree.c b/src/btree.c index aa4e28601..643d1c42d 100644 --- a/src/btree.c +++ b/src/btree.c @@ -5341,6 +5341,7 @@ static int moveToChild(BtCursor *pCur, u32 newPgno){ pCur->ix = 0; pCur->iPage++; rc = getAndInitPage(pCur->pBt, newPgno, &pCur->pPage, pCur->curPagerFlags); + assert( pCur->pPage!=0 || rc!=SQLITE_OK ); if( rc==SQLITE_OK && (pCur->pPage->nCell<1 || pCur->pPage->intKey!=pCur->curIntKey) ){ @@ -5569,7 +5570,7 @@ int sqlite3BtreeFirst(BtCursor *pCur, int *pRes){ *pRes = 0; rc = moveToLeftmost(pCur); }else if( rc==SQLITE_EMPTY ){ - assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 ); + assert( pCur->pgnoRoot==0 || (pCur->pPage!=0 && pCur->pPage->nCell==0) ); *pRes = 1; rc = SQLITE_OK; } diff --git a/src/util.c b/src/util.c index 2b5c193e3..ce0299706 100644 --- a/src/util.c +++ b/src/util.c @@ -933,6 +933,11 @@ int sqlite3Atoi(const char *z){ ** n is positive. Or round to -n signficant digits after the ** decimal point if n is negative. No rounding is performed if ** n is zero. +** +** The significant digits of the decimal representation are +** stored in p->z[] which is a often (but not always) a pointer +** into the middle of p->zBuf[]. There are p->n significant digits. +** The p->z[] array is *not* zero-terminated. */ void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){ int i; @@ -1025,14 +1030,16 @@ void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){ /* Extract significant digits. */ i = sizeof(p->zBuf)-1; + assert( v>0 ); while( v ){ p->zBuf[i--] = (v%10) + '0'; v /= 10; } - assert( i>=0 ); + assert( i>=0 && i<sizeof(p->zBuf)-1 ); p->n = sizeof(p->zBuf) - 1 - i; + assert( p->n>0 ); assert( p->n<sizeof(p->zBuf) ); p->iDP = p->n + exp; if( iRound<0 ){ iRound = p->iDP - iRound; - if( iRound==0 && p->z[i+1]>='5' ){ + if( iRound==0 && p->zBuf[i+1]>='5' ){ iRound = 1; p->zBuf[i--] = '0'; p->n++; @@ -1061,6 +1068,7 @@ void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){ } } p->z = &p->zBuf[i+1]; + assert( i+p->n < sizeof(p->zBuf) ); while( ALWAYS(p->n>0) && p->z[p->n-1]=='0' ){ p->n--; } } |