From 0c8cda6e0dcb1c9173710ac060b69fdbfb9c1a27 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 22 Dec 2011 15:30:46 +0000 Subject: [PATCH 1/4] Fix a problem in fts3_write.c causing stack memory to be referenced after it is out of scope. FossilOrigin-Name: f9c4a7c8f4e5821b47c1393d6272e32416d8886c --- ext/fts3/fts3_write.c | 11 ++++++++--- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ext/fts3/fts3_write.c b/ext/fts3/fts3_write.c index 2904a9acaa..fe9f26cf3e 100644 --- a/ext/fts3/fts3_write.c +++ b/ext/fts3/fts3_write.c @@ -1470,6 +1470,7 @@ int sqlite3Fts3SegReaderPending( Fts3SegReader **ppReader /* OUT: SegReader for pending-terms */ ){ Fts3SegReader *pReader = 0; /* Fts3SegReader object to return */ + Fts3HashElem *pE; /* Iterator variable */ Fts3HashElem **aElem = 0; /* Array of term hash entries to scan */ int nElem = 0; /* Size of array at aElem */ int rc = SQLITE_OK; /* Return Code */ @@ -1478,7 +1479,6 @@ int sqlite3Fts3SegReaderPending( pHash = &p->aIndex[iIndex].hPending; if( bPrefix ){ int nAlloc = 0; /* Size of allocated array at aElem */ - Fts3HashElem *pE = 0; /* Iterator variable */ for(pE=fts3HashFirst(pHash); pE; pE=fts3HashNext(pE)){ char *zKey = (char *)fts3HashKey(pE); @@ -1512,8 +1512,13 @@ int sqlite3Fts3SegReaderPending( }else{ /* The query is a simple term lookup that matches at most one term in - ** the index. All that is required is a straight hash-lookup. */ - Fts3HashElem *pE = fts3HashFindElem(pHash, zTerm, nTerm); + ** the index. All that is required is a straight hash-lookup. + ** + ** Because the stack address of pE may be accessed via the aElem pointer + ** below, the "Fts3HashElem *pE" must be declared so that it is valid + ** within this entire function, not just this "else{...}" block. + */ + pE = fts3HashFindElem(pHash, zTerm, nTerm); if( pE ){ aElem = &pE; nElem = 1; diff --git a/manifest b/manifest index bbe5f09d73..bcb25f1287 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sother\sproblems\swhere\s32-bit\sinteger\soverflow\smay\scause\sa\sproblem.\sTwo\sthat\srequire\san\simprobably\slarge\ssub-journal\sand\stwo\sin\stest\sharness\scode. -D 2011-12-21T18:04:41.417 +C Fix\sa\sproblem\sin\sfts3_write.c\scausing\sstack\smemory\sto\sbe\sreferenced\safter\sit\sis\sout\sof\sscope. +D 2011-12-22T15:30:46.102 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5b4a3e12a850b021547e43daf886b25133b44c07 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -78,7 +78,7 @@ F ext/fts3/fts3_test.c 24fa13f330db011500acb95590da9eee24951894 F ext/fts3/fts3_tokenizer.c 9ff7ec66ae3c5c0340fa081958e64f395c71a106 F ext/fts3/fts3_tokenizer.h 13ffd9fcb397fec32a05ef5cd9e0fa659bf3dbd3 F ext/fts3/fts3_tokenizer1.c 0dde8f307b8045565cf63797ba9acfaff1c50c68 -F ext/fts3/fts3_write.c c097228bff4d33c6b8a270c9717b9f8339068776 +F ext/fts3/fts3_write.c fb1998be659ff85b7045513ab625bbdcf9b804d8 F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9 F ext/fts3/mkfts3amal.tcl 252ecb7fe6467854f2aa237bf2c390b74e71f100 F ext/icu/README.txt bf8461d8cdc6b8f514c080e4e10dc3b2bbdfefa9 @@ -985,7 +985,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P c5256b59ad70104c1e181b9f49d1d712cf4cc9f6 -R 67d063070f0e350ae5f59b7b697ace26 +P c723e3e18a008922281d8d6e8e3aba07941eb173 +R a473dabc4c74a83ea005d83d596de923 U dan -Z bef61bfcf61cf3a9e556e6b3194dc0ce +Z 9db758f12d3cf045a211ef0d51186bd2 diff --git a/manifest.uuid b/manifest.uuid index 0d2903da39..0edb2fd4a3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c723e3e18a008922281d8d6e8e3aba07941eb173 \ No newline at end of file +f9c4a7c8f4e5821b47c1393d6272e32416d8886c \ No newline at end of file From de0f18154e0a1b71740eb67298442cb5b9805484 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 22 Dec 2011 17:10:35 +0000 Subject: [PATCH 2/4] Check the return code from sqlite3_initialize() called from within sqlite3_soft_heap_limit64() and return an error from sqlite3_soft_heap_limit64() if sqlite3_initialize() fails. FossilOrigin-Name: 676acce274fec692a1eb34d27ee4b1327b4b3334 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/malloc.c | 3 ++- src/sqlite.h.in | 3 ++- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index bcb25f1287..384275d8e0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\sin\sfts3_write.c\scausing\sstack\smemory\sto\sbe\sreferenced\safter\sit\sis\sout\sof\sscope. -D 2011-12-22T15:30:46.102 +C Check\sthe\sreturn\scode\sfrom\ssqlite3_initialize()\scalled\sfrom\swithin\nsqlite3_soft_heap_limit64()\sand\sreturn\san\serror\sfrom\ssqlite3_soft_heap_limit64()\nif\ssqlite3_initialize()\sfails. +D 2011-12-22T17:10:35.691 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5b4a3e12a850b021547e43daf886b25133b44c07 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -148,7 +148,7 @@ F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f F src/lempar.c 0ee69fca0be54cd93939df98d2aca4ca46f44416 F src/loadext.c f20382fbaeec832438a1ba7797bee3d3c8a6d51d F src/main.c c837e24182e8ec7121c61e44f547b59cbe413e7f -F src/malloc.c 591aedb20ae40813f1045f2ef253438a334775d9 +F src/malloc.c 15afac5e59b6584efe072e9933aefb4230e74f97 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 7998e7003a3047e323c849a26dda004debc04d03 F src/mem2.c e307323e86b5da1853d7111b68fd6b84ad6f09cf @@ -182,7 +182,7 @@ F src/resolve.c 3d3e80a98f203ac6b9329e9621e29eda85ddfd40 F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697 F src/select.c a1d075db66a0ea42807353501b62997969e5be79 F src/shell.c aa4183d4a5243d8110b1d3d77faa4aea7e9c9c2d -F src/sqlite.h.in e3e45b5c69ab3236c7ec4591a5858221863cecd4 +F src/sqlite.h.in e884dffa91721080e1792e73a2260485c9d2ffc1 F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477 F src/sqliteInt.h 165409fa8adc8701148830804febeded3f2e4448 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d @@ -985,7 +985,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P c723e3e18a008922281d8d6e8e3aba07941eb173 -R a473dabc4c74a83ea005d83d596de923 -U dan -Z 9db758f12d3cf045a211ef0d51186bd2 +P f9c4a7c8f4e5821b47c1393d6272e32416d8886c +R 362f49b95b21624f3aae30c0009ec92f +U drh +Z 1c719257426fd1979e90548de4947ab1 diff --git a/manifest.uuid b/manifest.uuid index 0edb2fd4a3..1abc503440 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f9c4a7c8f4e5821b47c1393d6272e32416d8886c \ No newline at end of file +676acce274fec692a1eb34d27ee4b1327b4b3334 \ No newline at end of file diff --git a/src/malloc.c b/src/malloc.c index 3e38d1df9f..29c6b0dcd0 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -130,7 +130,8 @@ sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 n){ sqlite3_int64 priorLimit; sqlite3_int64 excess; #ifndef SQLITE_OMIT_AUTOINIT - sqlite3_initialize(); + int rc = sqlite3_initialize(); + if( rc ) return -1; #endif sqlite3_mutex_enter(mem0.mutex); priorLimit = mem0.alarmThreshold; diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 0e0e3af6b6..5bb1cb5323 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -4608,7 +4608,8 @@ int sqlite3_db_release_memory(sqlite3*); ** is advisory only. ** ** ^The return value from sqlite3_soft_heap_limit64() is the size of -** the soft heap limit prior to the call. ^If the argument N is negative +** the soft heap limit prior to the call, or negative in the case of an +** error. ^If the argument N is negative ** then no change is made to the soft heap limit. Hence, the current ** size of the soft heap limit can be determined by invoking ** sqlite3_soft_heap_limit64() with a negative argument. From 64803bd2fabfb0316577dee1f2173e5baba19879 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 22 Dec 2011 17:31:17 +0000 Subject: [PATCH 3/4] Fix minor issues with FTS and RTREE discovered by coverity. FossilOrigin-Name: 1c27d842163e27c39bbe9409f50657b9de9ade6e --- ext/fts3/fts3_write.c | 10 ++-------- ext/rtree/rtree.c | 2 +- manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/ext/fts3/fts3_write.c b/ext/fts3/fts3_write.c index fe9f26cf3e..0ee7ea81f1 100644 --- a/ext/fts3/fts3_write.c +++ b/ext/fts3/fts3_write.c @@ -1386,7 +1386,6 @@ int sqlite3Fts3SegReaderNew( int nRoot, /* Size of buffer containing root node */ Fts3SegReader **ppReader /* OUT: Allocated Fts3SegReader */ ){ - int rc = SQLITE_OK; /* Return code */ Fts3SegReader *pReader; /* Newly allocated SegReader object */ int nExtra = 0; /* Bytes to allocate segment root node */ @@ -1414,13 +1413,8 @@ int sqlite3Fts3SegReaderNew( }else{ pReader->iCurrentBlock = iStartLeaf-1; } - - if( rc==SQLITE_OK ){ - *ppReader = pReader; - }else{ - sqlite3Fts3SegReaderFree(pReader); - } - return rc; + *ppReader = pReader; + return SQLITE_OK; } /* diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index 884482ea66..4c36f26171 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -1193,7 +1193,7 @@ static int deserializeGeometry(sqlite3_value *pValue, RtreeConstraint *pCons){ int nBlob; /* Check that value is actually a blob. */ - if( !sqlite3_value_type(pValue)==SQLITE_BLOB ) return SQLITE_ERROR; + if( sqlite3_value_type(pValue)!=SQLITE_BLOB ) return SQLITE_ERROR; /* Check that the blob is roughly the right size. */ nBlob = sqlite3_value_bytes(pValue); diff --git a/manifest b/manifest index 384275d8e0..1d52fc8814 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Check\sthe\sreturn\scode\sfrom\ssqlite3_initialize()\scalled\sfrom\swithin\nsqlite3_soft_heap_limit64()\sand\sreturn\san\serror\sfrom\ssqlite3_soft_heap_limit64()\nif\ssqlite3_initialize()\sfails. -D 2011-12-22T17:10:35.691 +C Fix\sminor\sissues\swith\sFTS\sand\sRTREE\sdiscovered\sby\scoverity. +D 2011-12-22T17:31:17.125 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5b4a3e12a850b021547e43daf886b25133b44c07 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -78,14 +78,14 @@ F ext/fts3/fts3_test.c 24fa13f330db011500acb95590da9eee24951894 F ext/fts3/fts3_tokenizer.c 9ff7ec66ae3c5c0340fa081958e64f395c71a106 F ext/fts3/fts3_tokenizer.h 13ffd9fcb397fec32a05ef5cd9e0fa659bf3dbd3 F ext/fts3/fts3_tokenizer1.c 0dde8f307b8045565cf63797ba9acfaff1c50c68 -F ext/fts3/fts3_write.c fb1998be659ff85b7045513ab625bbdcf9b804d8 +F ext/fts3/fts3_write.c fdf0c99830360146ec7128150271c8c014a8fef7 F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9 F ext/fts3/mkfts3amal.tcl 252ecb7fe6467854f2aa237bf2c390b74e71f100 F ext/icu/README.txt bf8461d8cdc6b8f514c080e4e10dc3b2bbdfefa9 F ext/icu/icu.c eb9ae1d79046bd7871aa97ee6da51eb770134b5a F ext/icu/sqliteicu.h 728867a802baa5a96de7495e9689a8e01715ef37 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 -F ext/rtree/rtree.c 692e9192d148f318b3dca9f744600346a175eedd +F ext/rtree/rtree.c b92ab2e91e35c4964644647322813419c65fe1ce F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e F ext/rtree/rtree1.test 28e1b8da4da98093ce3210187434dd760a8d89d8 F ext/rtree/rtree2.test acbb3a4ce0f4fbc2c304d2b4b784cfa161856bba @@ -985,7 +985,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P f9c4a7c8f4e5821b47c1393d6272e32416d8886c -R 362f49b95b21624f3aae30c0009ec92f +P 676acce274fec692a1eb34d27ee4b1327b4b3334 +R 8a1d21156d0abc4e02d468720492bfd4 U drh -Z 1c719257426fd1979e90548de4947ab1 +Z d6b64802c9259af408f51c1ca44ff382 diff --git a/manifest.uuid b/manifest.uuid index 1abc503440..fbfcdbf0a5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -676acce274fec692a1eb34d27ee4b1327b4b3334 \ No newline at end of file +1c27d842163e27c39bbe9409f50657b9de9ade6e \ No newline at end of file From 9291372094ec5dfa66fb9ca67171a7d9c7b4ceba Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 23 Dec 2011 00:07:33 +0000 Subject: [PATCH 4/4] Add interfaces sqlite3_uri_boolean() and sqlite3_uri_int64() which are wrappers around sqlite3_uri_parameter() combined with internal routines for converting strings to booleans and 64-bit integers. FossilOrigin-Name: 83d26b9a9115eadac9e59a33d608bca0ab2519e3 --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/main.c | 25 +++++++++++++++++++++++++ src/os_unix.c | 4 +--- src/sqlite.h.in | 36 ++++++++++++++++++++++++++---------- src/test_multiplex.c | 28 ++++++---------------------- src/util.c | 4 +--- 7 files changed, 70 insertions(+), 49 deletions(-) diff --git a/manifest b/manifest index 1d52fc8814..2f08ae4c31 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sminor\sissues\swith\sFTS\sand\sRTREE\sdiscovered\sby\scoverity. -D 2011-12-22T17:31:17.125 +C Add\sinterfaces\ssqlite3_uri_boolean()\sand\ssqlite3_uri_int64()\swhich\sare\nwrappers\saround\ssqlite3_uri_parameter()\scombined\swith\sinternal\sroutines\sfor\nconverting\sstrings\sto\sbooleans\sand\s64-bit\sintegers. +D 2011-12-23T00:07:33.075 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5b4a3e12a850b021547e43daf886b25133b44c07 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -147,7 +147,7 @@ F src/journal.c 552839e54d1bf76fb8f7abe51868b66acacf6a0e F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f F src/lempar.c 0ee69fca0be54cd93939df98d2aca4ca46f44416 F src/loadext.c f20382fbaeec832438a1ba7797bee3d3c8a6d51d -F src/main.c c837e24182e8ec7121c61e44f547b59cbe413e7f +F src/main.c e2e3fb34be05658f41ac65ee5d9a44e00a358b48 F src/malloc.c 15afac5e59b6584efe072e9933aefb4230e74f97 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 7998e7003a3047e323c849a26dda004debc04d03 @@ -166,7 +166,7 @@ F src/os.c 28bbdab2170dfce84d86c45456a18eab1d0f99a9 F src/os.h 549b1a2e5e0ed1e1499f252dac126c4973e7379c F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_os2.c 4a75888ba3dfc820ad5e8177025972d74d7f2440 -F src/os_unix.c 7dc7df10331942b139032328449a3723e051979e +F src/os_unix.c ee4ea557de196798bafba1ac69f76a755035ebbb F src/os_win.c 197d23ce8a0dff748e766e034bf95ff756dd3884 F src/pager.c 523c64f6ca707e820d5cf10ed8371238ecac8333 F src/pager.h 5cd760857707529b403837d813d86b68938d6183 @@ -182,7 +182,7 @@ F src/resolve.c 3d3e80a98f203ac6b9329e9621e29eda85ddfd40 F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697 F src/select.c a1d075db66a0ea42807353501b62997969e5be79 F src/shell.c aa4183d4a5243d8110b1d3d77faa4aea7e9c9c2d -F src/sqlite.h.in e884dffa91721080e1792e73a2260485c9d2ffc1 +F src/sqlite.h.in db834f87316a1422051a97cba5beac31c0cb1b2d F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477 F src/sqliteInt.h 165409fa8adc8701148830804febeded3f2e4448 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d @@ -214,7 +214,7 @@ F src/test_intarray.h 489edb9068bb926583445cb02589344961054207 F src/test_journal.c 2c06e4be6584d51b935dc8b353980a9388de62ef F src/test_loadext.c df586c27176e3c2cb2e099c78da67bf14379a56e F src/test_malloc.c 8d416f29ad8573f32601f6056c9d2b17472e9ad5 -F src/test_multiplex.c 6e07b94e2fe430f7f4f0d7d67b5e58f504dea655 +F src/test_multiplex.c 7a41891cda4c6b43298656d88e37e3c6244a90ff F src/test_multiplex.h e99c571bc4968b7a9363b661481f3934bfead61d F src/test_mutex.c a6bd7b9cf6e19d989e31392b06ac8d189f0d573e F src/test_onefile.c 40cf9e212a377a6511469384a64b01e6e34b2eec @@ -238,7 +238,7 @@ F src/tokenize.c c819d9f72168a035d545a5bdafe9b085b20df705 F src/trigger.c ee7e178fb9188f44b532cebd449a7c1df90fb684 F src/update.c d3076782c887c10e882996550345da9c4c9f9dea F src/utf.c 890c67dcfcc7a74623c95baac7535aadfe265e84 -F src/util.c 343508d359df65685b62e63964a40e7af4cfbe05 +F src/util.c 19ae3ee0dfa88e6054838afc5920327c5918fa2b F src/vacuum.c 0c0ba2242355c6048d65e2b333abe0f7c06348fa F src/vdbe.c 029add0c5197a61db588824a58570547330b9d8f F src/vdbe.h 18f581cac1f4339ec3299f3e0cc6e11aec654cdb @@ -985,7 +985,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P 676acce274fec692a1eb34d27ee4b1327b4b3334 -R 8a1d21156d0abc4e02d468720492bfd4 +P 1c27d842163e27c39bbe9409f50657b9de9ade6e +R 712ad6ea662046687d3fa2e6906d477a U drh -Z d6b64802c9259af408f51c1ca44ff382 +Z dfef488f9835a38d5955098b906ef223 diff --git a/manifest.uuid b/manifest.uuid index fbfcdbf0a5..0daedf9dab 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1c27d842163e27c39bbe9409f50657b9de9ade6e \ No newline at end of file +83d26b9a9115eadac9e59a33d608bca0ab2519e3 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 690b73c2e7..94ea2fa2e5 100644 --- a/src/main.c +++ b/src/main.c @@ -2977,6 +2977,7 @@ int sqlite3_test_control(int op, ...){ ** returns a NULL pointer. */ const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){ + if( zFilename==0 ) return 0; zFilename += sqlite3Strlen30(zFilename) + 1; while( zFilename[0] ){ int x = strcmp(zFilename, zParam); @@ -2987,6 +2988,30 @@ const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){ return 0; } +/* +** Return a boolean value for a query parameter. +*/ +int sqlite3_uri_boolean(const char *zFilename, const char *zParam, int bDflt){ + const char *z = sqlite3_uri_parameter(zFilename, zParam); + return z ? sqlite3GetBoolean(z) : (bDflt!=0); +} + +/* +** Return a 64-bit integer value for a query parameter. +*/ +sqlite3_int64 sqlite3_uri_int64( + const char *zFilename, /* Filename as passed to xOpen */ + const char *zParam, /* URI parameter sought */ + sqlite3_int64 bDflt /* return if parameter is missing */ +){ + const char *z = sqlite3_uri_parameter(zFilename, zParam); + sqlite3_int64 v; + if( z && sqlite3Atoi64(z, &v, sqlite3Strlen30(z), SQLITE_UTF8)==SQLITE_OK ){ + bDflt = v; + } + return bDflt; +} + /* ** Return the filename of the database associated with a database ** connection. diff --git a/src/os_unix.c b/src/os_unix.c index ee5971f10e..5f26017b02 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -3866,10 +3866,8 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ } if( pInode->bProcessLock==0 ){ - const char *zRO; int openFlags = O_RDWR | O_CREAT; - zRO = sqlite3_uri_parameter(pDbFd->zPath, "readonly_shm"); - if( zRO && sqlite3GetBoolean(zRO) ){ + if( sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){ openFlags = O_RDONLY; pShmNode->isReadonly = 1; } diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 5bb1cb5323..ca0d7e3208 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -2608,21 +2608,37 @@ int sqlite3_open_v2( /* ** CAPI3REF: Obtain Values For URI Parameters ** -** This is a utility routine, useful to VFS implementations, that checks +** These are utility routines, useful to VFS implementations, that check ** to see if a database file was a URI that contained a specific query -** parameter, and if so obtains the value of the query parameter. +** parameter, and if so obtains the value of that query parameter. ** -** The zFilename argument is the filename pointer passed into the xOpen() -** method of a VFS implementation. The zParam argument is the name of the -** query parameter we seek. This routine returns the value of the zParam -** parameter if it exists. If the parameter does not exist, this routine -** returns a NULL pointer. +** If F is the filename pointer passed into the xOpen() method of a VFS +** implementation and P is the name of the query parameter, then +** sqlite3_uri_parameter(F,P) returns the value of the P +** parameter if it exists or a NULL pointer if P does not appear as a +** query parameter on F. If P is a query parameter of F +** has no explicit value, then sqlite3_uri_parameter(F,P) returns +** a pointer to an empty string. ** -** If the zFilename argument to this function is not a pointer that SQLite -** passed into the xOpen VFS method, then the behavior of this routine -** is undefined and probably undesirable. +** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean +** parameter and returns true (1) or false (0) according to the value +** of P. The value of P is true if it is "yes" or "true" or "on" or +** a non-zero number and is false otherwise. If P is not a query parameter +** on F then sqlite3_uri_boolean(F,P,B) returns (B!=0). +** +** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a +** 64-bit signed integer and returns that integer, or D if P does not +** exist. If the value of P is something other than an integer, then +** zero is returned. +** +** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and +** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and +** is not a pathname pointer that SQLite passed into the xOpen VFS method, +** then the behavior of this routine is undefined and probably undesirable. */ const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam); +int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault); +sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64); /* diff --git a/src/test_multiplex.c b/src/test_multiplex.c index 25bfcdddd2..45f7310361 100644 --- a/src/test_multiplex.c +++ b/src/test_multiplex.c @@ -495,35 +495,19 @@ static int multiplexOpen( memset(pGroup, 0, sz); pMultiplexOpen->pGroup = pGroup; pGroup->bEnabled = -1; - pGroup->bTruncate = (flags & SQLITE_OPEN_MAIN_DB)==0; - pGroup->szChunk = SQLITE_MULTIPLEX_CHUNK_SIZE; - + pGroup->bTruncate = sqlite3_uri_boolean(zName, "truncate", + (flags & SQLITE_OPEN_MAIN_DB)==0); + pGroup->szChunk = sqlite3_uri_int64(zName, "chunksize", + SQLITE_MULTIPLEX_CHUNK_SIZE); + pGroup->szChunk = (pGroup->szChunk+0xffff)&~0xffff; if( zName ){ char *p = (char *)&pGroup[1]; - if( flags & SQLITE_OPEN_URI ){ - const char *zChunkSize; - zChunkSize = sqlite3_uri_parameter(zName, "chunksize"); - if( zChunkSize ){ - unsigned int n = 0; - int i; - for(i=0; zChunkSize[i]>='0' && zChunkSize[i]<='9'; i++){ - n = n*10 + zChunkSize[i] - '0'; - } - if( n>0 ){ - pGroup->szChunk = (n+0xffff)&~0xffff; - }else{ - /* A zero or negative chunksize disabled the multiplexor */ - pGroup->bEnabled = 0; - } - } - if( sqlite3_uri_parameter(zName, "truncate") ) pGroup->bTruncate = 1; - } pGroup->zName = p; memcpy(pGroup->zName, zName, nName+1); pGroup->nName = nName; } if( pGroup->bEnabled ){ - /* Make sure that the chunksize is not such that the pending byte + /* Make sure that the chunksize is such that the pending byte does not ** falls at the end of a chunk. A region of up to 64K following ** the pending byte is never written, so if the pending byte occurs ** near the end of a chunk, that chunk will be too small. */ diff --git a/src/util.c b/src/util.c index d27f6fdf26..a80b89a4ad 100644 --- a/src/util.c +++ b/src/util.c @@ -1173,9 +1173,7 @@ int sqlite3AbsInt32(int x){ */ void sqlite3FileSuffix3(const char *zBaseFilename, char *z){ #if SQLITE_ENABLE_8_3_NAMES<2 - const char *zOk; - zOk = sqlite3_uri_parameter(zBaseFilename, "8_3_names"); - if( zOk && sqlite3GetBoolean(zOk) ) + if( sqlite3_uri_boolean(zBaseFilename, "8_3_names") ) #endif { int i, sz;