aboutsummaryrefslogtreecommitdiff
path: root/src/expr.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2017-01-03 00:27:16 +0000
committerdrh <drh@noemail.net>2017-01-03 00:27:16 +0000
commitb163748e885af01e6eede23fff4e7aa7e8ee3620 (patch)
tree359adb3153db6d665f2e37d361b06ce29c18f149 /src/expr.c
parent90a7eae84c2d6d67a5983e07cc84e0c7de7ec830 (diff)
downloadsqlite-b163748e885af01e6eede23fff4e7aa7e8ee3620.tar.gz
sqlite-b163748e885af01e6eede23fff4e7aa7e8ee3620.zip
Improved assert()s on the sqlite3ExprListDup() logic for TK_SELECT_COLUMN.
FossilOrigin-Name: 14da99d41f7968bf816203b4ae11c1f0d1ee0b5d
Diffstat (limited to 'src/expr.c')
-rw-r--r--src/expr.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/expr.c b/src/expr.c
index 072c42078..6d4b48fae 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -1295,6 +1295,7 @@ ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
ExprList *pNew;
struct ExprList_item *pItem, *pOldItem;
int i;
+ Expr *pPriorSelectCol = 0;
assert( db!=0 );
if( p==0 ) return 0;
pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
@@ -1311,7 +1312,6 @@ ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
Expr *pOldExpr = pOldItem->pExpr;
Expr *pNewExpr;
pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
- assert( pItem->pExpr==0 || db->mallocFailed==0 );
if( pOldExpr
&& pOldExpr->op==TK_SELECT_COLUMN
&& (pNewExpr = pItem->pExpr)!=0
@@ -1319,9 +1319,13 @@ ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
assert( pNewExpr->iColumn==0 || i>0 );
if( pNewExpr->iColumn==0 ){
assert( pOldExpr->pLeft==pOldExpr->pRight );
- pNewExpr->pLeft = pNewExpr->pRight;
- }else if( ALWAYS(pItem[-1].pExpr!=0) ){
- pNewExpr->pLeft = pItem[-1].pExpr->pLeft;
+ pPriorSelectCol = pNewExpr->pLeft = pNewExpr->pRight;
+ }else{
+ assert( i>0 );
+ assert( pItem[-1].pExpr!=0 );
+ assert( pNewExpr->iColumn==pItem[-1].pExpr->iColumn+1 );
+ assert( pPriorSelectCol==pItem[-1].pExpr->pLeft );
+ pNewExpr->pLeft = pPriorSelectCol;
}
}
pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);