aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2009-01-09 01:12:27 +0000
committerdrh <drh@noemail.net>2009-01-09 01:12:27 +0000
commite2f02bacc1b5b1cf3a317b8f7a6b2a8e539b4cfa (patch)
tree09589065b0e979bcd3a008554668fcc06ad33182 /src
parent103bd88cf77e70867eb6937f5c949bf5315a17d5 (diff)
downloadsqlite-e2f02bacc1b5b1cf3a317b8f7a6b2a8e539b4cfa.tar.gz
sqlite-e2f02bacc1b5b1cf3a317b8f7a6b2a8e539b4cfa.zip
Increased test coverage. (CVS 6147)
FossilOrigin-Name: 45bb5703d7ef5e835b43a6fa7ee2a2d96db76939
Diffstat (limited to 'src')
-rw-r--r--src/hash.c4
-rw-r--r--src/rowset.c30
-rw-r--r--src/select.c20
3 files changed, 29 insertions, 25 deletions
diff --git a/src/hash.c b/src/hash.c
index 558118e43..013f41af5 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -12,7 +12,7 @@
** This is the implementation of generic hash-tables
** used in SQLite.
**
-** $Id: hash.c,v 1.32 2008/12/10 19:26:24 drh Exp $
+** $Id: hash.c,v 1.33 2009/01/09 01:12:28 drh Exp $
*/
#include "sqliteInt.h"
#include <assert.h>
@@ -48,7 +48,7 @@ void sqlite3HashClear(Hash *pH){
pH->htsize = 0;
while( elem ){
HashElem *next_elem = elem->next;
- if( pH->copyKey && elem->pKey ){
+ if( pH->copyKey ){
sqlite3_free(elem->pKey);
}
sqlite3_free(elem);
diff --git a/src/rowset.c b/src/rowset.c
index 2be962759..012cfc80b 100644
--- a/src/rowset.c
+++ b/src/rowset.c
@@ -73,25 +73,23 @@ struct RowSet {
** for any subsequent allocations that need to occur.
** Return a pointer to the new RowSet object.
**
-** If N is not sufficient memory to make even a minimum RowSet,
-** then return NULL. If N is larger than the minimum, use
-** the surplus as an initial allocation of entries available to
-** be filled.
+** It must be the case that N is sufficient to make a Rowset. If not
+** an assertion fault occurs.
+**
+** If N is larger than the minimum, use the surplus as an initial
+** allocation of entries available to be filled.
*/
RowSet *sqlite3RowSetInit(sqlite3 *db, void *pSpace, unsigned int N){
RowSet *p;
- if( N<sizeof(*p) ){
- p = 0;
- }else{
- p = pSpace;
- p->pChunk = 0;
- p->db = db;
- p->pEntry = 0;
- p->pLast = 0;
- p->pFresh = (struct RowSetEntry*)&p[1];
- p->nFresh = (u16)((N - sizeof(*p))/sizeof(struct RowSetEntry));
- p->isSorted = 1;
- }
+ assert( N >= sizeof(*p) );
+ p = pSpace;
+ p->pChunk = 0;
+ p->db = db;
+ p->pEntry = 0;
+ p->pLast = 0;
+ p->pFresh = (struct RowSetEntry*)&p[1];
+ p->nFresh = (u16)((N - sizeof(*p))/sizeof(struct RowSetEntry));
+ p->isSorted = 1;
return p;
}
diff --git a/src/select.c b/src/select.c
index ccecdf973..1feb6ae56 100644
--- a/src/select.c
+++ b/src/select.c
@@ -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.496 2009/01/05 19:36:30 drh Exp $
+** $Id: select.c,v 1.497 2009/01/09 01:12:28 drh Exp $
*/
#include "sqliteInt.h"
@@ -1067,7 +1067,7 @@ static void generateColumnNames(
#endif
assert( v!=0 );
- if( pParse->colNamesSet || v==0 || db->mallocFailed ) return;
+ if( pParse->colNamesSet || NEVER(v==0) || db->mallocFailed ) return;
pParse->colNamesSet = 1;
fullNames = (db->flags & SQLITE_FullColNames)!=0;
shortNames = (db->flags & SQLITE_ShortColNames)!=0;
@@ -1083,7 +1083,9 @@ static void generateColumnNames(
Table *pTab;
char *zCol;
int iCol = p->iColumn;
- for(j=0; j<pTabList->nSrc && pTabList->a[j].iCursor!=p->iTable; j++){}
+ for(j=0; ALWAYS(j<pTabList->nSrc); j++){
+ if( pTabList->a[j].iCursor==p->iTable ) break;
+ }
assert( j<pTabList->nSrc );
pTab = pTabList->a[j].pTab;
if( iCol<0 ) iCol = pTab->iPKey;
@@ -1545,10 +1547,14 @@ static int multiSelect(
SelectDest uniondest;
priorOp = SRT_Union;
- if( dest.eDest==priorOp && !p->pLimit && !p->pOffset ){
+ if( dest.eDest==priorOp && ALWAYS(!p->pLimit &&!p->pOffset) ){
/* We can reuse a temporary table generated by a SELECT to our
** right.
*/
+ assert( p->pRightmost!=p ); /* Can only happen for leftward elements
+ ** of a 3-way or more compound */
+ assert( p->pLimit==0 ); /* Not allowed on leftward elements */
+ assert( p->pOffset==0 ); /* Not allowed on leftward elements */
unionTab = dest.iParm;
}else{
/* We will need to create our own temporary table to hold the
@@ -2445,7 +2451,8 @@ static void substSelect(
substExpr(db, p->pWhere, iTable, pEList);
substSelect(db, p->pPrior, iTable, pEList);
pSrc = p->pSrc;
- if( pSrc ){
+ assert( pSrc ); /* Even for (SELECT 1) we have: pSrc!=0 but pSrc->nSrc==0 */
+ if( ALWAYS(pSrc) ){
for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
substSelect(db, pItem->pSelect, iTable, pEList);
}
@@ -2577,7 +2584,6 @@ static int flattenSubquery(
/* Check to see if flattening is permitted. Return 0 if not.
*/
assert( p!=0 );
- if( p==0 ) return 0;
assert( p->pPrior==0 ); /* Unable to flatten compound queries */
pSrc = p->pSrc;
assert( pSrc && iFrom>=0 && iFrom<pSrc->nSrc );
@@ -2655,7 +2661,7 @@ static int flattenSubquery(
** queries.
*/
if( pSub->pPrior ){
- if( p->pPrior || isAgg || (p->selFlags & SF_Distinct)!=0 || pSrc->nSrc!=1 ){
+ if( isAgg || (p->selFlags & SF_Distinct)!=0 || pSrc->nSrc!=1 ){
return 0;
}
for(pSub1=pSub; pSub1; pSub1=pSub1->pPrior){