Index: src/alter.c ================================================================== --- src/alter.c +++ src/alter.c @@ -1414,11 +1414,12 @@ */ static int renameTableSelectCb(Walker *pWalker, Select *pSelect){ int i; RenameCtx *p = pWalker->u.pRename; SrcList *pSrc = pSelect->pSrc; - if( NEVER(pSrc==0) ){ + if( pSrc==0 ){ + assert( pWalker->pParse->db->mallocFailed ); return WRC_Abort; } for(i=0; inSrc; i++){ struct SrcList_item *pItem = &pSrc->a[i]; if( pItem->pTab==p->pTab ){ Index: src/build.c ================================================================== --- src/build.c +++ src/build.c @@ -4141,11 +4141,12 @@ ** Assign VdbeCursor index numbers to all tables in a SrcList */ void sqlite3SrcListAssignCursors(Parse *pParse, SrcList *pList){ int i; struct SrcList_item *pItem; - if( ALWAYS(pList) ){ + assert(pList || pParse->db->mallocFailed ); + if( pList ){ for(i=0, pItem=pList->a; inSrc; i++, pItem++){ if( pItem->iCursor>=0 ) break; pItem->iCursor = pParse->nTab++; if( pItem->pSelect ){ sqlite3SrcListAssignCursors(pParse, pItem->pSelect->pSrc); Index: src/expr.c ================================================================== --- src/expr.c +++ src/expr.c @@ -184,11 +184,14 @@ /* The Expr.x union is never used at the same time as Expr.pRight */ assert( p->x.pList==0 || p->pRight==0 ); /* p->flags holds EP_Collate and p->pLeft->flags does not. And ** p->x.pSelect cannot. So if p->x.pLeft exists, it must hold at ** least one EP_Collate. Thus the following two ALWAYS. */ - if( p->x.pList!=0 && ALWAYS(!ExprHasProperty(p, EP_xIsSelect)) ){ + if( p->x.pList!=0 + && !db->mallocFailed + && ALWAYS(!ExprHasProperty(p, EP_xIsSelect)) + ){ int i; for(i=0; ALWAYS(ix.pList->nExpr); i++){ if( ExprHasProperty(p->x.pList->a[i].pExpr, EP_Collate) ){ pNext = p->x.pList->a[i].pExpr; break; @@ -1528,14 +1531,10 @@ *pp = pNew; pp = &pNew->pPrior; pNext = pNew; } - if( db->mallocFailed ){ - sqlite3SelectDelete(db, pRet); - pRet = 0; - } return pRet; } #else Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){ assert( p==0 ); Index: test/collate1.test ================================================================== --- test/collate1.test +++ test/collate1.test @@ -414,7 +414,26 @@ CREATE TABLE t0(c0 COLLATE RTRIM, c1 BLOB UNIQUE, PRIMARY KEY (c0, c1)) WITHOUT ROWID; INSERT INTO t0 VALUES (123, 3), (' ', 1), (' ', 2), ('', 4); SELECT * FROM t0 WHERE c1 = 1; } {{ } 1} + +# 2019-10-09 +# ALWAYS() macro fails following OOM +# Problem detected by dbsqlfuzz. +# +do_execsql_test 9.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); +} + +do_faultsim_test 9.1 -faults oom* -body { + execsql { + SELECT * FROM ( + SELECT b COLLATE nocase IN (SELECT c FROM t2) FROM t1 + ); + } +} -test { + faultsim_test_result {0 {}} +} finish_test