1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Changes to avoid obscure, theoretical undefined behavior. This is preventative

measures only - no actual problems observed on tested compilers.

FossilOrigin-Name: a9e819082ba19e72db03bba37edfb7702ff489a5
This commit is contained in:
drh
2015-12-07 16:43:44 +00:00
parent 28a6a1168b
commit d797a9b5cb
6 changed files with 45 additions and 42 deletions

View File

@@ -1,5 +1,5 @@
C Remove\sthe\sdependence\son\s"exec\sls\s-U"\sfrom\sthe\svtabH.test\smodule,\sas\sthe\s-U\noption\sto\s"ls"\sis\snot\suniversally\savailable.
D 2015-12-04T13:44:07.797
C Changes\sto\savoid\sobscure,\stheoretical\sundefined\sbehavior.\sThis\sis\spreventative\nmeasures\sonly\s-\sno\sactual\sproblems\sobserved\son\stested\scompilers.
D 2015-12-07T16:43:44.102
F Makefile.in 28bcd6149e050dff35d4dcfd97e890cd387a499d
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc e8fdca1cb89a1b58b5f4d3a130ea9a3d28cb314d
@@ -335,7 +335,7 @@ F src/pcache1.c 46a110be31a8d9f9b41431733836822ca0dd27ab
F src/pragma.c f3e7147299ca05ef4304a36f1fd6e002729c72c6
F src/pragma.h 3d94aebbebd2089899fecc01909bf2608b39507d
F src/prepare.c 82e5db1013846a819f198336fed72c44c974e7b1
F src/printf.c ca05561795ad6c2fa47acdd007702586282f7feb
F src/printf.c 9a9105464fbbdf84b81fb902f2eaf1f771896af1
F src/random.c ba2679f80ec82c4190062d756f22d0c358180696
F src/resolve.c a83b41104e6ff69855d03cd0aaa09e93927ec39f
F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e
@@ -349,7 +349,7 @@ F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46
F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba
F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e
F src/tclsqlite.c d9439b6a910985b7fff43ba6756bcef00de22649
F src/test1.c 4004bcc1b3b361a9137acd1d875599ecbdd6f961
F src/test1.c 90c4e80c7f4b0ad82c6dbe699c8f430b641769f5
F src/test2.c 5586f43fcd9a1be0830793cf9d354082c261b25b
F src/test3.c a8887dabbbee3059af338f20d290084a63ed1b0f
F src/test4.c d168f83cc78d02e8d35567bb5630e40dcd85ac1e
@@ -374,7 +374,7 @@ F src/test_intarray.c 870124b95ec4c645d4eb84f15efb7133528fb1a5
F src/test_intarray.h 9dc57417fb65bc7835cc18548852cc08cc062202
F src/test_journal.c 5360fbe1d1e4416ca36290562fd5a2e3f70f32aa
F src/test_loadext.c a5251f956ab6af21e138dc1f9c0399394a510cb4
F src/test_malloc.c 8e1c2112fa4f543b46c990a8872f9e6d37938744
F src/test_malloc.c 96df9381a1ff1f6d3805ff7231b9baf1386aaabf
F src/test_multiplex.c 6a088d8d9d4aad4bec45dd8878af11b15900702d
F src/test_multiplex.h c08e4e8f8651f0c5e0509b138ff4d5b43ed1f5d3
F src/test_mutex.c dbdfaff8580071f2212a0deae3325a93a737819c
@@ -408,7 +408,7 @@ F src/vdbe.c 4d75375fa8bf911aa76ab8383d6f7eea0dec0fda
F src/vdbe.h efb7a8c1459e31f3ea4377824c6a7e4cb5068637
F src/vdbeInt.h 75c2e82ee3357e9210c06474f8d9bdf12c81105d
F src/vdbeapi.c 020681b943e77766b32ae1cddf86d7831b7374ca
F src/vdbeaux.c 9a234c9aaab4ad725daf94667cfed441a437c52d
F src/vdbeaux.c f7a3e80d96e0e383bf5b636bbb770d452f52cea2
F src/vdbeblob.c fdc4a81605ae7a35ae94a55bd768b66d6be16f15
F src/vdbemem.c fdd1578e47bea61390d472de53c565781d81e045
F src/vdbesort.c a7ec02da4494c59dfd071126dd3726be5a11459d
@@ -1408,7 +1408,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 042738ad3b769ad70fd7603f928d5b94a952267d
R d4a001dfc820878042f471ef37d7e668
P 4ecbc75b465533cf80e166a9d0879b9afd3fe2be
R 52003d35f295f961555bc017c6dea8be
U drh
Z 2a98a6e0179300d3f1024c7c0c5f05bd
Z df68b9901f4a3c159da303c7427e83e3

View File

@@ -1 +1 @@
4ecbc75b465533cf80e166a9d0879b9afd3fe2be
a9e819082ba19e72db03bba37edfb7702ff489a5

View File

@@ -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{

View File

@@ -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;
}

View File

@@ -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 ){

View File

@@ -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;