aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2008-12-10 19:26:22 +0000
committerdrh <drh@noemail.net>2008-12-10 19:26:22 +0000
commitea6788322ed9cb2aee581ed7b2b1befaa45de723 (patch)
tree65d847abfea18be171501bb18f06fa71a44b2da2 /src
parentb27b7f5d3b5d9d249b9abb258ac0e6cb54b78fdd (diff)
downloadsqlite-ea6788322ed9cb2aee581ed7b2b1befaa45de723.tar.gz
sqlite-ea6788322ed9cb2aee581ed7b2b1befaa45de723.zip
Never use strlen(). Use our own internal sqlite3Strlen30() which is
guaranteed to never overflow an integer. Additional explicit casts to avoid nuisance warning messages. (CVS 6007) FossilOrigin-Name: c872d554930ecf221ac2be5f886d5d67bb35288c
Diffstat (limited to 'src')
-rw-r--r--src/alter.c6
-rw-r--r--src/build.c46
-rw-r--r--src/callback.c6
-rw-r--r--src/date.c20
-rw-r--r--src/delete.c4
-rw-r--r--src/func.c5
-rw-r--r--src/hash.c4
-rw-r--r--src/insert.c6
-rw-r--r--src/legacy.c4
-rw-r--r--src/malloc.c4
-rw-r--r--src/mem2.c4
-rw-r--r--src/memjournal.c4
-rw-r--r--src/os_os2.c6
-rw-r--r--src/os_unix.c20
-rw-r--r--src/os_win.c12
-rw-r--r--src/pager.c15
-rw-r--r--src/pragma.c8
-rw-r--r--src/prepare.c8
-rw-r--r--src/printf.c40
-rw-r--r--src/random.c6
-rw-r--r--src/resolve.c12
-rw-r--r--src/select.c30
-rw-r--r--src/shell.c62
-rw-r--r--src/sqliteInt.h3
-rw-r--r--src/table.c4
-rw-r--r--src/tclsqlite.c37
-rw-r--r--src/trigger.c16
-rw-r--r--src/utf.c6
-rw-r--r--src/vdbe.c18
-rw-r--r--src/vdbeaux.c22
-rw-r--r--src/vdbemem.c10
-rw-r--r--src/vtab.c18
-rw-r--r--src/where.c6
33 files changed, 261 insertions, 211 deletions
diff --git a/src/alter.c b/src/alter.c
index fe1e2cb19..9733c56cd 100644
--- a/src/alter.c
+++ b/src/alter.c
@@ -12,7 +12,7 @@
** This file contains C code routines that used to generate VDBE code
** that implements the ALTER TABLE command.
**
-** $Id: alter.c,v 1.50 2008/11/19 09:05:27 danielk1977 Exp $
+** $Id: alter.c,v 1.51 2008/12/10 19:26:22 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -305,7 +305,9 @@ void sqlite3AlterRenameTable(
/* Make sure it is not a system table being altered, or a reserved name
** that the table is being renamed to.
*/
- if( strlen(pTab->zName)>6 && 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) ){
+ if( sqlite3Strlen30(pTab->zName)>6
+ && 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7)
+ ){
sqlite3ErrorMsg(pParse, "table %s may not be altered", pTab->zName);
goto exit_rename_table;
}
diff --git a/src/build.c b/src/build.c
index 464dc39da..bb279b1ac 100644
--- a/src/build.c
+++ b/src/build.c
@@ -22,7 +22,7 @@
** COMMIT
** ROLLBACK
**
-** $Id: build.c,v 1.505 2008/12/10 17:20:00 drh Exp $
+** $Id: build.c,v 1.506 2008/12/10 19:26:22 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -369,7 +369,8 @@ static void sqliteDeleteIndex(Index *p){
Index *pOld;
const char *zName = p->zName;
- pOld = sqlite3HashInsert(&p->pSchema->idxHash, zName, strlen(zName)+1, 0);
+ pOld = sqlite3HashInsert(&p->pSchema->idxHash, zName,
+ sqlite3Strlen30(zName)+1, 0);
assert( pOld==0 || pOld==p );
freeIndex(p);
}
@@ -534,7 +535,7 @@ void sqlite3DeleteTable(Table *pTable){
for(pFKey=pTable->pFKey; pFKey; pFKey=pNextFKey){
pNextFKey = pFKey->pNextFrom;
assert( sqlite3HashFind(&pTable->pSchema->aFKey,
- pFKey->zTo, strlen(pFKey->zTo)+1)!=pFKey );
+ pFKey->zTo, sqlite3Strlen30(pFKey->zTo)+1)!=pFKey );
sqlite3DbFree(db, pFKey);
}
#endif
@@ -565,11 +566,12 @@ void sqlite3UnlinkAndDeleteTable(sqlite3 *db, int iDb, const char *zTabName){
assert( iDb>=0 && iDb<db->nDb );
assert( zTabName && zTabName[0] );
pDb = &db->aDb[iDb];
- p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName, strlen(zTabName)+1,0);
+ p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName,
+ sqlite3Strlen30(zTabName)+1,0);
if( p ){
#ifndef SQLITE_OMIT_FOREIGN_KEY
for(pF1=p->pFKey; pF1; pF1=pF1->pNextFrom){
- int nTo = strlen(pF1->zTo) + 1;
+ int nTo = sqlite3Strlen30(pF1->zTo) + 1;
pF2 = sqlite3HashFind(&pDb->pSchema->aFKey, pF1->zTo, nTo);
if( pF2==pF1 ){
sqlite3HashInsert(&pDb->pSchema->aFKey, pF1->zTo, nTo, pF1->pNextTo);
@@ -632,9 +634,9 @@ int sqlite3FindDb(sqlite3 *db, Token *pName){
zName = sqlite3NameFromToken(db, pName);
if( zName ){
- n = strlen(zName);
+ n = sqlite3Strlen30(zName);
for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
- if( (!OMIT_TEMPDB || i!=1 ) && n==strlen(pDb->zName) &&
+ if( (!OMIT_TEMPDB || i!=1 ) && n==sqlite3Strlen30(pDb->zName) &&
0==sqlite3StrICmp(pDb->zName, zName) ){
break;
}
@@ -1365,7 +1367,7 @@ static char *createTableStmt(sqlite3 *db, Table *p, int isTemp){
n += identLength(pCol->zName);
z = pCol->zType;
if( z ){
- n += (strlen(z) + 1);
+ n += (sqlite3Strlen30(z) + 1);
}
}
n += identLength(p->zName);
@@ -1386,19 +1388,19 @@ static char *createTableStmt(sqlite3 *db, Table *p, int isTemp){
}
sqlite3_snprintf(n, zStmt,
!OMIT_TEMPDB&&isTemp ? "CREATE TEMP TABLE ":"CREATE TABLE ");
- k = strlen(zStmt);
+ k = sqlite3Strlen30(zStmt);
identPut(zStmt, &k, p->zName);
zStmt[k++] = '(';
for(pCol=p->aCol, i=0; i<p->nCol; i++, pCol++){
sqlite3_snprintf(n-k, &zStmt[k], zSep);
- k += strlen(&zStmt[k]);
+ k += sqlite3Strlen30(&zStmt[k]);
zSep = zSep2;
identPut(zStmt, &k, pCol->zName);
if( (z = pCol->zType)!=0 ){
zStmt[k++] = ' ';
- assert( (int)(strlen(z)+k+1)<=n );
+ assert( (int)(sqlite3Strlen30(z)+k+1)<=n );
sqlite3_snprintf(n-k, &zStmt[k], "%s", z);
- k += strlen(z);
+ k += sqlite3Strlen30(z);
}
}
sqlite3_snprintf(n-k, &zStmt[k], "%s", zEnd);
@@ -1606,7 +1608,8 @@ void sqlite3EndTable(
Table *pOld;
FKey *pFKey;
Schema *pSchema = p->pSchema;
- pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName, strlen(p->zName)+1,p);
+ pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName,
+ sqlite3Strlen30(p->zName)+1,p);
if( pOld ){
assert( p==pOld ); /* Malloc must have failed inside HashInsert() */
db->mallocFailed = 1;
@@ -1615,7 +1618,7 @@ void sqlite3EndTable(
#ifndef SQLITE_OMIT_FOREIGN_KEY
for(pFKey=p->pFKey; pFKey; pFKey=pFKey->pNextFrom){
void *data;
- int nTo = strlen(pFKey->zTo) + 1;
+ int nTo = sqlite3Strlen30(pFKey->zTo) + 1;
pFKey->pNextTo = sqlite3HashFind(&pSchema->aFKey, pFKey->zTo, nTo);
data = sqlite3HashInsert(&pSchema->aFKey, pFKey->zTo, nTo, pFKey);
if( data==(void *)pFKey ){
@@ -2172,7 +2175,7 @@ void sqlite3CreateForeignKey(
nByte = sizeof(*pFKey) + nCol*sizeof(pFKey->aCol[0]) + pTo->n + 1;
if( pToCol ){
for(i=0; i<pToCol->nExpr; i++){
- nByte += strlen(pToCol->a[i].zName) + 1;
+ nByte += sqlite3Strlen30(pToCol->a[i].zName) + 1;
}
}
pFKey = sqlite3DbMallocZero(db, nByte );
@@ -2211,7 +2214,7 @@ void sqlite3CreateForeignKey(
}
if( pToCol ){
for(i=0; i<nCol; i++){
- int n = strlen(pToCol->a[i].zName);
+ int n = sqlite3Strlen30(pToCol->a[i].zName);
pFKey->aCol[i].zCol = z;
memcpy(z, pToCol->a[i].zName, n);
z[n] = 0;
@@ -2497,7 +2500,7 @@ void sqlite3CreateIndex(
*/
if( pList==0 ){
nullId.z = (u8*)pTab->aCol[pTab->nCol-1].zName;
- nullId.n = strlen((char*)nullId.z);
+ nullId.n = sqlite3Strlen30((char*)nullId.z);
pList = sqlite3ExprListAppend(pParse, 0, 0, &nullId);
if( pList==0 ) goto exit_create_index;
pList->a[0].sortOrder = sortOrder;
@@ -2510,14 +2513,14 @@ void sqlite3CreateIndex(
Expr *pExpr;
CollSeq *pColl;
if( (pExpr = pList->a[i].pExpr)!=0 && (pColl = pExpr->pColl)!=0 ){
- nExtra += (1 + strlen(pColl->zName));
+ nExtra += (1 + sqlite3Strlen30(pColl->zName));
}
}
/*
** Allocate the index structure.
*/
- nName = strlen(zName);
+ nName = sqlite3Strlen30(zName);
nCol = pList->nExpr;
pIndex = sqlite3DbMallocZero(db,
sizeof(Index) + /* Index structure */
@@ -2581,7 +2584,7 @@ void sqlite3CreateIndex(
assert( pListItem->pExpr->pColl );
zColl = zExtra;
sqlite3_snprintf(nExtra, zExtra, "%s", pListItem->pExpr->pColl->zName);
- zExtra += (strlen(zColl) + 1);
+ zExtra += (sqlite3Strlen30(zColl) + 1);
}else{
zColl = pTab->aCol[j].zColl;
if( !zColl ){
@@ -2654,7 +2657,8 @@ void sqlite3CreateIndex(
if( db->init.busy ){
Index *p;
p = sqlite3HashInsert(&pIndex->pSchema->idxHash,
- pIndex->zName, strlen(pIndex->zName)+1, pIndex);
+ pIndex->zName, sqlite3Strlen30(pIndex->zName)+1,
+ pIndex);
if( p ){
assert( p==pIndex ); /* Malloc must have failed */
db->mallocFailed = 1;
diff --git a/src/callback.c b/src/callback.c
index c2e39cd8c..90f4297d3 100644
--- a/src/callback.c
+++ b/src/callback.c
@@ -13,7 +13,7 @@
** This file contains functions used to access the internal hash tables
** of user defined functions and collation sequences.
**
-** $Id: callback.c,v 1.32 2008/10/10 17:41:29 drh Exp $
+** $Id: callback.c,v 1.33 2008/12/10 19:26:22 drh Exp $
*/
#include "sqliteInt.h"
@@ -56,7 +56,7 @@ static void callCollNeeded(sqlite3 *db, const char *zName, int nName){
static int synthCollSeq(sqlite3 *db, CollSeq *pColl){
CollSeq *pColl2;
char *z = pColl->zName;
- int n = strlen(z);
+ int n = sqlite3Strlen30(z);
int i;
static const u8 aEnc[] = { SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF8 };
for(i=0; i<3; i++){
@@ -287,7 +287,7 @@ void sqlite3FuncDefInsert(
FuncDef *pDef /* The function definition to insert */
){
FuncDef *pOther;
- int nName = strlen(pDef->zName);
+ int nName = sqlite3Strlen30(pDef->zName);
u8 c1 = (u8)pDef->zName[0];
int h = (sqlite3UpperToLower[c1] + nName) % ArraySize(pHash->a);
pOther = functionSearch(pHash, h, pDef->zName, nName);
diff --git a/src/date.c b/src/date.c
index 3f6fbddea..968478eb8 100644
--- a/src/date.c
+++ b/src/date.c
@@ -16,7 +16,7 @@
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
** All other code has file scope.
**
-** $Id: date.c,v 1.95 2008/12/09 04:59:00 shane Exp $
+** $Id: date.c,v 1.96 2008/12/10 19:26:22 drh Exp $
**
** SQLite processes all times and dates as Julian Day numbers. The
** dates and times are stored as the number of days since noon
@@ -657,7 +657,7 @@ static int parseModifier(const char *zMod, DateTime *p){
}
z += n;
while( isspace(*(u8*)z) ) z++;
- n = (int)strlen(z);
+ n = sqlite3Strlen30(z);
if( n>10 || n<3 ) break;
if( z[n-1]=='s' ){ z[n-1] = 0; n--; }
computeJD(p);
@@ -912,7 +912,7 @@ static void strftimeFunc(
double s = x.s;
if( s>59.999 ) s = 59.999;
sqlite3_snprintf(7, &z[j],"%06.3f", s);
- j += strlen(&z[j]);
+ j += sqlite3Strlen30(&z[j]);
break;
}
case 'H': sqlite3_snprintf(3, &z[j],"%02d",x.h); j+=2; break;
@@ -938,7 +938,7 @@ static void strftimeFunc(
}
case 'J': {
sqlite3_snprintf(20, &z[j],"%.16g",x.iJD/86400000.0);
- j+=strlen(&z[j]);
+ j+=sqlite3Strlen30(&z[j]);
break;
}
case 'm': sqlite3_snprintf(3, &z[j],"%02d",x.M); j+=2; break;
@@ -946,12 +946,18 @@ static void strftimeFunc(
case 's': {
sqlite3_snprintf(30,&z[j],"%d",
(int)(x.iJD/1000.0 - 210866760000.0));
- j += strlen(&z[j]);
+ j += sqlite3Strlen30(&z[j]);
break;
}
case 'S': sqlite3_snprintf(3,&z[j],"%02d",(int)x.s); j+=2; break;
- case 'w': z[j++] = (char)(((x.iJD+129600000)/86400000) % 7) + '0'; break;
- case 'Y': sqlite3_snprintf(5,&z[j],"%04d",x.Y); j+=strlen(&z[j]);break;
+ case 'w': {
+ z[j++] = (char)(((x.iJD+129600000)/86400000) % 7) + '0';
+ break;
+ }
+ case 'Y': {
+ sqlite3_snprintf(5,&z[j],"%04d",x.Y); j+=sqlite3Strlen30(&z[j]);
+ break;
+ }
default: z[j++] = '%'; break;
}
}
diff --git a/src/delete.c b/src/delete.c
index 6fad57aef..aa90b19ea 100644
--- a/src/delete.c
+++ b/src/delete.c
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** in order to generate code for DELETE FROM statements.
**
-** $Id: delete.c,v 1.188 2008/12/04 20:40:10 drh Exp $
+** $Id: delete.c,v 1.189 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
@@ -106,7 +106,7 @@ void sqlite3MaterializeView(
pWhere = sqlite3ExprDup(db, pWhere);
viewName.z = (u8*)pView->zName;
- viewName.n = (unsigned int)strlen((const char*)viewName.z);
+ viewName.n = (unsigned int)sqlite3Strlen30((const char*)viewName.z);
pFrom = sqlite3SrcListAppendFromTerm(pParse, 0, 0, 0, &viewName, pDup, 0,0);
pDup = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0);
}
diff --git a/src/func.c b/src/func.c
index 34a1642f8..5e3264fea 100644
--- a/src/func.c
+++ b/src/func.c
@@ -16,7 +16,7 @@
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
-** $Id: func.c,v 1.206 2008/11/19 16:52:44 danielk1977 Exp $
+** $Id: func.c,v 1.207 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -1253,7 +1253,8 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
*/
static void setLikeOptFlag(sqlite3 *db, const char *zName, int flagVal){
FuncDef *pDef;
- pDef = sqlite3FindFunction(db, zName, strlen(zName), 2, SQLITE_UTF8, 0);
+ pDef = sqlite3FindFunction(db, zName, sqlite3Strlen30(zName),
+ 2, SQLITE_UTF8, 0);
if( pDef ){
pDef->flags = flagVal;
}
diff --git a/src/hash.c b/src/hash.c
index 99a4103f9..558118e43 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.31 2008/10/10 17:41:29 drh Exp $
+** $Id: hash.c,v 1.32 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
#include <assert.h>
@@ -63,7 +63,7 @@ void sqlite3HashClear(Hash *pH){
static int strHash(const void *pKey, int nKey){
const char *z = (const char *)pKey;
int h = 0;
- if( nKey<=0 ) nKey = strlen(z);
+ if( nKey<=0 ) nKey = sqlite3Strlen30(z);
while( nKey > 0 ){
h = (h<<3) ^ h ^ sqlite3UpperToLower[(unsigned char)*z++];
nKey--;
diff --git a/src/insert.c b/src/insert.c
index 560394312..19fc75728 100644
--- a/src/insert.c
+++ b/src/insert.c
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
**
-** $Id: insert.c,v 1.254 2008/12/10 17:20:00 drh Exp $
+** $Id: insert.c,v 1.255 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
@@ -1272,10 +1272,10 @@ void sqlite3GenerateConstraintChecks(
char zErrMsg[200];
sqlite3_snprintf(ArraySize(zErrMsg), zErrMsg,
pIdx->nColumn>1 ? "columns " : "column ");
- n1 = strlen(zErrMsg);
+ n1 = sqlite3Strlen30(zErrMsg);
for(j=0; j<pIdx->nColumn && n1<ArraySize(zErrMsg)-30; j++){
char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
- n2 = strlen(zCol);
+ n2 = sqlite3Strlen30(zCol);
if( j>0 ){
sqlite3_snprintf(ArraySize(zErrMsg)-n1, &zErrMsg[n1], ", ");
n1 += 2;
diff --git a/src/legacy.c b/src/legacy.c
index e6b75c0a6..5b037f067 100644
--- a/src/legacy.c
+++ b/src/legacy.c
@@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
-** $Id: legacy.c,v 1.29 2008/08/02 03:50:39 drh Exp $
+** $Id: legacy.c,v 1.30 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
@@ -131,7 +131,7 @@ exec_out:
rc = sqlite3ApiExit(db, rc);
if( rc!=SQLITE_OK && rc==sqlite3_errcode(db) && pzErrMsg ){
- int nErrMsg = 1 + strlen(sqlite3_errmsg(db));
+ int nErrMsg = 1 + sqlite3Strlen30(sqlite3_errmsg(db));
*pzErrMsg = sqlite3Malloc(nErrMsg);
if( *pzErrMsg ){
memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg);
diff --git a/src/malloc.c b/src/malloc.c
index da70da9f8..1950e048b 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -12,7 +12,7 @@
**
** Memory allocation functions used throughout sqlite.
**
-** $Id: malloc.c,v 1.49 2008/12/05 15:24:17 drh Exp $
+** $Id: malloc.c,v 1.50 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
@@ -724,7 +724,7 @@ char *sqlite3DbStrDup(sqlite3 *db, const char *z){
if( z==0 ){
return 0;
}
- n = strlen(z)+1;
+ n = (db ? sqlite3Strlen(db, z) : sqlite3Strlen30(z))+1;
assert( (n&0x7fffffff)==n );
zNew = sqlite3DbMallocRaw(db, (int)n);
if( zNew ){
diff --git a/src/mem2.c b/src/mem2.c
index aaa58e2d1..25a6a56de 100644
--- a/src/mem2.c
+++ b/src/mem2.c
@@ -19,7 +19,7 @@
** This file contains implementations of the low-level memory allocation
** routines specified in the sqlite3_mem_methods object.
**
-** $Id: mem2.c,v 1.41 2008/12/05 17:17:08 drh Exp $
+** $Id: mem2.c,v 1.42 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
@@ -363,7 +363,7 @@ void sqlite3MemdebugBacktraceCallback(void (*xBacktrace)(int, int, void **)){
** Set the title string for subsequent allocations.
*/
void sqlite3MemdebugSettitle(const char *zTitle){
- unsigned int n = strlen(zTitle) + 1;
+ unsigned int n = sqlite3Strlen30(zTitle) + 1;
sqlite3_mutex_enter(mem.mutex);
if( n>=sizeof(mem.zTitle) ) n = sizeof(mem.zTitle)-1;
memcpy(mem.zTitle, zTitle, n);
diff --git a/src/memjournal.c b/src/memjournal.c
index 9ee6f10f0..bd91a3e15 100644
--- a/src/memjournal.c
+++ b/src/memjournal.c
@@ -14,7 +14,7 @@
** The in-memory rollback journal is used to journal transactions for
** ":memory:" databases and when the journal_mode=MEMORY pragma is used.
**
-** @(#) $Id: memjournal.c,v 1.5 2008/11/19 16:52:44 danielk1977 Exp $
+** @(#) $Id: memjournal.c,v 1.6 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
@@ -99,7 +99,7 @@ static int memjrnlRead(
zOut += nCopy;
nRead -= iSpace;
iChunkOffset = 0;
- } while( nRead>=0 && (pChunk=pChunk->pNext) && nRead>0 );
+ } while( nRead>=0 && (pChunk=pChunk->pNext)!=0 && nRead>0 );
p->readpoint.iOffset = iOfst+iAmt;
p->readpoint.pChunk = pChunk;
diff --git a/src/os_os2.c b/src/os_os2.c
index 8bcdb8c0b..07e9e6dba 100644
--- a/src/os_os2.c
+++ b/src/os_os2.c
@@ -12,7 +12,7 @@
**
** This file contains code that is specific to OS/2.
**
-** $Id: os_os2.c,v 1.62 2008/11/26 20:03:21 pweilbacher Exp $
+** $Id: os_os2.c,v 1.63 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
@@ -694,7 +694,7 @@ static int getTempname(int nBuf, char *zBuf ){
/* Strip off a trailing slashes or backslashes, otherwise we would get *
* multiple (back)slashes which causes DosOpen() to fail. *
* Trailing spaces are not allowed, either. */
- j = strlen(zTempPath);
+ j = sqlite3Strlen30(zTempPath);
while( j > 0 && ( zTempPath[j-1] == '\\' || zTempPath[j-1] == '/'
|| zTempPath[j-1] == ' ' ) ){
j--;
@@ -709,7 +709,7 @@ static int getTempname(int nBuf, char *zBuf ){
sqlite3_snprintf( nBuf-30, zBuf,
"%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath );
}
- j = strlen( zBuf );
+ j = sqlite3Strlen30( zBuf );
sqlite3_randomness( 20, &zBuf[j] );
for( i = 0; i < 20; i++, j++ ){
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
diff --git a/src/os_unix.c b/src/os_unix.c
index 0e4975d3b..7675300d7 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -43,7 +43,7 @@
** * Definitions of sqlite3_vfs objects for all locking methods
** plus implementations of sqlite3_os_init() and sqlite3_os_end().
**
-** $Id: os_unix.c,v 1.230 2008/12/08 18:19:18 drh Exp $
+** $Id: os_unix.c,v 1.231 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
#if SQLITE_OS_UNIX /* This file is used on unix only */
@@ -483,7 +483,7 @@ static struct vxworksFileId *vxworksFindFileId(const char *zAbsoluteName){
int n; /* Length of zAbsoluteName string */
assert( zAbsoluteName[0]=='/' );
- n = strlen(zAbsoluteName);
+ n = (int)strlen(zAbsoluteName);
pNew = sqlite3_malloc( sizeof(*pNew) + (n+1) );
if( pNew==0 ) return 0;
pNew->zCanonicalName = (char*)&pNew[1];
@@ -3307,7 +3307,7 @@ static int fillInUnixFile(
*/
char *zLockFile;
int nFilename;
- nFilename = strlen(zFilename) + 6;
+ nFilename = (int)strlen(zFilename) + 6;
zLockFile = (char *)sqlite3_malloc(nFilename);
if( zLockFile==0 ){
rc = SQLITE_NOMEM;
@@ -3375,7 +3375,7 @@ static int openDirectory(const char *zFilename, int *pFd){
char zDirname[MAX_PATHNAME+1];
sqlite3_snprintf(MAX_PATHNAME, zDirname, "%s", zFilename);
- for(ii=strlen(zDirname); ii>=0 && zDirname[ii]!='/'; ii--);
+ for(ii=(int)strlen(zDirname); ii>=0 && zDirname[ii]!='/'; ii--);
if( ii>0 ){
zDirname[ii] = '\0';
fd = open(zDirname, O_RDONLY|O_BINARY, 0);
@@ -3441,7 +3441,7 @@ static int getTempname(int nBuf, char *zBuf){
do{
sqlite3_snprintf(nBuf-17, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX, zDir);
- j = strlen(zBuf);
+ j = (int)strlen(zBuf);
sqlite3_randomness(15, &zBuf[j]);
for(i=0; i<15; i++, j++){
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
@@ -3743,7 +3743,7 @@ static int unixFullPathname(
if( getcwd(zOut, nOut-1)==0 ){
return SQLITE_CANTOPEN;
}
- nCwd = strlen(zOut);
+ nCwd = (int)strlen(zOut);
sqlite3_snprintf(nOut-nCwd, &zOut[nCwd], "/%s", zPath);
}
return SQLITE_OK;
@@ -4280,7 +4280,7 @@ static int proxyGetLockPath(const char *dbPath, char *lPath, size_t maxLen){
}
/* transform the db path to a unique cache name */
- dbLen = strlen(dbPath);
+ dbLen = (int)strlen(dbPath);
for( i=0; i<dbLen && (i+len+7)<maxLen; i++){
char c = dbPath[i];
lPath[i+len] = (c=='/')?'_':c;
@@ -4516,7 +4516,7 @@ static int proxyReleaseConch(unixFile *pFile){
*/
static int proxyCreateConchPathname(char *dbPath, char **pConchPath){
int i; /* Loop counter */
- int len = strlen(dbPath); /* Length of database filename - dbPath */
+ int len = (int)strlen(dbPath); /* Length of database filename - dbPath */
char *conchPath; /* buffer in which to construct conch name */
/* Allocate space for the conch filename and initialize the name to
@@ -4542,7 +4542,7 @@ static int proxyCreateConchPathname(char *dbPath, char **pConchPath){
/* append the "-conch" suffix to the file */
memcpy(&conchPath[i+1], "-conch", 7);
- assert( strlen(conchPath) == len+7 );
+ assert( (int)strlen(conchPath) == len+7 );
return SQLITE_OK;
}
@@ -4592,7 +4592,7 @@ static int proxyGetDbPathForUnixFile(unixFile *pFile, char *dbPath){
if( pFile->pMethod == &afpIoMethods ){
/* afp style keeps a reference to the db path in the filePath field
** of the struct */
- assert( strlen((char*)pFile->lockingContext)<=MAXPATHLEN );
+ assert( (int)strlen((char*)pFile->lockingContext)<=MAXPATHLEN );
strcpy(dbPath, ((afpLockingContext *)pFile->lockingContext)->dbPath);
}else
#endif
diff --git a/src/os_win.c b/src/os_win.c
index 7f32b43f1..f5fb4f581 100644
--- a/src/os_win.c
+++ b/src/os_win.c
@@ -12,7 +12,7 @@
**
** This file contains code that is specific to windows.
**
-** $Id: os_win.c,v 1.141 2008/12/08 18:19:18 drh Exp $
+** $Id: os_win.c,v 1.142 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
#if SQLITE_OS_WIN /* This file is used for windows only */
@@ -685,7 +685,7 @@ static int winWrite(
LONG upperBits = (offset>>32) & 0x7fffffff;
LONG lowerBits = offset & 0xffffffff;
DWORD rc;
- DWORD wrote;
+ DWORD wrote = 0;
winFile *pFile = (winFile*)id;
assert( id!=0 );
SimulateIOError(return SQLITE_IOERR_WRITE);
@@ -1149,11 +1149,11 @@ static int getTempname(int nBuf, char *zBuf){
}
#endif
}
- for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
+ for(i=sqlite3Strlen30(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
zTempPath[i] = 0;
sqlite3_snprintf(nBuf-30, zBuf,
"%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath);
- j = strlen(zBuf);
+ j = sqlite3Strlen30(zBuf);
sqlite3_randomness(20, &zBuf[j]);
for(i=0; i<20; i++, j++){
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
@@ -1350,7 +1350,7 @@ static int winDelete(
){
int cnt = 0;
DWORD rc;
- DWORD error;
+ DWORD error = 0;
void *zConverted = convertUtf8Filename(zFilename);
if( zConverted==0 ){
return SQLITE_NOMEM;
@@ -1393,7 +1393,7 @@ static int winAccess(
int *pResOut /* OUT: Result */
){
DWORD attr;
- int rc;
+ int rc = 0;
void *zConverted = convertUtf8Filename(zFilename);
if( zConverted==0 ){
return SQLITE_NOMEM;
diff --git a/src/pager.c b/src/pager.c
index b95a0bf82..f8b98e654 100644
--- a/src/pager.c
+++ b/src/pager.c
@@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while
** another is writing.
**
-** @(#) $Id: pager.c,v 1.511 2008/12/10 16:45:51 drh Exp $
+** @(#) $Id: pager.c,v 1.512 2008/12/10 19:26:24 drh Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
@@ -815,7 +815,7 @@ static int writeMasterJournal(Pager *pPager, const char *zMaster){
if( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ) return SQLITE_OK;
pPager->setMaster = 1;
- len = strlen(zMaster);
+ len = sqlite3Strlen30(zMaster);
for(i=0; i<len; i++){
cksum += zMaster[i];
}
@@ -1287,7 +1287,7 @@ static int pager_delmaster(Pager *pPager, const char *zMaster){
goto delmaster_out;
}
}
- zJournal += (strlen(zJournal)+1);
+ zJournal += (sqlite3Strlen30(zJournal)+1);
}
}
@@ -1795,7 +1795,7 @@ int sqlite3PagerOpen(
sqlite3_free(zPathname);
return rc;
}
- nPathname = strlen(zPathname);
+ nPathname = sqlite3Strlen30(zPathname);
}
/* Allocate memory for the pager structure */
@@ -1903,7 +1903,8 @@ int sqlite3PagerOpen(
/* Fill in Pager.zDirectory[] */
memcpy(pPager->zDirectory, pPager->zFilename, nPathname+1);
- for(i=strlen(pPager->zDirectory); i>0 && pPager->zDirectory[i-1]!='/'; i--){}
+ for(i=sqlite3Strlen30(pPager->zDirectory);
+ i>0 && pPager->zDirectory[i-1]!='/'; i--){}
if( i>0 ) pPager->zDirectory[i-1] = 0;
/* Fill in Pager.zJournal[] */
@@ -2504,8 +2505,8 @@ static int pagerStress(void *p, PgHdr *pPg){
static int hasHotJournal(Pager *pPager, int *pExists){
sqlite3_vfs *pVfs = pPager->pVfs;
int rc = SQLITE_OK;
- int exists;
- int locked;
+ int exists = 0;
+ int locked = 0;
assert( pPager!=0 );
assert( pPager->useJournal );
assert( pPager->fd->pMethods );
diff --git a/src/pragma.c b/src/pragma.c
index 1fb07736f..9134e6c5d 100644
--- a/src/pragma.c
+++ b/src/pragma.c
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
-** $Id: pragma.c,v 1.196 2008/12/10 17:20:01 drh Exp $
+** $Id: pragma.c,v 1.197 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -40,7 +40,7 @@ static int getSafetyLevel(const char *z){
if( isdigit(*z) ){
return atoi(z);
}
- n = strlen(z);
+ n = sqlite3Strlen30(z);
for(i=0; i<ArraySize(iLength); i++){
if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0 ){
return iValue[i];
@@ -464,7 +464,7 @@ void sqlite3Pragma(
if( zRight==0 ){
eMode = PAGER_JOURNALMODE_QUERY;
}else{
- int n = strlen(zRight);
+ int n = sqlite3Strlen30(zRight);
eMode = sizeof(azModeName)/sizeof(azModeName[0]) - 1;
while( eMode>=0 && sqlite3StrNICmp(zRight, azModeName[eMode], n)!=0 ){
eMode--;
@@ -1345,7 +1345,7 @@ void sqlite3Pragma(
#if SQLITE_HAS_CODEC
if( sqlite3StrICmp(zLeft, "key")==0 ){
- sqlite3_key(db, zRight, strlen(zRight));
+ sqlite3_key(db, zRight, sqlite3Strlen30(zRight));
}else
#endif
#if SQLITE_HAS_CODEC || defined(SQLITE_ENABLE_CEROD)
diff --git a/src/prepare.c b/src/prepare.c
index d141cb6fe..a6eaddb1f 100644
--- a/src/prepare.c
+++ b/src/prepare.c
@@ -13,7 +13,7 @@
** interface, and routines that contribute to loading the database schema
** from disk.
**
-** $Id: prepare.c,v 1.102 2008/12/10 17:20:01 drh Exp $
+** $Id: prepare.c,v 1.103 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -295,7 +295,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
** file_format==3 Version 3.1.4. // ditto but with non-NULL defaults
** file_format==4 Version 3.3.0. // DESC indices. Boolean constants
*/
- pDb->pSchema->file_format = meta[1];
+ pDb->pSchema->file_format = (u8)meta[1];
if( pDb->pSchema->file_format==0 ){
pDb->pSchema->file_format = 1;
}
@@ -623,7 +623,7 @@ static int sqlite3Prepare(
}
if( saveSqlFlag ){
- sqlite3VdbeSetSql(sParse.pVdbe, zSql, sParse.zTail - zSql);
+ sqlite3VdbeSetSql(sParse.pVdbe, zSql, (int)(sParse.zTail - zSql));
}
if( rc!=SQLITE_OK || db->mallocFailed ){
sqlite3_finalize((sqlite3_stmt*)sParse.pVdbe);
@@ -766,7 +766,7 @@ static int sqlite3Prepare16(
** characters between zSql8 and zTail8, and then returning a pointer
** the same number of characters into the UTF-16 string.
*/
- int chars_parsed = sqlite3Utf8CharLen(zSql8, zTail8-zSql8);
+ int chars_parsed = sqlite3Utf8CharLen(zSql8, (int)(zTail8-zSql8));
*pzTail = (u8 *)zSql + sqlite3Utf16ByteLen(zSql, chars_parsed);
}
sqlite3DbFree(db, zSql8);
diff --git a/src/printf.c b/src/printf.c
index 6518ddb22..58e575be8 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -5,7 +5,7 @@
** an historical reference. Most of the "enhancements" have been backed
** out so that the functionality is now the same as standard printf().
**
-** $Id: printf.c,v 1.98 2008/12/10 18:03:46 drh Exp $
+** $Id: printf.c,v 1.99 2008/12/10 19:26:24 drh Exp $
**
**************************************************************************
**
@@ -156,7 +156,7 @@ static const et_info fmtinfo[] = {
** 16 (the number of significant digits in a 64-bit float) '0' is
** always returned.
*/
-static int et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){
+static char et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){
int digit;
LONGDOUBLE_TYPE d;
if( (*cnt)++ >= 16 ) return '0';
@@ -164,7 +164,7 @@ static int et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){
d = digit;
digit += '0';
*val = (*val - d)*10.0;
- return digit;
+ return (char)digit;
}
#endif /* SQLITE_OMIT_FLOATING_POINT */
@@ -413,7 +413,7 @@ void sqlite3VXPrintf(
bufpt = &buf[etBUFSIZE-1];
if( xtype==etORDINAL ){
static const char zOrd[] = "thstndrd";
- int x = longvalue % 10;
+ int x = (int)(longvalue % 10);
if( x>=4 || (longvalue/10)%10==1 ){
x = 0;
}
@@ -431,7 +431,7 @@ void sqlite3VXPrintf(
longvalue = longvalue/base;
}while( longvalue>0 );
}
- length = &buf[etBUFSIZE-1]-bufpt;
+ length = (int)(&buf[etBUFSIZE-1]-bufpt);
for(idx=precision-length; idx>0; idx--){
*(--bufpt) = '0'; /* Zero pad */
}
@@ -442,7 +442,7 @@ void sqlite3VXPrintf(
pre = &aPrefix[infop->prefix];
for(; (x=(*pre))!=0; pre++) *(--bufpt) = x;
}
- length = &buf[etBUFSIZE-1]-bufpt;
+ length = (int)(&buf[etBUFSIZE-1]-bufpt);
break;
case etFLOAT:
case etEXP:
@@ -470,7 +470,7 @@ void sqlite3VXPrintf(
if( xtype==etFLOAT ) realvalue += rounder;
/* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
exp = 0;
- if( sqlite3IsNaN(realvalue) ){
+ if( sqlite3IsNaN((double)realvalue) ){
bufpt = "NaN";
length = 3;
break;
@@ -489,7 +489,7 @@ void sqlite3VXPrintf(
}else{
bufpt = "Inf";
}
- length = strlen(bufpt);
+ length = sqlite3Strlen30(bufpt);
break;
}
}
@@ -520,7 +520,7 @@ void sqlite3VXPrintf(
e2 = exp;
}
nsd = 0;
- flag_dp = (precision>0) | flag_alternateform | flag_altform2;
+ flag_dp = (precision>0 ?1:0) | flag_alternateform | flag_altform2;
/* The sign in front of the number */
if( prefix ){
*(bufpt++) = prefix;
@@ -568,18 +568,18 @@ void sqlite3VXPrintf(
*(bufpt++) = '+';
}
if( exp>=100 ){
- *(bufpt++) = (exp/100)+'0'; /* 100's digit */
+ *(bufpt++) = (char)((exp/100)+'0'); /* 100's digit */
exp %= 100;
}
- *(bufpt++) = exp/10+'0'; /* 10's digit */
- *(bufpt++) = exp%10+'0'; /* 1's digit */
+ *(bufpt++) = (char)(exp/10+'0'); /* 10's digit */
+ *(bufpt++) = (char)(exp%10+'0'); /* 1's digit */
}
*bufpt = 0;
/* The converted number is in buf[] and zero terminated. Output it.
** Note that the number is in the usual order, not reversed as with
** integer conversions. */
- length = bufpt-buf;
+ length = (int)(bufpt-buf);
bufpt = buf;
/* Special case: Add leading zeros if the flag_zeropad flag is
@@ -606,9 +606,10 @@ void sqlite3VXPrintf(
length = 1;
break;
case etCHARX:
- c = buf[0] = va_arg(ap,int);
+ c = va_arg(ap,int);
+ buf[0] = (char)c;
if( precision>=0 ){
- for(idx=1; idx<precision; idx++) buf[idx] = c;
+ for(idx=1; idx<precision; idx++) buf[idx] = (char)c;
length = precision;
}else{
length =1;
@@ -626,14 +627,15 @@ void sqlite3VXPrintf(
if( precision>=0 ){
for(length=0; length<precision && bufpt[length]; length++){}
}else{
- length = strlen(bufpt);
+ length = sqlite3Strlen30(bufpt);
}
break;
case etSQLESCAPE:
case etSQLESCAPE2:
case etSQLESCAPE3: {
- int i, j, n, ch, isnull;
+ int i, j, n, isnull;
int needQuote;
+ char ch;
char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
char *escarg = va_arg(ap,char*);
isnull = escarg==0;
@@ -723,7 +725,7 @@ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
return;
}
if( N<0 ){
- N = strlen(z);
+ N = sqlite3Strlen30(z);
}
if( N==0 || z==0 ){
return;
@@ -744,7 +746,7 @@ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
p->tooBig = 1;
return;
}else{
- p->nAlloc = szNew;
+ p->nAlloc = (int)szNew;
}
zNew = sqlite3DbMallocRaw(p->db, p->nAlloc );
if( zNew ){
diff --git a/src/random.c b/src/random.c
index eb3ec1958..f90a34edf 100644
--- a/src/random.c
+++ b/src/random.c
@@ -15,7 +15,7 @@
** Random numbers are used by some of the database backends in order
** to generate random integer keys for tables or random filenames.
**
-** $Id: random.c,v 1.28 2008/12/08 18:19:18 drh Exp $
+** $Id: random.c,v 1.29 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
@@ -45,7 +45,7 @@ static SQLITE_WSD struct sqlite3PrngType {
** (Later): Actually, OP_NewRowid does not depend on a good source of
** randomness any more. But we will leave this code in all the same.
*/
-static int randomByte(void){
+static u8 randomByte(void){
unsigned char t;
@@ -79,7 +79,7 @@ static int randomByte(void){
wsdPrng.i = 0;
sqlite3OsRandomness(sqlite3_vfs_find(0), 256, k);
for(i=0; i<256; i++){
- wsdPrng.s[i] = i;
+ wsdPrng.s[i] = (u8)i;
}
for(i=0; i<256; i++){
wsdPrng.j += wsdPrng.s[i] + k[i];
diff --git a/src/resolve.c b/src/resolve.c
index 33b0335b5..d6f58fc70 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -14,7 +14,7 @@
** resolve all identifiers by associating them with a particular
** table and column.
**
-** $Id: resolve.c,v 1.14 2008/12/10 18:03:46 drh Exp $
+** $Id: resolve.c,v 1.15 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
#include <stdlib.h>
@@ -69,7 +69,7 @@ static void resolveAlias(
pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
if( pDup==0 ) return;
if( pEList->a[iCol].iAlias==0 ){
- pEList->a[iCol].iAlias = ++pParse->nAlias;
+ pEList->a[iCol].iAlias = (u16)(++pParse->nAlias);
}
pDup->iTable = pEList->a[iCol].iAlias;
}
@@ -483,7 +483,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
int nId; /* Number of characters in function name */
const char *zId; /* The function name. */
FuncDef *pDef; /* Information about the function */
- int enc = ENC(pParse->db); /* The database encoding */
+ u8 enc = ENC(pParse->db); /* The database encoding */
zId = (char*)pExpr->token.z;
nId = pExpr->token.n;
@@ -756,7 +756,7 @@ static int resolveCompoundOrderBy(
pE->pColl = pColl;
pE->flags |= EP_IntValue | flags;
pE->iTable = iCol;
- pItem->iCol = iCol;
+ pItem->iCol = (u16)iCol;
pItem->done = 1;
}else{
moreToDo = 1;
@@ -860,7 +860,7 @@ static int resolveOrderGroupBy(
** a copy of the iCol-th result-set column. The subsequent call to
** sqlite3ResolveOrderGroupBy() will convert the expression to a
** copy of the iCol-th result-set expression. */
- pItem->iCol = iCol;
+ pItem->iCol = (u16)iCol;
continue;
}
if( sqlite3ExprIsInteger(pE, &iCol) ){
@@ -871,7 +871,7 @@ static int resolveOrderGroupBy(
resolveOutOfRangeError(pParse, zType, i+1, nResult);
return 1;
}
- pItem->iCol = iCol;
+ pItem->iCol = (u16)iCol;
continue;
}
diff --git a/src/select.c b/src/select.c
index 3468c1fd3..ffb4be234 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.492 2008/12/10 18:03:46 drh Exp $
+** $Id: select.c,v 1.493 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
@@ -37,7 +37,7 @@ static void clearSelect(sqlite3 *db, Select *p){
** Initialize a SelectDest structure.
*/
void sqlite3SelectDestInit(SelectDest *pDest, int eDest, int iParm){
- pDest->eDest = eDest;
+ pDest->eDest = (u8)eDest;
pDest->iParm = iParm;
pDest->affinity = 0;
pDest->iMem = 0;
@@ -191,7 +191,7 @@ static int columnIndex(Table *pTab, const char *zCol){
*/
static void setToken(Token *p, const char *z){
p->z = (u8*)z;
- p->n = z ? strlen(z) : 0;
+ p->n = z ? sqlite3Strlen30(z) : 0;
p->dyn = 0;
}
@@ -220,13 +220,13 @@ static void setQuotedToken(Parse *pParse, Token *p, const char *z){
/* String contains " characters - copy and quote the string. */
p->z = (u8 *)sqlite3MPrintf(pParse->db, "\"%w\"", z);
if( p->z ){
- p->n = strlen((char *)p->z);
+ p->n = sqlite3Strlen30((char *)p->z);
p->dyn = 1;
}
}else{
/* String contains no " characters - copy the pointer. */
p->z = (u8*)z;
- p->n = (z2 - z);
+ p->n = (int)(z2 - z);
p->dyn = 0;
}
}
@@ -756,7 +756,7 @@ static KeyInfo *keyInfoFromExprList(Parse *pParse, ExprList *pList){
pInfo = sqlite3DbMallocZero(db, sizeof(*pInfo) + nExpr*(sizeof(CollSeq*)+1) );
if( pInfo ){
pInfo->aSortOrder = (u8*)&pInfo->aColl[nExpr];
- pInfo->nField = nExpr;
+ pInfo->nField = (u16)nExpr;
pInfo->enc = ENC(db);
pInfo->db = db;
for(i=0, pItem=pList->a; i<nExpr; i++, pItem++){
@@ -1195,7 +1195,7 @@ static int selectColumnsFromExprList(
/* Make sure the column name is unique. If the name is not unique,
** append a integer to the name so that it becomes unique.
*/
- nName = strlen(zName);
+ nName = sqlite3Strlen30(zName);
for(j=cnt=0; j<i; j++){
if( sqlite3StrICmp(aCol[j].zName, zName)==0 ){
char *zNewName;
@@ -1538,7 +1538,7 @@ static int multiSelect(
case TK_EXCEPT:
case TK_UNION: {
int unionTab; /* Cursor number of the temporary table holding result */
- int op = 0; /* One of the SRT_ operations to apply to self */
+ u8 op = 0; /* One of the SRT_ operations to apply to self */
int priorOp; /* The SRT_ operation to apply to prior selects */
Expr *pLimit, *pOffset; /* Saved values of p->nLimit and p->nOffset */
int addr;
@@ -1733,7 +1733,7 @@ static int multiSelect(
}
pKeyInfo->enc = ENC(db);
- pKeyInfo->nField = nCol;
+ pKeyInfo->nField = (u16)nCol;
for(i=0, apColl=pKeyInfo->aColl; i<nCol; i++, apColl++){
*apColl = multiSelectCollSeq(pParse, p, i);
@@ -2091,7 +2091,7 @@ static int multiSelectOrderBy(
pNew->flags |= EP_IntValue;
pNew->iTable = i;
pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew, 0);
- pOrderBy->a[nOrderBy++].iCol = i;
+ pOrderBy->a[nOrderBy++].iCol = (u16)i;
}
}
}
@@ -2114,7 +2114,7 @@ static int multiSelectOrderBy(
sqlite3DbMallocRaw(db, sizeof(*pKeyMerge)+nOrderBy*(sizeof(CollSeq*)+1));
if( pKeyMerge ){
pKeyMerge->aSortOrder = (u8*)&pKeyMerge->aColl[nOrderBy];
- pKeyMerge->nField = nOrderBy;
+ pKeyMerge->nField = (u16)nOrderBy;
pKeyMerge->enc = ENC(db);
for(i=0; i<nOrderBy; i++){
CollSeq *pColl;
@@ -2154,7 +2154,7 @@ static int multiSelectOrderBy(
sizeof(*pKeyDup) + nExpr*(sizeof(CollSeq*)+1) );
if( pKeyDup ){
pKeyDup->aSortOrder = (u8*)&pKeyDup->aColl[nExpr];
- pKeyDup->nField = nExpr;
+ pKeyDup->nField = (u16)nExpr;
pKeyDup->enc = ENC(db);
for(i=0; i<nExpr; i++){
pKeyDup->aColl[i] = multiSelectCollSeq(pParse, p, i);
@@ -2786,7 +2786,7 @@ static int flattenSubquery(
*/
for(pParent=p; pParent; pParent=pParent->pPrior, pSub=pSub->pPrior){
int nSubSrc;
- int jointype = 0;
+ u8 jointype = 0;
pSubSrc = pSub->pSrc; /* FROM clause of subquery */
nSubSrc = pSubSrc->nSrc; /* Number of terms in subquery FROM clause */
pSrc = pParent->pSrc; /* FROM clause of the outer query */
@@ -3430,7 +3430,7 @@ static void updateAccumulator(Parse *pParse, AggInfo *pAggInfo){
}
sqlite3VdbeAddOp4(v, OP_AggStep, 0, regAgg, pF->iMem,
(void*)pF->pFunc, P4_FUNCDEF);
- sqlite3VdbeChangeP5(v, nArg);
+ sqlite3VdbeChangeP5(v, (u8)nArg);
sqlite3ReleaseTempRange(pParse, regAgg, nArg);
sqlite3ExprCacheAffinityChange(pParse, regAgg, nArg);
if( addrNext ){
@@ -4014,7 +4014,7 @@ int sqlite3Select(
if( flag ){
pDel = pMinMax = sqlite3ExprListDup(db, p->pEList->a[0].pExpr->pList);
if( pMinMax && !db->mallocFailed ){
- pMinMax->a[0].sortOrder = flag!=WHERE_ORDERBY_MIN;
+ pMinMax->a[0].sortOrder = flag!=WHERE_ORDERBY_MIN ?1:0;
pMinMax->a[0].pExpr->op = TK_COLUMN;
}
}
diff --git a/src/shell.c b/src/shell.c
index 43c0cab50..3434dd437 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -12,7 +12,7 @@
** This file contains code to implement the "sqlite" command line
** utility for accessing SQLite databases.
**
-** $Id: shell.c,v 1.191 2008/12/08 18:27:31 drh Exp $
+** $Id: shell.c,v 1.192 2008/12/10 19:26:24 drh Exp $
*/
#include <stdlib.h>
#include <string.h>
@@ -363,6 +363,16 @@ static const char *modeDescr[] = {
#define ArraySize(X) (int)(sizeof(X)/sizeof(X[0]))
/*
+** Compute a string length that is limited to what can be stored in
+** lower 30 bits of a 32-bit signed integer.
+*/
+int sqlite3Strlen30(const char *z){
+ const char *z2 = z;
+ while( *z2 ){ z2++; }
+ return 0x3fffffff & (int)(z2 - z);
+}
+
+/*
** Output the given string as a quoted string using SQL quoting conventions.
*/
static void output_quoted_string(FILE *out, const char *z){
@@ -477,7 +487,7 @@ static void output_csv(struct callback_data *p, const char *z, int bSep){
fprintf(out,"%s",p->nullvalue);
}else{
int i;
- int nSep = strlen(p->separator);
+ int nSep = sqlite3Strlen30(p->separator);
for(i=0; z[i]; i++){
if( needCsvQuote[((unsigned char*)z)[i]]
|| (z[i]==p->separator[0] &&
@@ -525,7 +535,7 @@ static int callback(void *pArg, int nArg, char **azArg, char **azCol){
int w = 5;
if( azArg==0 ) break;
for(i=0; i<nArg; i++){
- int len = strlen(azCol[i] ? azCol[i] : "");
+ int len = sqlite3Strlen30(azCol[i] ? azCol[i] : "");
if( len>w ) w = len;
}
if( p->cnt++>0 ) fprintf(p->out,"\n");
@@ -546,9 +556,9 @@ static int callback(void *pArg, int nArg, char **azArg, char **azCol){
w = 0;
}
if( w<=0 ){
- w = strlen(azCol[i] ? azCol[i] : "");
+ w = sqlite3Strlen30(azCol[i] ? azCol[i] : "");
if( w<10 ) w = 10;
- n = strlen(azArg && azArg[i] ? azArg[i] : p->nullvalue);
+ n = sqlite3Strlen30(azArg && azArg[i] ? azArg[i] : p->nullvalue);
if( w<n ) w = n;
}
if( i<ArraySize(p->actualWidth) ){
@@ -580,8 +590,9 @@ static int callback(void *pArg, int nArg, char **azArg, char **azCol){
}else{
w = 10;
}
- if( p->mode==MODE_Explain && azArg[i] && strlen(azArg[i])>(unsigned)w ){
- w = strlen(azArg[i]);
+ if( p->mode==MODE_Explain && azArg[i] &&
+ sqlite3Strlen30(azArg[i])>w ){
+ w = sqlite3Strlen30(azArg[i]);
}
fprintf(p->out,"%-*.*s%s",w,w,
azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " ");
@@ -728,8 +739,8 @@ static void set_table_name(struct callback_data *p, const char *zName){
static char *appendText(char *zIn, char const *zAppend, char quote){
int len;
int i;
- int nAppend = strlen(zAppend);
- int nIn = (zIn?strlen(zIn):0);
+ int nAppend = sqlite3Strlen30(zAppend);
+ int nIn = (zIn?sqlite3Strlen30(zIn):0);
len = nAppend+nIn+1;
if( quote ){
@@ -896,7 +907,7 @@ static int run_schema_dump_query(
rc = sqlite3_exec(p->db, zQuery, dump_callback, p, pzErrMsg);
if( rc==SQLITE_CORRUPT ){
char *zQ2;
- int len = strlen(zQuery);
+ int len = sqlite3Strlen30(zQuery);
if( pzErrMsg ) sqlite3_free(*pzErrMsg);
zQ2 = malloc( len+100 );
if( zQ2==0 ) return rc;
@@ -1070,7 +1081,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
/* Process the input line.
*/
if( nArg==0 ) return rc;
- n = strlen(azArg[0]);
+ n = sqlite3Strlen30(azArg[0]);
c = azArg[0][0];
if( c=='b' && n>1 && strncmp(azArg[0], "bail", n)==0 && nArg>1 ){
bail_on_error = booleanValue(azArg[1]);
@@ -1208,14 +1219,14 @@ static int do_meta_command(char *zLine, struct callback_data *p){
int lineno = 0; /* Line number of input file */
open_db(p);
- nSep = strlen(p->separator);
+ nSep = sqlite3Strlen30(p->separator);
if( nSep==0 ){
fprintf(stderr, "non-null separator required for import\n");
return 0;
}
zSql = sqlite3_mprintf("SELECT * FROM '%q'", zTable);
if( zSql==0 ) return 0;
- nByte = strlen(zSql);
+ nByte = sqlite3Strlen30(zSql);
rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
sqlite3_free(zSql);
if( rc ){
@@ -1230,7 +1241,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
zSql = malloc( nByte + 20 + nCol*2 );
if( zSql==0 ) return 0;
sqlite3_snprintf(nByte+20, zSql, "INSERT INTO '%q' VALUES(?", zTable);
- j = strlen(zSql);
+ j = sqlite3Strlen30(zSql);
for(i=1; i<nCol; i++){
zSql[j++] = ',';
zSql[j++] = '?';
@@ -1363,7 +1374,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
#endif
if( c=='m' && strncmp(azArg[0], "mode", n)==0 && nArg>=2 ){
- int n2 = strlen(azArg[1]);
+ int n2 = sqlite3Strlen30(azArg[1]);
if( strncmp(azArg[1],"line",n2)==0
||
strncmp(azArg[1],"lines",n2)==0 ){
@@ -1521,7 +1532,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
output_c_string(p->out, p->nullvalue);
fprintf(p->out, "\n");
fprintf(p->out,"%9.9s: %s\n","output",
- strlen(p->outfile) ? p->outfile : "stdout");
+ sqlite3Strlen30(p->outfile) ? p->outfile : "stdout");
fprintf(p->out,"%9.9s: ", "separator");
output_c_string(p->out, p->separator);
fprintf(p->out, "\n");
@@ -1570,7 +1581,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
int nPrintCol, nPrintRow;
for(i=1; i<=nRow; i++){
if( azResult[i]==0 ) continue;
- len = strlen(azResult[i]);
+ len = sqlite3Strlen30(azResult[i]);
if( len>maxlen ) maxlen = len;
}
nPrintCol = 80/(maxlen+2);
@@ -1717,7 +1728,7 @@ static int process_input(struct callback_data *p, FILE *in){
int i;
for(i=0; zLine[i] && isspace((unsigned char)zLine[i]); i++){}
if( zLine[i]!=0 ){
- nSql = strlen(zLine);
+ nSql = sqlite3Strlen30(zLine);
zSql = malloc( nSql+1 );
if( zSql==0 ){
fprintf(stderr, "out of memory\n");
@@ -1727,7 +1738,7 @@ static int process_input(struct callback_data *p, FILE *in){
startline = lineno;
}
}else{
- int len = strlen(zLine);
+ int len = sqlite3Strlen30(zLine);
zSql = realloc( zSql, nSql + len + 2 );
if( zSql==0 ){
fprintf(stderr,"%s: out of memory!\n", Argv0);
@@ -1814,7 +1825,7 @@ static char *find_home_dir(void){
zDrive = getenv("HOMEDRIVE");
zPath = getenv("HOMEPATH");
if( zDrive && zPath ){
- n = strlen(zDrive) + strlen(zPath) + 1;
+ n = sqlite3Strlen30(zDrive) + sqlite3Strlen30(zPath) + 1;
home_dir = malloc( n );
if( home_dir==0 ) return 0;
sqlite3_snprintf(n, home_dir, "%s%s", zDrive, zPath);
@@ -1827,7 +1838,7 @@ static char *find_home_dir(void){
#endif /* !_WIN32_WCE */
if( home_dir ){
- int n = strlen(home_dir) + 1;
+ int n = sqlite3Strlen30(home_dir) + 1;
char *z = malloc( n );
if( z ) memcpy(z, home_dir, n);
home_dir = z;
@@ -1858,7 +1869,7 @@ static void process_sqliterc(
#endif
return;
}
- nBuf = strlen(home_dir) + 16;
+ nBuf = sqlite3Strlen30(home_dir) + 16;
zBuf = malloc( nBuf );
if( zBuf==0 ){
fprintf(stderr,"%s: out of memory!\n", Argv0);
@@ -2081,8 +2092,11 @@ int main(int argc, char **argv){
sqlite3_libversion()
);
zHome = find_home_dir();
- if( zHome && (zHistory = malloc(nHistory = strlen(zHome)+20))!=0 ){
- sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
+ if( zHome ){
+ nHistory = sqlite3Strlen30(zHome) + 20;
+ if( (zHistory = malloc(nHistory))!=0 ){
+ sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
+ }
}
#if defined(HAVE_READLINE) && HAVE_READLINE==1
if( zHistory ) read_history(zHistory);
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index ea558e19a..a4b764e51 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
-** @(#) $Id: sqliteInt.h,v 1.807 2008/12/09 13:04:29 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.808 2008/12/10 19:26:24 drh Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
@@ -2064,6 +2064,7 @@ int sqlite3StrICmp(const char *, const char *);
int sqlite3StrNICmp(const char *, const char *, int);
int sqlite3IsNumber(const char*, int*, u8);
int sqlite3Strlen(sqlite3*, const char*);
+int sqlite3Strlen30(const char*);
int sqlite3MallocInit(void);
void sqlite3MallocEnd(void);
diff --git a/src/table.c b/src/table.c
index 232e898d6..71d926e06 100644
--- a/src/table.c
+++ b/src/table.c
@@ -16,7 +16,7 @@
** These routines are in a separate files so that they will not be linked
** if they are not used.
**
-** $Id: table.c,v 1.37 2008/12/09 03:55:14 drh Exp $
+** $Id: table.c,v 1.38 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
#include <stdlib.h>
@@ -92,7 +92,7 @@ static int sqlite3_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
if( argv[i]==0 ){
z = 0;
}else{
- int n = (int)strlen(argv[i])+1;
+ int n = sqlite3Strlen30(argv[i])+1;
z = sqlite3_malloc( n );
if( z==0 ) goto malloc_failed;
memcpy(z, argv[i], n);
diff --git a/src/tclsqlite.c b/src/tclsqlite.c
index d94a9ae66..db31af6d0 100644
--- a/src/tclsqlite.c
+++ b/src/tclsqlite.c
@@ -12,7 +12,7 @@
** A TCL Interface to SQLite. Append this file to sqlite3.c and
** compile the whole thing to build a TCL-enabled version of SQLite.
**
-** $Id: tclsqlite.c,v 1.228 2008/10/09 14:45:26 drh Exp $
+** $Id: tclsqlite.c,v 1.229 2008/12/10 19:26:24 drh Exp $
*/
#include "tcl.h"
#include <errno.h>
@@ -129,6 +129,19 @@ struct IncrblobChannel {
IncrblobChannel *pPrev; /* Linked list of all open incrblob channels */
};
+#ifndef SQLITE_AMALGAMATION
+/*
+** Compute a string length that is limited to what can be stored in
+** lower 30 bits of a 32-bit signed integer.
+*/
+int sqlite3Strlen30(const char *z){
+ const char *z2 = z;
+ while( *z2 ){ z2++; }
+ return 0x3fffffff & (int)(z2 - z);
+}
+#endif
+
+
#ifndef SQLITE_OMIT_INCRBLOB
/*
** Close all incrblob channels opened using database connection pDb.
@@ -384,7 +397,7 @@ static int safeToUseEvalObjv(Tcl_Interp *interp, Tcl_Obj *pCmd){
static SqlFunc *findSqlFunc(SqliteDb *pDb, const char *zName){
SqlFunc *p, *pNew;
int i;
- pNew = (SqlFunc*)Tcl_Alloc( sizeof(*pNew) + strlen(zName) + 1 );
+ pNew = (SqlFunc*)Tcl_Alloc( sizeof(*pNew) + sqlite3Strlen30(zName) + 1 );
pNew->zName = (char*)&pNew[1];
for(i=0; zName[i]; i++){ pNew->zName[i] = tolower(zName[i]); }
pNew->zName[i] = 0;
@@ -1339,8 +1352,8 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
zConflict = Tcl_GetStringFromObj(objv[2], 0);
zTable = Tcl_GetStringFromObj(objv[3], 0);
zFile = Tcl_GetStringFromObj(objv[4], 0);
- nSep = strlen(zSep);
- nNull = strlen(zNull);
+ nSep = sqlite3Strlen30(zSep);
+ nNull = sqlite3Strlen30(zNull);
if( nSep==0 ){
Tcl_AppendResult(interp,"Error: non-null separator required for copy",0);
return TCL_ERROR;
@@ -1360,7 +1373,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
Tcl_AppendResult(interp, "Error: no such table: ", zTable, 0);
return TCL_ERROR;
}
- nByte = strlen(zSql);
+ nByte = sqlite3Strlen30(zSql);
rc = sqlite3_prepare(pDb->db, zSql, -1, &pStmt, 0);
sqlite3_free(zSql);
if( rc ){
@@ -1380,7 +1393,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
}
sqlite3_snprintf(nByte+50, zSql, "INSERT OR %q INTO '%q' VALUES(?",
zConflict, zTable);
- j = strlen(zSql);
+ j = sqlite3Strlen30(zSql);
for(i=1; i<nCol; i++){
zSql[j++] = ',';
zSql[j++] = '?';
@@ -1425,7 +1438,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
}
if( i+1!=nCol ){
char *zErr;
- int nErr = strlen(zFile) + 200;
+ int nErr = sqlite3Strlen30(zFile) + 200;
zErr = malloc(nErr);
if( zErr ){
sqlite3_snprintf(nErr, zErr,
@@ -1439,7 +1452,9 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
}
for(i=0; i<nCol; i++){
/* check for null data, if so, bind as null */
- if ((nNull>0 && strcmp(azCol[i], zNull)==0) || strlen(azCol[i])==0) {
+ if( (nNull>0 && strcmp(azCol[i], zNull)==0)
+ || sqlite3Strlen30(azCol[i])==0
+ ){
sqlite3_bind_null(pStmt, i+1);
}else{
sqlite3_bind_text(pStmt, i+1, azCol[i], -1, SQLITE_STATIC);
@@ -1580,7 +1595,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
** which matches the next sequence of SQL.
*/
pStmt = 0;
- len = strlen(zSql);
+ len = sqlite3Strlen30(zSql);
for(pPreStmt = pDb->stmtList; pPreStmt; pPreStmt=pPreStmt->pNext){
int n = pPreStmt->nSql;
if( len>=n
@@ -1833,7 +1848,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
pPreStmt->pStmt = pStmt;
pPreStmt->nSql = len;
pPreStmt->zSql = sqlite3_sql(pStmt);
- assert( strlen(pPreStmt->zSql)==len );
+ assert( sqlite3Strlen30(pPreStmt->zSql)==len );
assert( 0==memcmp(pPreStmt->zSql, zSql, len) );
}
@@ -1894,7 +1909,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
int nArg = -1;
if( objc==6 ){
const char *z = Tcl_GetString(objv[3]);
- int n = strlen(z);
+ int n = sqlite3Strlen30(z);
if( n>2 && strncmp(z, "-argcount",n)==0 ){
if( Tcl_GetIntFromObj(interp, objv[4], &nArg) ) return TCL_ERROR;
if( nArg<0 ){
diff --git a/src/trigger.c b/src/trigger.c
index 65e17e223..0f3595b47 100644
--- a/src/trigger.c
+++ b/src/trigger.c
@@ -10,7 +10,7 @@
*************************************************************************
**
**
-** $Id: trigger.c,v 1.131 2008/12/09 03:55:14 drh Exp $
+** $Id: trigger.c,v 1.132 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
@@ -119,7 +119,7 @@ void sqlite3BeginTrigger(
goto trigger_cleanup;
}
if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash),
- zName, (int)strlen(zName)) ){
+ zName, sqlite3Strlen30(zName)) ){
if( !noErr ){
sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);
}
@@ -256,13 +256,13 @@ void sqlite3FinishTrigger(
Table *pTab;
Trigger *pDel;
pDel = sqlite3HashInsert(&db->aDb[iDb].pSchema->trigHash,
- pTrig->name, (int)strlen(pTrig->name), pTrig);
+ pTrig->name, sqlite3Strlen30(pTrig->name), pTrig);
if( pDel ){
assert( pDel==pTrig );
db->mallocFailed = 1;
goto triggerfinish_cleanup;
}
- n = (int)strlen(pTrig->table) + 1;
+ n = sqlite3Strlen30(pTrig->table) + 1;
pTab = sqlite3HashFind(&pTrig->pTabSchema->tblHash, pTrig->table, n);
assert( pTab!=0 );
pTrig->pNext = pTab->pTrigger;
@@ -465,7 +465,7 @@ void sqlite3DropTrigger(Parse *pParse, SrcList *pName, int noErr){
assert( pName->nSrc==1 );
zDb = pName->a[0].zDatabase;
zName = pName->a[0].zName;
- nName = strlen(zName);
+ nName = sqlite3Strlen30(zName);
for(i=OMIT_TEMPDB; i<db->nDb; i++){
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
@@ -489,7 +489,7 @@ drop_trigger_cleanup:
** is set on.
*/
static Table *tableOfTrigger(Trigger *pTrigger){
- int n = (int)strlen(pTrigger->table) + 1;
+ int n = sqlite3Strlen30(pTrigger->table) + 1;
return sqlite3HashFind(&pTrigger->pTabSchema->tblHash, pTrigger->table, n);
}
@@ -554,7 +554,7 @@ void sqlite3DropTriggerPtr(Parse *pParse, Trigger *pTrigger){
*/
void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){
Trigger *pTrigger;
- int nName = (int)strlen(zName);
+ int nName = sqlite3Strlen30(zName);
pTrigger = sqlite3HashInsert(&(db->aDb[iDb].pSchema->trigHash),
zName, nName, 0);
if( pTrigger ){
@@ -645,7 +645,7 @@ static SrcList *targetSrcList(
if( iDb==0 || iDb>=2 ){
assert( iDb<pParse->db->nDb );
sDb.z = (u8*)pParse->db->aDb[iDb].zName;
- sDb.n = (int)strlen((char*)sDb.z);
+ sDb.n = sqlite3Strlen30((char*)sDb.z);
pSrc = sqlite3SrcListAppend(pParse->db, 0, &sDb, &pStep->target);
} else {
pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0);
diff --git a/src/utf.c b/src/utf.c
index d17f532cb..5fc8fb4a4 100644
--- a/src/utf.c
+++ b/src/utf.c
@@ -12,7 +12,7 @@
** This file contains routines used to translate between UTF-8,
** UTF-16, UTF-16BE, and UTF-16LE.
**
-** $Id: utf.c,v 1.68 2008/12/09 03:55:14 drh Exp $
+** $Id: utf.c,v 1.69 2008/12/10 19:26:24 drh Exp $
**
** Notes on UTF-8:
**
@@ -288,7 +288,7 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
WRITE_UTF16BE(z, c);
}
}
- pMem->n = z - zOut;
+ pMem->n = (int)(z - zOut);
*z++ = 0;
}else{
assert( desiredEnc==SQLITE_UTF8 );
@@ -407,7 +407,7 @@ int sqlite3Utf8CharLen(const char *zIn, int nByte){
int sqlite3Utf8To8(unsigned char *zIn){
unsigned char *zOut = zIn;
unsigned char *zStart = zIn;
- unsigned char *zTerm = &zIn[strlen((char *)zIn)];
+ unsigned char *zTerm = &zIn[sqlite3Strlen30((char *)zIn)];
u32 c;
while( zIn[0] ){
diff --git a/src/vdbe.c b/src/vdbe.c
index 84d95746b..92ec56b36 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -43,7 +43,7 @@
** 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.794 2008/12/10 18:03:47 drh Exp $
+** $Id: vdbe.c,v 1.795 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -370,12 +370,12 @@ void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf){
}
sqlite3_snprintf(100, zCsr, "%c", c);
- zCsr += strlen(zCsr);
+ zCsr += sqlite3Strlen30(zCsr);
sqlite3_snprintf(100, zCsr, "%d[", pMem->n);
- zCsr += strlen(zCsr);
+ zCsr += sqlite3Strlen30(zCsr);
for(i=0; i<16 && i<pMem->n; i++){
sqlite3_snprintf(100, zCsr, "%02X", ((int)pMem->z[i] & 0xFF));
- zCsr += strlen(zCsr);
+ zCsr += sqlite3Strlen30(zCsr);
}
for(i=0; i<16 && i<pMem->n; i++){
char z = pMem->z[i];
@@ -384,10 +384,10 @@ void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf){
}
sqlite3_snprintf(100, zCsr, "]%s", encnames[pMem->enc]);
- zCsr += strlen(zCsr);
+ zCsr += sqlite3Strlen30(zCsr);
if( f & MEM_Zero ){
sqlite3_snprintf(100, zCsr,"+%dz",pMem->u.nZero);
- zCsr += strlen(zCsr);
+ zCsr += sqlite3Strlen30(zCsr);
}
*zCsr = '\0';
}else if( f & MEM_Str ){
@@ -407,7 +407,7 @@ void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf){
}
k = 2;
sqlite3_snprintf(100, &zBuf[k], "%d", pMem->n);
- k += strlen(&zBuf[k]);
+ k += sqlite3Strlen30(&zBuf[k]);
zBuf[k++] = '[';
for(j=0; j<15 && j<pMem->n; j++){
u8 c = pMem->z[j];
@@ -419,7 +419,7 @@ void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf){
}
zBuf[k++] = ']';
sqlite3_snprintf(100,&zBuf[k], encnames[pMem->enc]);
- k += strlen(&zBuf[k]);
+ k += sqlite3Strlen30(&zBuf[k]);
zBuf[k++] = 0;
}
}
@@ -882,7 +882,7 @@ case OP_Real: { /* same as TK_FLOAT, out2-prerelease */
case OP_String8: { /* same as TK_STRING, out2-prerelease */
assert( pOp->p4.z!=0 );
pOp->opcode = OP_String;
- pOp->p1 = strlen(pOp->p4.z);
+ pOp->p1 = sqlite3Strlen30(pOp->p4.z);
#ifndef SQLITE_OMIT_UTF16
if( encoding!=SQLITE_UTF8 ){
diff --git a/src/vdbeaux.c b/src/vdbeaux.c
index aba2ef898..1dc25131d 100644
--- a/src/vdbeaux.c
+++ b/src/vdbeaux.c
@@ -14,7 +14,7 @@
** 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.425 2008/12/10 17:20:01 drh Exp $
+** $Id: vdbeaux.c,v 1.426 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -576,7 +576,7 @@ void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int n){
pOp->p4.p = (void*)zP4;
pOp->p4type = (signed char)n;
}else{
- if( n==0 ) n = (int)strlen(zP4);
+ if( n==0 ) n = sqlite3Strlen30(zP4);
pOp->p4.z = sqlite3DbStrNDup(p->db, zP4, n);
pOp->p4type = P4_DYNAMIC;
}
@@ -640,11 +640,11 @@ static char *displayP4(Op *pOp, char *zTemp, int nTemp){
int i, j;
KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
sqlite3_snprintf(nTemp, zTemp, "keyinfo(%d", pKeyInfo->nField);
- i = (int)strlen(zTemp);
+ i = sqlite3Strlen30(zTemp);
for(j=0; j<pKeyInfo->nField; j++){
CollSeq *pColl = pKeyInfo->aColl[j];
if( pColl ){
- int n = (int)strlen(pColl->zName);
+ int n = sqlite3Strlen30(pColl->zName);
if( i+n>nTemp-6 ){
memcpy(&zTemp[i],",...",4);
break;
@@ -878,7 +878,7 @@ int sqlite3VdbeList(
pMem->flags = MEM_Static|MEM_Str|MEM_Term;
pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */
assert( pMem->z!=0 );
- pMem->n = (int)strlen(pMem->z);
+ pMem->n = sqlite3Strlen30(pMem->z);
pMem->type = SQLITE_TEXT;
pMem->enc = SQLITE_UTF8;
pMem++;
@@ -911,7 +911,7 @@ int sqlite3VdbeList(
sqlite3VdbeMemSetStr(pMem, z, -1, SQLITE_UTF8, 0);
}else{
assert( pMem->z!=0 );
- pMem->n = (int)strlen(pMem->z);
+ pMem->n = sqlite3Strlen30(pMem->z);
pMem->enc = SQLITE_UTF8;
}
pMem->type = SQLITE_TEXT;
@@ -933,7 +933,7 @@ int sqlite3VdbeList(
if( pOp->zComment ){
pMem->flags = MEM_Str|MEM_Term;
pMem->z = pOp->zComment;
- pMem->n = (int)strlen(pMem->z);
+ pMem->n = sqlite3Strlen30(pMem->z);
pMem->enc = SQLITE_UTF8;
pMem->type = SQLITE_TEXT;
}else
@@ -1293,7 +1293,9 @@ static int vdbeCommit(sqlite3 *db, Vdbe *p){
** that case we do not support atomic multi-file commits, so use the
** simple case then too.
*/
- if( 0==strlen(sqlite3BtreeGetFilename(db->aDb[0].pBt)) || nTrans<=1 ){
+ if( 0==sqlite3Strlen30(sqlite3BtreeGetFilename(db->aDb[0].pBt))
+ || nTrans<=1
+ ){
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
Btree *pBt = db->aDb[i].pBt;
if( pBt ){
@@ -1369,8 +1371,8 @@ static int vdbeCommit(sqlite3 *db, Vdbe *p){
if( !needSync && !sqlite3BtreeSyncDisabled(pBt) ){
needSync = 1;
}
- rc = sqlite3OsWrite(pMaster, zFile, (int)strlen(zFile)+1, offset);
- offset += strlen(zFile)+1;
+ rc = sqlite3OsWrite(pMaster, zFile, sqlite3Strlen30(zFile)+1, offset);
+ offset += sqlite3Strlen30(zFile)+1;
if( rc!=SQLITE_OK ){
sqlite3OsCloseFree(pMaster);
sqlite3OsDelete(pVfs, zMaster, 0);
diff --git a/src/vdbemem.c b/src/vdbemem.c
index 466c24da9..6c586a703 100644
--- a/src/vdbemem.c
+++ b/src/vdbemem.c
@@ -15,7 +15,7 @@
** only within the VDBE. Interface routines refer to a Mem using the
** name sqlite_value
**
-** $Id: vdbemem.c,v 1.132 2008/12/10 18:03:47 drh Exp $
+** $Id: vdbemem.c,v 1.133 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -228,7 +228,7 @@ int sqlite3VdbeMemStringify(Mem *pMem, int enc){
assert( fg & MEM_Real );
sqlite3_snprintf(nByte, pMem->z, "%!.15g", pMem->r);
}
- pMem->n = (int)strlen(pMem->z);
+ pMem->n = sqlite3Strlen30(pMem->z);
pMem->enc = SQLITE_UTF8;
pMem->flags |= MEM_Str|MEM_Term;
sqlite3VdbeChangeEncoding(pMem, enc);
@@ -898,11 +898,11 @@ void sqlite3VdbeMemSanity(Mem *pMem){
/* If the string is UTF-8 encoded and nul terminated, then pMem->n
** must be the length of the string. (Later:) If the database file
** has been corrupted, '\000' characters might have been inserted
- ** into the middle of the string. In that case, the strlen() might
- ** be less.
+ ** into the middle of the string. In that case, the sqlite3Strlen30()
+ ** might be less.
*/
if( pMem->enc==SQLITE_UTF8 && (flags & MEM_Term) ){
- assert( strlen(pMem->z)<=pMem->n );
+ assert( sqlite3Strlen30(pMem->z)<=pMem->n );
assert( pMem->z[pMem->n]==0 );
}
}
diff --git a/src/vtab.c b/src/vtab.c
index ee7bb30ef..83c4a3395 100644
--- a/src/vtab.c
+++ b/src/vtab.c
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to help implement virtual tables.
**
-** $Id: vtab.c,v 1.80 2008/12/10 18:03:47 drh Exp $
+** $Id: vtab.c,v 1.81 2008/12/10 19:26:24 drh Exp $
*/
#ifndef SQLITE_OMIT_VIRTUALTABLE
#include "sqliteInt.h"
@@ -27,7 +27,7 @@ static int createModule(
Module *pMod;
sqlite3_mutex_enter(db->mutex);
- nName = (int)strlen(zName);
+ nName = sqlite3Strlen30(zName);
pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1);
if( pMod ){
Module *pDel;
@@ -241,7 +241,8 @@ void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){
db = pParse->db;
if( pTab->nModuleArg<1 ) return;
zModule = pTab->azModuleArg[0];
- pMod = (Module*)sqlite3HashFind(&db->aModule, zModule, (int)strlen(zModule));
+ pMod = (Module*)sqlite3HashFind(&db->aModule, zModule,
+ sqlite3Strlen30(zModule));
pTab->pMod = pMod;
/* If the CREATE VIRTUAL TABLE statement is being entered for the
@@ -289,7 +290,7 @@ void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){
zWhere = sqlite3MPrintf(db, "name='%q'", pTab->zName);
sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 1, 0, zWhere, P4_DYNAMIC);
sqlite3VdbeAddOp4(v, OP_VCreate, iDb, 0, 0,
- pTab->zName, (int)strlen(pTab->zName) + 1);
+ pTab->zName, sqlite3Strlen30(pTab->zName) + 1);
}
/* If we are rereading the sqlite_master table create the in-memory
@@ -300,7 +301,7 @@ void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){
Table *pOld;
Schema *pSchema = pTab->pSchema;
const char *zName = pTab->zName;
- int nName = (int)strlen(zName) + 1;
+ int nName = sqlite3Strlen30(zName) + 1;
pOld = sqlite3HashInsert(&pSchema->tblHash, zName, nName, pTab);
if( pOld ){
db->mallocFailed = 1;
@@ -405,7 +406,7 @@ static int vtabCallConstructor(
int nType;
int i = 0;
if( !zType ) continue;
- nType = (int)strlen(zType);
+ nType = sqlite3Strlen30(zType);
if( sqlite3StrNICmp("hidden", zType, 6) || (zType[6] && zType[6]!=' ') ){
for(i=0; i<nType; i++){
if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7))
@@ -804,13 +805,14 @@ FuncDef *sqlite3VtabOverloadFunction(
/* Create a new ephemeral function definition for the overloaded
** function */
- pNew = sqlite3DbMallocZero(db, sizeof(*pNew) + (int)strlen(pDef->zName) );
+ pNew = sqlite3DbMallocZero(db, sizeof(*pNew)
+ + sqlite3Strlen30(pDef->zName) );
if( pNew==0 ){
return pDef;
}
*pNew = *pDef;
pNew->zName = (char *)&pNew[1];
- memcpy(pNew->zName, pDef->zName, strlen(pDef->zName)+1);
+ memcpy(pNew->zName, pDef->zName, sqlite3Strlen30(pDef->zName)+1);
pNew->xFunc = xFunc;
pNew->pUserData = pArg;
pNew->flags |= SQLITE_FUNC_EPHEM;
diff --git a/src/where.c b/src/where.c
index 93a932b5d..120246e47 100644
--- a/src/where.c
+++ b/src/where.c
@@ -16,7 +16,7 @@
** so is applicable. Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer".
**
-** $Id: where.c,v 1.335 2008/12/09 01:32:03 drh Exp $
+** $Id: where.c,v 1.336 2008/12/10 19:26:24 drh Exp $
*/
#include "sqliteInt.h"
@@ -2801,7 +2801,7 @@ WhereInfo *sqlite3WhereBegin(
pTabItem = &pTabList->a[pLevel->iFrom];
z = pTabItem->zAlias;
if( z==0 ) z = pTabItem->pTab->zName;
- n = strlen(z);
+ n = sqlite3Strlen30(z);
if( n+nQPlan < sizeof(sqlite3_query_plan)-10 ){
if( pLevel->wsFlags & WHERE_IDX_ONLY ){
memcpy(&sqlite3_query_plan[nQPlan], "{}", 2);
@@ -2821,7 +2821,7 @@ WhereInfo *sqlite3WhereBegin(
memcpy(&sqlite3_query_plan[nQPlan], "{} ", 3);
nQPlan += 3;
}else{
- n = strlen(pLevel->pIdx->zName);
+ n = sqlite3Strlen30(pLevel->pIdx->zName);
if( n+nQPlan < sizeof(sqlite3_query_plan)-2 ){
memcpy(&sqlite3_query_plan[nQPlan], pLevel->pIdx->zName, n);
nQPlan += n;