Index: src/vdbe.c ================================================================== --- src/vdbe.c +++ src/vdbe.c @@ -41,11 +41,11 @@ ** documentation, headers files, or other derived files. The formatting ** of the code in this file is, therefore, important. See other comments ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.792 2008/12/06 16:46:14 drh Exp $ +** $Id: vdbe.c,v 1.793 2008/12/09 02:51:24 drh Exp $ */ #include "sqliteInt.h" #include #include "vdbeInt.h" @@ -384,11 +384,11 @@ } sqlite3_snprintf(100, zCsr, "]%s", encnames[pMem->enc]); zCsr += strlen(zCsr); if( f & MEM_Zero ){ - sqlite3_snprintf(100, zCsr,"+%lldz",pMem->u.i); + sqlite3_snprintf(100, zCsr,"+%dz",pMem->u.nZero); zCsr += strlen(zCsr); } *zCsr = '\0'; }else if( f & MEM_Str ){ int j, k; @@ -2288,11 +2288,11 @@ nData += len; nHdr += sqlite3VarintLen(serial_type); if( pRec->flags & MEM_Zero ){ /* Only pure zero-filled BLOBs can be input to this Opcode. ** We do not allow blobs with a prefix and a zero-filled tail. */ - nZero += pRec->u.i; + nZero += pRec->u.nZero; }else if( len ){ nZero = 0; } } @@ -2332,11 +2332,11 @@ assert( pOp->p3>0 && pOp->p3<=p->nMem ); pOut->n = nByte; pOut->flags = MEM_Blob | MEM_Dyn; pOut->xDel = 0; if( nZero ){ - pOut->u.i = nZero; + pOut->u.nZero = nZero; pOut->flags |= MEM_Zero; } pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */ REGISTER_TRACE(pOp->p3, pOut); UPDATE_MAX_BLOBSIZE(pOut); @@ -3483,11 +3483,11 @@ } pC->nullRow = 0; }else{ int nZero; if( pData->flags & MEM_Zero ){ - nZero = pData->u.i; + nZero = pData->u.nZero; }else{ nZero = 0; } rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey, pData->z, pData->n, nZero, Index: src/vdbeInt.h ================================================================== --- src/vdbeInt.h +++ src/vdbeInt.h @@ -13,11 +13,11 @@ ** VDBE. This information used to all be at the top of the single ** source code file "vdbe.c". When that file became too big (over ** 6000 lines long) it was split up into several smaller files and ** this header information was factored out. ** -** $Id: vdbeInt.h,v 1.159 2008/12/04 20:40:10 drh Exp $ +** $Id: vdbeInt.h,v 1.160 2008/12/09 02:51:24 drh Exp $ */ #ifndef _VDBEINT_H_ #define _VDBEINT_H_ /* @@ -112,10 +112,11 @@ ** SQLITE_BLOB. */ struct Mem { union { i64 i; /* Integer value. */ + int nZero; /* Used when bit MEM_Zero is set in flags */ FuncDef *pDef; /* Used only when flags==MEM_Agg */ RowSet *pRowSet; /* Used only when flags==MEM_RowSet */ } u; double r; /* Real value */ sqlite3 *db; /* The associated database connection */ Index: src/vdbeaux.c ================================================================== --- src/vdbeaux.c +++ src/vdbeaux.c @@ -12,11 +12,11 @@ ** This file contains code used for creating, destroying, and populating ** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.) Prior ** to version 2.8.7, all this code was combined into the vdbe.c source file. ** But that file was getting too big so this subroutines were split out. ** -** $Id: vdbeaux.c,v 1.423 2008/12/05 15:24:17 drh Exp $ +** $Id: vdbeaux.c,v 1.424 2008/12/09 02:51:24 drh Exp $ */ #include "sqliteInt.h" #include #include "vdbeInt.h" @@ -139,18 +139,19 @@ int i; VdbeOp *pOp; i = p->nOp; assert( p->magic==VDBE_MAGIC_INIT ); + assert( op>0 && op<0xff ); if( p->nOpAlloc<=i ){ if( growOpArray(p) ){ return 0; } } p->nOp++; pOp = &p->aOp[i]; - pOp->opcode = op; + pOp->opcode = (u8)op; pOp->p5 = 0; pOp->p1 = p1; pOp->p2 = p2; pOp->p3 = p3; pOp->p4.p = 0; @@ -541,11 +542,11 @@ pOp->p4.p = 0; if( n==P4_INT32 ){ /* Note: this cast is safe, because the origin data point was an int ** that was cast to a (const char *). */ pOp->p4.i = SQLITE_PTR_TO_INT(zP4); - pOp->p4type = n; + pOp->p4type = P4_INT32; }else if( zP4==0 ){ pOp->p4.p = 0; pOp->p4type = P4_NOTUSED; }else if( n==P4_KEYINFO ){ KeyInfo *pKeyInfo; @@ -571,13 +572,13 @@ }else if( n==P4_KEYINFO_HANDOFF ){ pOp->p4.p = (void*)zP4; pOp->p4type = P4_KEYINFO; }else if( n<0 ){ pOp->p4.p = (void*)zP4; - pOp->p4type = n; + pOp->p4type = (signed char)n; }else{ - if( n==0 ) n = strlen(zP4); + if( n==0 ) n = (int)strlen(zP4); pOp->p4.z = sqlite3DbStrNDup(p->db, zP4, n); pOp->p4type = P4_DYNAMIC; } } @@ -637,15 +638,15 @@ case P4_KEYINFO_STATIC: case P4_KEYINFO: { int i, j; KeyInfo *pKeyInfo = pOp->p4.pKeyInfo; sqlite3_snprintf(nTemp, zTemp, "keyinfo(%d", pKeyInfo->nField); - i = strlen(zTemp); + i = (int)strlen(zTemp); for(j=0; jnField; j++){ CollSeq *pColl = pKeyInfo->aColl[j]; if( pColl ){ - int n = strlen(pColl->zName); + int n = (int)strlen(pColl->zName); if( i+n>nTemp-6 ){ memcpy(&zTemp[i],",...",4); break; } zTemp[i++] = ','; @@ -765,11 +766,11 @@ */ static void releaseMemArray(Mem *p, int N){ if( p && N ){ Mem *pEnd; sqlite3 *db = p->db; - int malloc_failed = db->mallocFailed; + u8 malloc_failed = db->mallocFailed; for(pEnd=&p[N]; pflags = MEM_Static|MEM_Str|MEM_Term; pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */ assert( pMem->z!=0 ); - pMem->n = strlen(pMem->z); + pMem->n = (int)strlen(pMem->z); pMem->type = SQLITE_TEXT; pMem->enc = SQLITE_UTF8; pMem++; } @@ -908,11 +909,11 @@ z = displayP4(pOp, pMem->z, 32); if( z!=pMem->z ){ sqlite3VdbeMemSetStr(pMem, z, -1, SQLITE_UTF8, 0); }else{ assert( pMem->z!=0 ); - pMem->n = strlen(pMem->z); + pMem->n = (int)strlen(pMem->z); pMem->enc = SQLITE_UTF8; } pMem->type = SQLITE_TEXT; pMem++; @@ -930,11 +931,11 @@ #ifdef SQLITE_DEBUG if( pOp->zComment ){ pMem->flags = MEM_Str|MEM_Term; pMem->z = pOp->zComment; - pMem->n = strlen(pMem->z); + pMem->n = (int)strlen(pMem->z); pMem->enc = SQLITE_UTF8; pMem->type = SQLITE_TEXT; }else #endif { @@ -1366,11 +1367,11 @@ char const *zFile = sqlite3BtreeGetJournalname(pBt); if( zFile[0]==0 ) continue; /* Ignore :memory: databases */ if( !needSync && !sqlite3BtreeSyncDisabled(pBt) ){ needSync = 1; } - rc = sqlite3OsWrite(pMaster, zFile, strlen(zFile)+1, offset); + rc = sqlite3OsWrite(pMaster, zFile, (int)strlen(zFile)+1, offset); offset += strlen(zFile)+1; if( rc!=SQLITE_OK ){ sqlite3OsCloseFree(pMaster); sqlite3OsDelete(pVfs, zMaster, 0); sqlite3DbFree(db, zMaster); @@ -1866,11 +1867,11 @@ #endif assert( p->isTable ); rc = sqlite3BtreeMovetoUnpacked(p->pCursor, 0, p->movetoTarget, 0, &res); if( rc ) return rc; p->lastRowid = keyToInt(p->movetoTarget); - p->rowidIsValid = res==0; + p->rowidIsValid = res==0 ?1:0; if( res<0 ){ rc = sqlite3BtreeNext(p->pCursor, &res); if( rc ) return rc; } #ifdef SQLITE_TEST @@ -1946,11 +1947,11 @@ /* Figure out whether to use 1, 2, 4, 6 or 8 bytes. */ # define MAX_6BYTE ((((i64)0x00008000)<<32)-1) i64 i = pMem->u.i; u64 u; if( file_format>=4 && (i&1)==i ){ - return 8+i; + return 8+(u32)i; } u = i<0 ? -i : i; if( u<=127 ) return 1; if( u<=32767 ) return 2; if( u<=8388607 ) return 3; @@ -1962,11 +1963,11 @@ return 7; } assert( pMem->db->mallocFailed || flags&(MEM_Str|MEM_Blob) ); n = pMem->n; if( flags & MEM_Zero ){ - n += pMem->u.i; + n += pMem->u.nZero; } assert( n>=0 ); return ((n*2) + 12 + ((flags&MEM_Str)!=0)); } @@ -2069,25 +2070,25 @@ v = pMem->u.i; } len = i = sqlite3VdbeSerialTypeLen(serial_type); assert( len<=nBuf ); while( i-- ){ - buf[i] = (v&0xFF); + buf[i] = (u8)(v&0xFF); v >>= 8; } return len; } /* String or blob */ if( serial_type>=12 ){ - assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.i:0) + assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0) == sqlite3VdbeSerialTypeLen(serial_type) ); assert( pMem->n<=nBuf ); len = pMem->n; memcpy(buf, pMem->z, len); if( pMem->flags & MEM_Zero ){ - len += pMem->u.i; + len += pMem->u.nZero; if( len>nBuf ){ len = nBuf; } memset(&buf[pMem->n], 0, len-pMem->n); } @@ -2389,17 +2390,17 @@ u32 typeRowid; /* Serial type of the rowid */ u32 lenRowid; /* Size of the rowid */ Mem m, v; sqlite3BtreeKeySize(pCur, &nCellKey); - if( nCellKey<=0 ){ + if( nCellKey<=0 || nCellKey>0x7fffffff ){ return SQLITE_CORRUPT_BKPT; } m.flags = 0; m.db = 0; m.zMalloc = 0; - rc = sqlite3VdbeMemFromBtree(pCur, 0, nCellKey, 1, &m); + rc = sqlite3VdbeMemFromBtree(pCur, 0, (int)nCellKey, 1, &m); if( rc ){ return rc; } (void)getVarint32((u8*)m.z, szHdr); (void)getVarint32((u8*)&m.z[szHdr-1], typeRowid); @@ -2433,18 +2434,18 @@ int rc; BtCursor *pCur = pC->pCursor; Mem m; sqlite3BtreeKeySize(pCur, &nCellKey); - if( nCellKey<=0 ){ + if( nCellKey<=0 || nCellKey>0x7fffffff ){ *res = 0; return SQLITE_OK; } m.db = 0; m.flags = 0; m.zMalloc = 0; - rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, nCellKey, 1, &m); + rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (int)nCellKey, 1, &m); if( rc ){ return rc; } assert( pUnpacked->flags & UNPACKED_IGNORE_ROWID ); *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked); Index: src/vdbemem.c ================================================================== --- src/vdbemem.c +++ src/vdbemem.c @@ -13,11 +13,11 @@ ** This file contains code use to manipulate "Mem" structure. A "Mem" ** stores a single value in the VDBE. Mem is an opaque structure visible ** only within the VDBE. Interface routines refer to a Mem using the ** name sqlite_value ** -** $Id: vdbemem.c,v 1.129 2008/12/05 23:40:23 drh Exp $ +** $Id: vdbemem.c,v 1.130 2008/12/09 02:51:24 drh Exp $ */ #include "sqliteInt.h" #include #include "vdbeInt.h" @@ -149,20 +149,20 @@ assert( pMem->flags&MEM_Blob ); assert( (pMem->flags&MEM_RowSet)==0 ); assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); /* Set nByte to the number of bytes required to store the expanded blob. */ - nByte = pMem->n + pMem->u.i; + nByte = pMem->n + pMem->u.nZero; if( nByte<=0 ){ nByte = 1; } if( sqlite3VdbeMemGrow(pMem, nByte, 1) ){ return SQLITE_NOMEM; } - memset(&pMem->z[pMem->n], 0, pMem->u.i); - pMem->n += pMem->u.i; + memset(&pMem->z[pMem->n], 0, pMem->u.nZero); + pMem->n += pMem->u.nZero; pMem->flags &= ~(MEM_Zero|MEM_Term); } return SQLITE_OK; } #endif @@ -224,11 +224,11 @@ sqlite3_snprintf(nByte, pMem->z, "%lld", pMem->u.i); }else{ assert( fg & MEM_Real ); sqlite3_snprintf(nByte, pMem->z, "%!.15g", pMem->r); } - pMem->n = strlen(pMem->z); + pMem->n = (int)strlen(pMem->z); pMem->enc = SQLITE_UTF8; pMem->flags |= MEM_Str|MEM_Term; sqlite3VdbeChangeEncoding(pMem, enc); return rc; } @@ -465,11 +465,11 @@ MemSetTypeFlag(pMem, MEM_Blob); pMem->flags = MEM_Blob|MEM_Zero; pMem->type = SQLITE_BLOB; pMem->n = 0; if( n<0 ) n = 0; - pMem->u.i = n; + pMem->u.nZero = n; pMem->enc = SQLITE_UTF8; } /* ** Delete any previous value and set the value stored in *pMem to val, @@ -528,11 +528,11 @@ int sqlite3VdbeMemTooBig(Mem *p){ assert( p->db!=0 ); if( p->flags & (MEM_Str|MEM_Blob) ){ int n = p->n; if( p->flags & MEM_Zero ){ - n += p->u.i; + n += p->u.nZero; } return n>p->db->aLimit[SQLITE_LIMIT_LENGTH]; } return 0; } @@ -616,11 +616,11 @@ u8 enc, /* Encoding of z. 0 for BLOBs */ void (*xDel)(void*) /* Destructor function */ ){ int nByte = n; /* New value for pMem->n */ int iLimit; /* Maximum allowed string or blob size */ - int flags = 0; /* New value for pMem->flags */ + u16 flags = 0; /* New value for pMem->flags */ assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); assert( (pMem->flags & MEM_RowSet)==0 ); /* If z is a NULL pointer, set pMem to contain an SQL NULL. */ @@ -730,16 +730,16 @@ return -1; } if( (f1 & f2 & MEM_Int)==0 ){ double r1, r2; if( (f1&MEM_Real)==0 ){ - r1 = pMem1->u.i; + r1 = (double)pMem1->u.i; }else{ r1 = pMem1->r; } if( (f2&MEM_Real)==0 ){ - r2 = pMem2->u.i; + r2 = (double)pMem2->u.i; }else{ r2 = pMem2->r; } if( r1r2 ) return 1; @@ -951,11 +951,11 @@ } sqlite3VdbeMemNulTerminate(pVal); }else{ assert( (pVal->flags&MEM_Blob)==0 ); sqlite3VdbeMemStringify(pVal, enc); - assert( 0==(1&(int)pVal->z) ); + assert( 0==(1&SQLITE_PTR_TO_INT(pVal->z)) ); } assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || pVal->db==0 || pVal->db->mallocFailed ); if( pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) ){ return pVal->z; @@ -1076,12 +1076,12 @@ */ int sqlite3ValueBytes(sqlite3_value *pVal, u8 enc){ Mem *p = (Mem*)pVal; if( (p->flags & MEM_Blob)!=0 || sqlite3ValueText(pVal, enc) ){ if( p->flags & MEM_Zero ){ - return p->n+p->u.i; + return p->n + p->u.nZero; }else{ return p->n; } } return 0; }