aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2015-12-07 16:43:44 +0000
committerdrh <drh@noemail.net>2015-12-07 16:43:44 +0000
commitd797a9b5cb22e248015aabf0148ca544a7a7da3d (patch)
tree9c051f51b0faaed76653b3a2b2f90a3756ab4610 /src
parent28a6a1168b8352161035a10c8c459eae77187657 (diff)
downloadsqlite-d797a9b5cb22e248015aabf0148ca544a7a7da3d.tar.gz
sqlite-d797a9b5cb22e248015aabf0148ca544a7a7da3d.zip
Changes to avoid obscure, theoretical undefined behavior. This is preventative
measures only - no actual problems observed on tested compilers. FossilOrigin-Name: a9e819082ba19e72db03bba37edfb7702ff489a5
Diffstat (limited to 'src')
-rw-r--r--src/printf.c2
-rw-r--r--src/test1.c4
-rw-r--r--src/test_malloc.c3
-rw-r--r--src/vdbeaux.c58
4 files changed, 35 insertions, 32 deletions
diff --git a/src/printf.c b/src/printf.c
index 88bb82e3e..e34ddd3bd 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -788,7 +788,7 @@ static int sqlite3StrAccumEnlarge(StrAccum *p, int N){
}
if( zNew ){
assert( p->zText!=0 || p->nChar==0 );
- if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
+ if( p->zText==p->zBase && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
p->zText = zNew;
p->nAlloc = sqlite3DbMallocSize(p->db, zNew);
}else{
diff --git a/src/test1.c b/src/test1.c
index 186e4e468..b8154a64f 100644
--- a/src/test1.c
+++ b/src/test1.c
@@ -5906,13 +5906,13 @@ static int test_sqlite3_log(
Tcl_DecrRefCount(logcallback.pObj);
logcallback.pObj = 0;
logcallback.pInterp = 0;
- sqlite3_config(SQLITE_CONFIG_LOG, 0, 0);
+ sqlite3_config(SQLITE_CONFIG_LOG, (void*)0, (void*)0);
}
if( objc>1 ){
logcallback.pObj = objv[1];
Tcl_IncrRefCount(logcallback.pObj);
logcallback.pInterp = interp;
- sqlite3_config(SQLITE_CONFIG_LOG, xLogcallback, 0);
+ sqlite3_config(SQLITE_CONFIG_LOG, xLogcallback, (void*)0);
}
return TCL_OK;
}
diff --git a/src/test_malloc.c b/src/test_malloc.c
index a3ff9d205..aaa640b03 100644
--- a/src/test_malloc.c
+++ b/src/test_malloc.c
@@ -222,7 +222,8 @@ static int faultsimInstall(int install){
assert( memcmp(&m2, &memfault.m, sizeof(m2))==0 );
rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &memfault.m);
- sqlite3_test_control(SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS, 0, 0);
+ sqlite3_test_control(SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,
+ (void*)0, (void*)0);
}
if( rc==SQLITE_OK ){
diff --git a/src/vdbeaux.c b/src/vdbeaux.c
index 1889aec79..acf386428 100644
--- a/src/vdbeaux.c
+++ b/src/vdbeaux.c
@@ -1725,30 +1725,31 @@ void sqlite3VdbeIOTraceSql(Vdbe *p){
**
** nByte is the number of bytes of space needed.
**
-** *ppFrom points to available space and pEnd points to the end of the
-** available space. When space is allocated, *ppFrom is advanced past
-** the end of the allocated space.
+** pFrom points to *pnFrom bytes of available space. New space is allocated
+** from the end of the pFrom buffer and *pnFrom is decremented.
**
-** *pnByte is a counter of the number of bytes of space that have failed
-** to allocate. If there is insufficient space in *ppFrom to satisfy the
-** request, then increment *pnByte by the amount of the request.
+** *pnNeeded is a counter of the number of bytes of space that have failed
+** to allocate. If there is insufficient space in pFrom to satisfy the
+** request, then increment *pnNeeded by the amount of the request.
*/
static void *allocSpace(
void *pBuf, /* Where return pointer will be stored */
int nByte, /* Number of bytes to allocate */
- u8 **ppFrom, /* IN/OUT: Allocate from *ppFrom */
- u8 *pEnd, /* Pointer to 1 byte past the end of *ppFrom buffer */
- int *pnByte /* If allocation cannot be made, increment *pnByte */
+ u8 *pFrom, /* Memory available for allocation */
+ int *pnFrom, /* IN/OUT: Space available at pFrom */
+ int *pnNeeded /* If allocation cannot be made, increment *pnByte */
){
- assert( EIGHT_BYTE_ALIGNMENT(*ppFrom) );
- if( pBuf ) return pBuf;
- nByte = ROUND8(nByte);
- if( &(*ppFrom)[nByte] <= pEnd ){
- pBuf = (void*)*ppFrom;
- *ppFrom += nByte;
- }else{
- *pnByte += nByte;
+ assert( EIGHT_BYTE_ALIGNMENT(pFrom) );
+ if( pBuf==0 ){
+ nByte = ROUND8(nByte);
+ if( nByte <= *pnFrom ){
+ *pnFrom -= nByte;
+ pBuf = &pFrom[*pnFrom];
+ }else{
+ *pnNeeded += nByte;
+ }
}
+ assert( EIGHT_BYTE_ALIGNMENT(pBuf) );
return pBuf;
}
@@ -1821,8 +1822,8 @@ void sqlite3VdbeMakeReady(
int nArg; /* Number of arguments in subprograms */
int nOnce; /* Number of OP_Once instructions */
int n; /* Loop counter */
+ int nFree; /* Available free space */
u8 *zCsr; /* Memory available for allocation */
- u8 *zEnd; /* First byte past allocated memory */
int nByte; /* How much extra memory is needed */
assert( p!=0 );
@@ -1854,14 +1855,15 @@ void sqlite3VdbeMakeReady(
** an array to marshal SQL function arguments in.
*/
zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */
- zEnd = (u8*)&p->aOp[pParse->nOpAlloc]; /* First byte past end of zCsr[] */
+ assert( pParse->nOpAlloc*sizeof(Op) <= 0x7fffff00 );
+ nFree = (pParse->nOpAlloc - p->nOp)*sizeof(p->aOp[0]); /* Available space */
resolveP2Values(p, &nArg);
p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
if( pParse->explain && nMem<10 ){
nMem = 10;
}
- memset(zCsr, 0, zEnd-zCsr);
+ memset(zCsr, 0, nFree);
zCsr += (zCsr - (u8*)0)&7;
assert( EIGHT_BYTE_ALIGNMENT(zCsr) );
p->expired = 0;
@@ -1878,21 +1880,21 @@ void sqlite3VdbeMakeReady(
*/
do {
nByte = 0;
- p->aMem = allocSpace(p->aMem, nMem*sizeof(Mem), &zCsr, zEnd, &nByte);
- p->aVar = allocSpace(p->aVar, nVar*sizeof(Mem), &zCsr, zEnd, &nByte);
- p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte);
- p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte);
+ p->aMem = allocSpace(p->aMem, nMem*sizeof(Mem), zCsr, &nFree, &nByte);
+ p->aVar = allocSpace(p->aVar, nVar*sizeof(Mem), zCsr, &nFree, &nByte);
+ p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), zCsr, &nFree, &nByte);
+ p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), zCsr, &nFree, &nByte);
p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*),
- &zCsr, zEnd, &nByte);
- p->aOnceFlag = allocSpace(p->aOnceFlag, nOnce, &zCsr, zEnd, &nByte);
+ zCsr, &nFree, &nByte);
+ p->aOnceFlag = allocSpace(p->aOnceFlag, nOnce, zCsr, &nFree, &nByte);
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
- p->anExec = allocSpace(p->anExec, p->nOp*sizeof(i64), &zCsr, zEnd, &nByte);
+ p->anExec = allocSpace(p->anExec, p->nOp*sizeof(i64), zCsr, &nFree, &nByte);
#endif
if( nByte ){
p->pFree = sqlite3DbMallocZero(db, nByte);
}
zCsr = p->pFree;
- zEnd = &zCsr[nByte];
+ nFree = nByte;
}while( nByte && !db->mallocFailed );
p->nCursor = nCursor;