Update the implementation of sqlite3ResultSetOfSelect() to (hopefully) make

it clearer that malloc failures cannot possibly result in a crash.
Ticket #3247. (CVS 5470)

FossilOrigin-Name: 7455310931787ddc72d677ba6c471b67af9418a8
This commit is contained in:
drh 2008-07-24 15:50:41 +00:00
parent fae8917633
commit 7ce72f6950
3 changed files with 16 additions and 13 deletions

View File

@ -1,5 +1,5 @@
C Do\snot\srun\scapi3.test\sor\scapi3c.test\swhen\stesting\smemsys6.\s(CVS\s5469)
D 2008-07-24T10:32:31
C Update\sthe\simplementation\sof\ssqlite3ResultSetOfSelect()\sto\s(hopefully)\smake\nit\sclearer\sthat\smalloc\sfailures\scannot\spossibly\sresult\sin\sa\scrash.\nTicket\s#3247.\s(CVS\s5470)
D 2008-07-24T15:50:41
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 77ff156061bb870aa0a8b3d545c670d08070f7e6
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -142,7 +142,7 @@ F src/pragma.c 6fad83fbcc7ec6e76d91fe2805fe972ff3af6a0c
F src/prepare.c c9bb0aacb7a571d049805699ed18f2bb136ea091
F src/printf.c 2174222bc346a11b1eac2a654ccc4f635355ae7e
F src/random.c 5c754319d38abdd6acd74601ee0105504adc508a
F src/select.c 859ea5194b05fb2f1f816368062478cda5baa9b8
F src/select.c a152b1436d7117e25ce010453c61d1002214e337
F src/shell.c 4b835fe734304ac22a3385868cd3790c1e4f7aa1
F src/sqlite.h.in 30a57188b126a001dbc28955885fb9698a3b02e9
F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e
@ -612,7 +612,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P 9b97ce60c63c8b8afa43496a97917afd5fc26c71
R c3430620d7325034b347ad7805ef7be8
U danielk1977
Z a7f8538476a97e5c85ced884ac5e1f21
P e0a101117ca44f0cce555b5db667286729fd2ad4
R 36f01beb529c949c7be18da5beb3dc1a
U drh
Z 17b4c03daebd767a4ef2a00afd17ccd3

View File

@ -1 +1 @@
e0a101117ca44f0cce555b5db667286729fd2ad4
7455310931787ddc72d677ba6c471b67af9418a8

View File

@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.458 2008/07/22 05:00:56 shane Exp $
** $Id: select.c,v 1.459 2008/07/24 15:50:41 drh Exp $
*/
#include "sqliteInt.h"
@ -1169,6 +1169,7 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){
pTab->nCol = pEList->nExpr;
assert( pTab->nCol>0 );
pTab->aCol = aCol = sqlite3DbMallocZero(db, sizeof(pTab->aCol[0])*pTab->nCol);
testcase( aCol==0 );
for(i=0, pCol=aCol; i<pTab->nCol; i++, pCol++){
Expr *p;
char *zType;
@ -1194,11 +1195,9 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){
/* Use the original text of the column expression as its name */
zName = sqlite3MPrintf(db, "%T", &p->span);
}
if( !zName || db->mallocFailed ){
db->mallocFailed = 1;
if( db->mallocFailed ){
sqlite3_free(zName);
sqlite3DeleteTable(pTab);
return 0;
break;
}
sqlite3Dequote(zName);
@ -1230,6 +1229,10 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){
}
}
pTab->iPKey = -1;
if( db->mallocFailed ){
sqlite3DeleteTable(pTab);
return 0;
}
return pTab;
}