1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-06 15:49:35 +03:00

Simplified array allocation in the IdList and AggInfo objects.

FossilOrigin-Name: 25df2a7458d025bc00380b4a0893637639f9f0d4
This commit is contained in:
drh
2012-02-02 03:38:30 +00:00
parent a3cc3c9616
commit 6c5351589c
5 changed files with 20 additions and 31 deletions

View File

@@ -1,5 +1,5 @@
C Fix\sa\spossible\ssegfault\safter\san\sOOM\sfault.\s\sThis\shas\sbeen\sin\sthe\scode\sfor\sages\nbut\sonly\sexpressed\sitself\sfollowing\sthe\sprevious\scheck-in. C Simplified\sarray\sallocation\sin\sthe\sIdList\sand\sAggInfo\sobjects.
D 2012-02-02T03:11:40.324 D 2012-02-02T03:38:30.479
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 3f79a373e57c3b92dabf76f40b065e719d31ac34 F Makefile.in 3f79a373e57c3b92dabf76f40b065e719d31ac34
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -128,13 +128,13 @@ F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
F src/btree.c 24bde768288b3365bc6acfbb24030f76fefe7e1f F src/btree.c 24bde768288b3365bc6acfbb24030f76fefe7e1f
F src/btree.h 46e9f04672f1390255bc56865a3238b384d0f2d5 F src/btree.h 46e9f04672f1390255bc56865a3238b384d0f2d5
F src/btreeInt.h 6c9960645c431c9456ca56498f43a2b3bf1fa8c2 F src/btreeInt.h 6c9960645c431c9456ca56498f43a2b3bf1fa8c2
F src/build.c 8e2a4dedad860fed982270ef43968505f35ec57f F src/build.c 7a03d1772f906ca1ba905858b4f19d4d8b34e59d
F src/callback.c 0425c6320730e6d3981acfb9202c1bed9016ad1a F src/callback.c 0425c6320730e6d3981acfb9202c1bed9016ad1a
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
F src/ctime.c a9c26822515f81ec21588cbb482ca6724be02e33 F src/ctime.c a9c26822515f81ec21588cbb482ca6724be02e33
F src/date.c 067a81c9942c497aafd2c260e13add8a7d0c7dd4 F src/date.c 067a81c9942c497aafd2c260e13add8a7d0c7dd4
F src/delete.c 51d32f0a9c880663e54ce309f52e40c325d5e112 F src/delete.c 51d32f0a9c880663e54ce309f52e40c325d5e112
F src/expr.c d644aac3409c67c9a9bcf9d5098641b18b47d925 F src/expr.c 00675123e0beec98f999aa4594d2cbe1fec33c1b
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
F src/fkey.c 657212460bf5cfd3ae607d12ea62092844c227b5 F src/fkey.c 657212460bf5cfd3ae607d12ea62092844c227b5
F src/func.c 6261ce00aad9c63cd5b4219249b05683979060e9 F src/func.c 6261ce00aad9c63cd5b4219249b05683979060e9
@@ -184,7 +184,7 @@ F src/select.c b6eec9d11ec5df0d1fd11e8a0eed0fc2d2d96b25
F src/shell.c 60d147c2411dd2d79a5151cfb9a068de87c7babe F src/shell.c 60d147c2411dd2d79a5151cfb9a068de87c7babe
F src/sqlite.h.in 371c30e4be94b9b0ea6400ed66663fcf8e891eb4 F src/sqlite.h.in 371c30e4be94b9b0ea6400ed66663fcf8e891eb4
F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477 F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477
F src/sqliteInt.h f6b1d14dbabf8bc86f7d48da64c1ed881c747eb8 F src/sqliteInt.h e4275be35f82b3da4734d0d8eb97c618a91bb1a1
F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
F src/status.c 4568e72dfd36b6a5911f93457364deb072e0b03a F src/status.c 4568e72dfd36b6a5911f93457364deb072e0b03a
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
@@ -988,7 +988,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
P 5963de303a9106b446a9423aa838bfdf6bc1e7f3 P a3553b8a035b70e76a5a325b9e9f379f84de3955
R 850cb01b34139b6ff5ae22e6f4202f6f R 0dee572dcbe8f4a7b8dff88e26875d80
U drh U drh
Z ef5893d9871699934600cb710a85a051 Z 566ebf07e0f933f12b6e71767840fbdb

View File

@@ -1 +1 @@
a3553b8a035b70e76a5a325b9e9f379f84de3955 25df2a7458d025bc00380b4a0893637639f9f0d4

View File

@@ -3059,27 +3059,23 @@ void *sqlite3ArrayAllocate(
sqlite3 *db, /* Connection to notify of malloc failures */ sqlite3 *db, /* Connection to notify of malloc failures */
void *pArray, /* Array of objects. Might be reallocated */ void *pArray, /* Array of objects. Might be reallocated */
int szEntry, /* Size of each object in the array */ int szEntry, /* Size of each object in the array */
int initSize, /* Suggested initial allocation, in elements */
int *pnEntry, /* Number of objects currently in use */ int *pnEntry, /* Number of objects currently in use */
int *pnAlloc, /* Current size of the allocation, in elements */
int *pIdx /* Write the index of a new slot here */ int *pIdx /* Write the index of a new slot here */
){ ){
char *z; char *z;
if( *pnEntry >= *pnAlloc ){ int n = *pnEntry;
void *pNew; if( (n & (n-1))==0 ){
int newSize; int sz = (n==0) ? 1 : 2*n;
newSize = (*pnAlloc)*2 + initSize; void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry);
pNew = sqlite3DbRealloc(db, pArray, newSize*szEntry);
if( pNew==0 ){ if( pNew==0 ){
*pIdx = -1; *pIdx = -1;
return pArray; return pArray;
} }
*pnAlloc = sqlite3DbMallocSize(db, pNew)/szEntry;
pArray = pNew; pArray = pNew;
} }
z = (char*)pArray; z = (char*)pArray;
memset(&z[*pnEntry * szEntry], 0, szEntry); memset(&z[n * szEntry], 0, szEntry);
*pIdx = *pnEntry; *pIdx = n;
++*pnEntry; ++*pnEntry;
return pArray; return pArray;
} }
@@ -3095,15 +3091,12 @@ IdList *sqlite3IdListAppend(sqlite3 *db, IdList *pList, Token *pToken){
if( pList==0 ){ if( pList==0 ){
pList = sqlite3DbMallocZero(db, sizeof(IdList) ); pList = sqlite3DbMallocZero(db, sizeof(IdList) );
if( pList==0 ) return 0; if( pList==0 ) return 0;
pList->nAlloc = 0;
} }
pList->a = sqlite3ArrayAllocate( pList->a = sqlite3ArrayAllocate(
db, db,
pList->a, pList->a,
sizeof(pList->a[0]), sizeof(pList->a[0]),
5,
&pList->nId, &pList->nId,
&pList->nAlloc,
&i &i
); );
if( i<0 ){ if( i<0 ){

View File

@@ -926,12 +926,15 @@ IdList *sqlite3IdListDup(sqlite3 *db, IdList *p){
if( p==0 ) return 0; if( p==0 ) return 0;
pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) ); pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
if( pNew==0 ) return 0; if( pNew==0 ) return 0;
pNew->nId = pNew->nAlloc = p->nId; pNew->nId = p->nId;
pNew->a = sqlite3DbMallocRaw(db, p->nId*sizeof(p->a[0]) ); pNew->a = sqlite3DbMallocRaw(db, p->nId*sizeof(p->a[0]) );
if( pNew->a==0 ){ if( pNew->a==0 ){
sqlite3DbFree(db, pNew); sqlite3DbFree(db, pNew);
return 0; return 0;
} }
/* Note that because the size of the allocation for p->a[] is not
** necessarily a power of two, sqlite3IdListAppend() may not be called
** on the duplicate created by this function. */
for(i=0; i<p->nId; i++){ for(i=0; i<p->nId; i++){
struct IdList_item *pNewItem = &pNew->a[i]; struct IdList_item *pNewItem = &pNew->a[i];
struct IdList_item *pOldItem = &p->a[i]; struct IdList_item *pOldItem = &p->a[i];
@@ -3774,9 +3777,7 @@ static int addAggInfoColumn(sqlite3 *db, AggInfo *pInfo){
db, db,
pInfo->aCol, pInfo->aCol,
sizeof(pInfo->aCol[0]), sizeof(pInfo->aCol[0]),
3,
&pInfo->nColumn, &pInfo->nColumn,
&pInfo->nColumnAlloc,
&i &i
); );
return i; return i;
@@ -3792,9 +3793,7 @@ static int addAggInfoFunc(sqlite3 *db, AggInfo *pInfo){
db, db,
pInfo->aFunc, pInfo->aFunc,
sizeof(pInfo->aFunc[0]), sizeof(pInfo->aFunc[0]),
3,
&pInfo->nFunc, &pInfo->nFunc,
&pInfo->nFuncAlloc,
&i &i
); );
return i; return i;

View File

@@ -1567,7 +1567,6 @@ struct AggInfo {
Expr *pExpr; /* The original expression */ Expr *pExpr; /* The original expression */
} *aCol; } *aCol;
int nColumn; /* Number of used entries in aCol[] */ int nColumn; /* Number of used entries in aCol[] */
int nColumnAlloc; /* Number of slots allocated for aCol[] */
int nAccumulator; /* Number of columns that show through to the output. int nAccumulator; /* Number of columns that show through to the output.
** Additional columns are used only as parameters to ** Additional columns are used only as parameters to
** aggregate functions */ ** aggregate functions */
@@ -1578,7 +1577,6 @@ struct AggInfo {
int iDistinct; /* Ephemeral table used to enforce DISTINCT */ int iDistinct; /* Ephemeral table used to enforce DISTINCT */
} *aFunc; } *aFunc;
int nFunc; /* Number of entries in aFunc[] */ int nFunc; /* Number of entries in aFunc[] */
int nFuncAlloc; /* Number of slots allocated for aFunc[] */
}; };
/* /*
@@ -1819,7 +1817,6 @@ struct IdList {
int idx; /* Index in some Table.aCol[] of a column named zName */ int idx; /* Index in some Table.aCol[] of a column named zName */
} *a; } *a;
int nId; /* Number of identifiers on the list */ int nId; /* Number of identifiers on the list */
int nAlloc; /* Number of entries allocated for a[] below */
}; };
/* /*
@@ -2762,7 +2759,7 @@ void sqlite3DeleteTable(sqlite3*, Table*);
# define sqlite3AutoincrementEnd(X) # define sqlite3AutoincrementEnd(X)
#endif #endif
void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int); void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
void *sqlite3ArrayAllocate(sqlite3*,void*,int,int,int*,int*,int*); void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*);
IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*); IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
int sqlite3IdListIndex(IdList*,const char*); int sqlite3IdListIndex(IdList*,const char*);
SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int); SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);