summaryrefslogtreecommitdiffstats
path: root/lib/libsqlite3/ext/misc
diff options
context:
space:
mode:
authorjturner <jturner@openbsd.org>2015-04-04 23:24:43 +0000
committerjturner <jturner@openbsd.org>2015-04-04 23:24:43 +0000
commit4cd20ac631b4b7b4b044a0402b379984aae8c8fa (patch)
tree67f2e52b4aeaa573e6ee5b3b4172c119abef2a05 /lib/libsqlite3/ext/misc
parentThe swapfile argument is also const char *. (diff)
downloadwireguard-openbsd-4cd20ac631b4b7b4b044a0402b379984aae8c8fa.tar.xz
wireguard-openbsd-4cd20ac631b4b7b4b044a0402b379984aae8c8fa.zip
Update sqlite3 to 3.8.8.3. Changes available here:
http://sqlite.org/releaselog/3_8_8_3.html Tested in bulk and ok landry@
Diffstat (limited to 'lib/libsqlite3/ext/misc')
-rw-r--r--lib/libsqlite3/ext/misc/amatch.c2
-rw-r--r--lib/libsqlite3/ext/misc/eval.c122
-rw-r--r--lib/libsqlite3/ext/misc/fuzzer.c3
-rw-r--r--lib/libsqlite3/ext/misc/spellfix.c2
4 files changed, 126 insertions, 3 deletions
diff --git a/lib/libsqlite3/ext/misc/amatch.c b/lib/libsqlite3/ext/misc/amatch.c
index d869dbd8d13..98c01431bae 100644
--- a/lib/libsqlite3/ext/misc/amatch.c
+++ b/lib/libsqlite3/ext/misc/amatch.c
@@ -398,7 +398,7 @@ static amatch_avl *amatchAvlInsert(amatch_avl **ppHead, amatch_avl *pNew){
*/
static void amatchAvlRemove(amatch_avl **ppHead, amatch_avl *pOld){
amatch_avl **ppParent;
- amatch_avl *pBalance;
+ amatch_avl *pBalance = 0;
/* assert( amatchAvlSearch(*ppHead, pOld->zKey)==pOld ); */
ppParent = amatchAvlFromPtr(pOld, ppHead);
if( pOld->pBefore==0 && pOld->pAfter==0 ){
diff --git a/lib/libsqlite3/ext/misc/eval.c b/lib/libsqlite3/ext/misc/eval.c
new file mode 100644
index 00000000000..71b6b69f20a
--- /dev/null
+++ b/lib/libsqlite3/ext/misc/eval.c
@@ -0,0 +1,122 @@
+/*
+** 2014-11-10
+**
+** The author disclaims copyright to this source code. In place of
+** a legal notice, here is a blessing:
+**
+** May you do good and not evil.
+** May you find forgiveness for yourself and forgive others.
+** May you share freely, never taking more than you give.
+**
+******************************************************************************
+**
+** This SQLite extension implements SQL function eval() which runs
+** SQL statements recursively.
+*/
+#include "sqlite3ext.h"
+SQLITE_EXTENSION_INIT1
+#include <string.h>
+
+/*
+** Structure used to accumulate the output
+*/
+struct EvalResult {
+ char *z; /* Accumulated output */
+ const char *zSep; /* Separator */
+ int szSep; /* Size of the separator string */
+ sqlite3_int64 nAlloc; /* Number of bytes allocated for z[] */
+ sqlite3_int64 nUsed; /* Number of bytes of z[] actually used */
+};
+
+/*
+** Callback from sqlite_exec() for the eval() function.
+*/
+static int callback(void *pCtx, int argc, char **argv, char **colnames){
+ struct EvalResult *p = (struct EvalResult*)pCtx;
+ int i;
+ for(i=0; i<argc; i++){
+ const char *z = argv[i] ? argv[i] : "";
+ size_t sz = strlen(z);
+ if( (sqlite3_int64)sz+p->nUsed+p->szSep+1 > p->nAlloc ){
+ char *zNew;
+ p->nAlloc = p->nAlloc*2 + sz + p->szSep + 1;
+ /* Using sqlite3_realloc64() would be better, but it is a recent
+ ** addition and will cause a segfault if loaded by an older version
+ ** of SQLite. */
+ zNew = p->nAlloc<=0x7fffffff ? sqlite3_realloc(p->z, (int)p->nAlloc) : 0;
+ if( zNew==0 ){
+ sqlite3_free(p->z);
+ memset(p, 0, sizeof(*p));
+ return 1;
+ }
+ p->z = zNew;
+ }
+ if( p->nUsed>0 ){
+ memcpy(&p->z[p->nUsed], p->zSep, p->szSep);
+ p->nUsed += p->szSep;
+ }
+ memcpy(&p->z[p->nUsed], z, sz);
+ p->nUsed += sz;
+ }
+ return 0;
+}
+
+/*
+** Implementation of the eval(X) and eval(X,Y) SQL functions.
+**
+** Evaluate the SQL text in X. Return the results, using string
+** Y as the separator. If Y is omitted, use a single space character.
+*/
+static void sqlEvalFunc(
+ sqlite3_context *context,
+ int argc,
+ sqlite3_value **argv
+){
+ const char *zSql;
+ sqlite3 *db;
+ char *zErr = 0;
+ int rc;
+ struct EvalResult x;
+
+ memset(&x, 0, sizeof(x));
+ x.zSep = " ";
+ zSql = (const char*)sqlite3_value_text(argv[0]);
+ if( zSql==0 ) return;
+ if( argc>1 ){
+ x.zSep = (const char*)sqlite3_value_text(argv[1]);
+ if( x.zSep==0 ) return;
+ }
+ x.szSep = (int)strlen(x.zSep);
+ db = sqlite3_context_db_handle(context);
+ rc = sqlite3_exec(db, zSql, callback, &x, &zErr);
+ if( rc!=SQLITE_OK ){
+ sqlite3_result_error(context, zErr, -1);
+ sqlite3_free(zErr);
+ }else if( x.zSep==0 ){
+ sqlite3_result_error_nomem(context);
+ sqlite3_free(x.z);
+ }else{
+ sqlite3_result_text(context, x.z, (int)x.nUsed, sqlite3_free);
+ }
+}
+
+
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int sqlite3_eval_init(
+ sqlite3 *db,
+ char **pzErrMsg,
+ const sqlite3_api_routines *pApi
+){
+ int rc = SQLITE_OK;
+ SQLITE_EXTENSION_INIT2(pApi);
+ (void)pzErrMsg; /* Unused parameter */
+ rc = sqlite3_create_function(db, "eval", 1, SQLITE_UTF8, 0,
+ sqlEvalFunc, 0, 0);
+ if( rc==SQLITE_OK ){
+ rc = sqlite3_create_function(db, "eval", 2, SQLITE_UTF8, 0,
+ sqlEvalFunc, 0, 0);
+ }
+ return rc;
+}
diff --git a/lib/libsqlite3/ext/misc/fuzzer.c b/lib/libsqlite3/ext/misc/fuzzer.c
index fe41cda8c24..dc03161aafa 100644
--- a/lib/libsqlite3/ext/misc/fuzzer.c
+++ b/lib/libsqlite3/ext/misc/fuzzer.c
@@ -342,7 +342,8 @@ static int fuzzerLoadOneRule(
rc = SQLITE_NOMEM;
}else{
memset(pRule, 0, sizeof(*pRule));
- pRule->zFrom = &pRule->zTo[nTo+1];
+ pRule->zFrom = pRule->zTo;
+ pRule->zFrom += nTo + 1;
pRule->nFrom = nFrom;
memcpy(pRule->zFrom, zFrom, nFrom+1);
memcpy(pRule->zTo, zTo, nTo+1);
diff --git a/lib/libsqlite3/ext/misc/spellfix.c b/lib/libsqlite3/ext/misc/spellfix.c
index 2a26e08391d..a6f780584c2 100644
--- a/lib/libsqlite3/ext/misc/spellfix.c
+++ b/lib/libsqlite3/ext/misc/spellfix.c
@@ -356,7 +356,7 @@ static int substituteCost(char cPrev, char cFrom, char cTo){
static int editdist1(const char *zA, const char *zB, int *pnMatch){
int nA, nB; /* Number of characters in zA[] and zB[] */
int xA, xB; /* Loop counters for zA[] and zB[] */
- char cA, cB; /* Current character of zA and zB */
+ char cA = 0, cB; /* Current character of zA and zB */
char cAprev, cBprev; /* Previous character of zA and zB */
char cAnext, cBnext; /* Next character in zA and zB */
int d; /* North-west cost value */