-C Fix\sa\sbuffer-overflow\sproblem\sin\sthe\srandStr\sfunction\s(used\sonly\sfor\stesting).\s(CVS\s1182)
-D 2004-01-16T13:58:18
+C Incremental\scode\scompaction\sin\sexpr.c.\s\sNow\sabout\s4%\ssmaller.\nLots\smore\swork\sto\sdo.\s(CVS\s1183)
+D 2004-01-16T15:55:38
F Makefile.in 0515ff9218ad8d5a8f6220f0494b8ef94c67013b
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
F src/date.c bb89fdb9c89e367b9a728c58cb96e4823974a2c1
F src/delete.c 0f81e6799c089487615d38e042a2de4d2d6192bc
F src/encode.c 9e70ea1e4e746f23f18180949e94f1bb1c2220d3
-F src/expr.c 866a6d7aacc2825aa13056ccbea1a16f436a1ca5
+F src/expr.c 5ecbce47b7f163bb1f64bc5e19fbb115ab468f98
F src/func.c 564c0bbe93c290774b305c0199237b8e8bcbda53
F src/hash.c 9b56ef3b291e25168f630d5643a4264ec011c70e
F src/hash.h 3247573ab95b9dd90bcca0307a75d9a16da1ccc7
F src/select.c 2712bd4d311ebe7dbf8fd7596a809042657db85f
F src/shell.c 3b067edc098c45caca164bcad1fa79192c3ec5ae
F src/sqlite.h.in c70d8533cd5a5ae8af580597dbc726693ef82de9
-F src/sqliteInt.h 99df38d3c16cc727030c218a3fc61de08c071d08
+F src/sqliteInt.h c5b727d5d07b88654c204c0fc1ae79c9f635a008
F src/table.c d845cb101b5afc1f7fea083c99e3d2fa7998d895
F src/tclsqlite.c 85810fc4a850e2178d71aa5efe576dcd331db596
F src/test1.c e8652055d04d241d4fb437b5c33ff07d9f13b4b4
F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
-P 5e85025be7aa4a03b0cfb4d0f28a2e44653b9d3f
-R aaef1a0aff5b12b7d4f36cc6a72499f1
+P 42c79edc2e8d1051b3bca915b4b205c601b8077f
+R 36f16e7773dddd52ae0de77fcf909446
U drh
-Z ebbe741602d66e22ec8fa796a8084911
+Z 7d1bc38e295a20482fad97622944af0e
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
-** $Id: expr.c,v 1.104 2004/01/14 03:12:42 drh Exp $
+** $Id: expr.c,v 1.105 2004/01/16 15:55:38 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
Expr *pNew;
pNew = sqliteMalloc( sizeof(Expr) );
if( pNew==0 ){
- sqliteExprDelete(pLeft);
- sqliteExprDelete(pRight);
+ /* When malloc fails, we leak memory from pLeft and pRight */
return 0;
}
pNew->op = op;
pNew->token = *pToken;
pNew->span = *pToken;
}else{
- pNew->token.dyn = 0;
- pNew->token.z = 0;
- pNew->token.n = 0;
+ assert( pNew->token.dyn==0 );
+ assert( pNew->token.z==0 );
+ assert( pNew->token.n==0 );
if( pLeft && pRight ){
sqliteExprSpan(pNew, &pLeft->span, &pRight->span);
}else{
** text between the two given tokens.
*/
void sqliteExprSpan(Expr *pExpr, Token *pLeft, Token *pRight){
- if( pExpr && pRight && pRight->z && pLeft && pLeft->z ){
+ assert( pRight!=0 );
+ assert( pLeft!=0 );
+ /* Note: pExpr might be NULL due to a prior malloc failure */
+ if( pExpr && pRight->z && pLeft->z ){
if( pLeft->dyn==0 && pRight->dyn==0 ){
pExpr->span.z = pLeft->z;
pExpr->span.n = pRight->n + Addr(pRight->z) - Addr(pLeft->z);
}else{
pExpr->span.z = 0;
- pExpr->span.n = 0;
- pExpr->span.dyn = 0;
}
}
}
Expr *pNew;
pNew = sqliteMalloc( sizeof(Expr) );
if( pNew==0 ){
- sqliteExprListDelete(pList);
+ /* sqliteExprListDelete(pList); // Leak pList when malloc fails */
return 0;
}
pNew->op = TK_FUNCTION;
pNew->pList = pList;
- pNew->token.dyn = 0;
if( pToken ){
assert( pToken->dyn==0 );
pNew->token = *pToken;
}else{
pNew->token.z = 0;
- pNew->token.n = 0;
}
pNew->span = pNew->token;
return pNew;
*/
void sqliteExprDelete(Expr *p){
if( p==0 ) return;
- if( p->span.dyn && p->span.z ) sqliteFree((char*)p->span.z);
- if( p->token.dyn && p->token.z ) sqliteFree((char*)p->token.z);
- if( p->pLeft ) sqliteExprDelete(p->pLeft);
- if( p->pRight ) sqliteExprDelete(p->pRight);
- if( p->pList ) sqliteExprListDelete(p->pList);
- if( p->pSelect ) sqliteSelectDelete(p->pSelect);
+ if( p->span.dyn ) sqliteFree((char*)p->span.z);
+ if( p->token.dyn ) sqliteFree((char*)p->token.z);
+ sqliteExprDelete(p->pLeft);
+ sqliteExprDelete(p->pRight);
+ sqliteExprListDelete(p->pList);
+ sqliteSelectDelete(p->pSelect);
sqliteFree(p);
}
pNew->token.z = sqliteStrDup(p->token.z);
pNew->token.dyn = 1;
}else{
- pNew->token.z = 0;
- pNew->token.n = 0;
- pNew->token.dyn = 0;
+ assert( pNew->token.z==0 );
}
pNew->span.z = 0;
- pNew->span.n = 0;
- pNew->span.dyn = 0;
pNew->pLeft = sqliteExprDup(p->pLeft);
pNew->pRight = sqliteExprDup(p->pRight);
pNew->pList = sqliteExprListDup(p->pList);
pTo->z = sqliteStrNDup(pFrom->z, pFrom->n);
pTo->dyn = 1;
}else{
- pTo->n = 0;
pTo->z = 0;
- pTo->dyn = 0;
}
}
ExprList *sqliteExprListDup(ExprList *p){
int nByte;
if( p==0 ) return 0;
nByte = sizeof(*p) + (p->nSrc>0 ? sizeof(p->a[0]) * (p->nSrc-1) : 0);
- pNew = sqliteMalloc( nByte );
+ pNew = sqliteMallocRaw( nByte );
if( pNew==0 ) return 0;
pNew->nSrc = pNew->nAlloc = p->nSrc;
for(i=0; i<p->nSrc; i++){
- pNew->a[i].zDatabase = sqliteStrDup(p->a[i].zDatabase);
- pNew->a[i].zName = sqliteStrDup(p->a[i].zName);
- pNew->a[i].zAlias = sqliteStrDup(p->a[i].zAlias);
- pNew->a[i].jointype = p->a[i].jointype;
- pNew->a[i].iCursor = p->a[i].iCursor;
- pNew->a[i].pTab = 0;
- pNew->a[i].pSelect = sqliteSelectDup(p->a[i].pSelect);
- pNew->a[i].pOn = sqliteExprDup(p->a[i].pOn);
- pNew->a[i].pUsing = sqliteIdListDup(p->a[i].pUsing);
+ struct SrcList_item *pNewItem = &pNew->a[i];
+ struct SrcList_item *pOldItem = &p->a[i];
+ pNewItem->zDatabase = sqliteStrDup(pOldItem->zDatabase);
+ pNewItem->zName = sqliteStrDup(pOldItem->zName);
+ pNewItem->zAlias = sqliteStrDup(pOldItem->zAlias);
+ pNewItem->jointype = pOldItem->jointype;
+ pNewItem->iCursor = pOldItem->iCursor;
+ pNewItem->pTab = 0;
+ pNewItem->pSelect = sqliteSelectDup(pOldItem->pSelect);
+ pNewItem->pOn = sqliteExprDup(pOldItem->pOn);
+ pNewItem->pUsing = sqliteIdListDup(pOldItem->pUsing);
}
return pNew;
}
IdList *pNew;
int i;
if( p==0 ) return 0;
- pNew = sqliteMalloc( sizeof(*pNew) );
+ pNew = sqliteMallocRaw( sizeof(*pNew) );
if( pNew==0 ) return 0;
pNew->nId = pNew->nAlloc = p->nId;
- pNew->a = sqliteMalloc( p->nId*sizeof(p->a[0]) );
+ pNew->a = sqliteMallocRaw( p->nId*sizeof(p->a[0]) );
if( pNew->a==0 ) return 0;
for(i=0; i<p->nId; i++){
- pNew->a[i].zName = sqliteStrDup(p->a[i].zName);
- pNew->a[i].idx = p->a[i].idx;
+ struct IdList_item *pNewItem = &pNew->a[i];
+ struct IdList_item *pOldItem = &p->a[i];
+ pNewItem->zName = sqliteStrDup(pOldItem->zName);
+ pNewItem->idx = pOldItem->idx;
}
return pNew;
}
Select *sqliteSelectDup(Select *p){
Select *pNew;
if( p==0 ) return 0;
- pNew = sqliteMalloc( sizeof(*p) );
+ pNew = sqliteMallocRaw( sizeof(*p) );
if( pNew==0 ) return 0;
pNew->isDistinct = p->isDistinct;
pNew->pEList = sqliteExprListDup(p->pEList);
if( pList==0 ){
pList = sqliteMalloc( sizeof(ExprList) );
if( pList==0 ){
- sqliteExprDelete(pExpr);
+ /* sqliteExprDelete(pExpr); // Leak memory if malloc fails */
return 0;
}
- pList->nAlloc = 0;
+ assert( pList->nAlloc==0 );
}
if( pList->nAlloc<=pList->nExpr ){
- struct ExprList_item *a;
pList->nAlloc = pList->nAlloc*2 + 4;
- a = sqliteRealloc(pList->a, pList->nAlloc*sizeof(pList->a[0]));
- if( a==0 ){
- sqliteExprDelete(pExpr);
+ pList->a = sqliteRealloc(pList->a, pList->nAlloc*sizeof(pList->a[0]));
+ if( pList->a==0 ){
+ /* sqliteExprDelete(pExpr); // Leak memory if malloc fails */
+ pList->nExpr = pList->nAlloc = 0;
return pList;
}
- pList->a = a;
}
- if( pList->a && (pExpr || pName) ){
- i = pList->nExpr++;
- memset(&pList->a[i], 0, sizeof(pList->a[i]));
- pList->a[i].pExpr = pExpr;
+ assert( pList->a!=0 );
+ if( pExpr || pName ){
+ struct ExprList_item *pItem = &pList->a[pList->nExpr++];
+ memset(pItem, 0, sizeof(*pItem));
+ pItem->pExpr = pExpr;
if( pName ){
- sqliteSetNString(&pList->a[i].zName, pName->z, pName->n, 0);
- sqliteDequote(pList->a[i].zName);
+ sqliteSetNString(&pItem->zName, pName->z, pName->n, 0);
+ sqliteDequote(pItem->zName);
}
}
return pList;