]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix memory allocation problems on the utf-16 versions of collating function
authordrh <drh@noemail.net>
Thu, 15 Dec 2005 03:04:10 +0000 (03:04 +0000)
committerdrh <drh@noemail.net>
Thu, 15 Dec 2005 03:04:10 +0000 (03:04 +0000)
control routines. (CVS 2817)

FossilOrigin-Name: ad292e27336b8c5afc0acdf111944a456bd23c32

manifest
manifest.uuid
src/main.c
src/prepare.c
src/sqliteInt.h
src/utf.c

index 786de7752f6d7c554e23af6f3bbd9877ca993080..205fc552f72a3d1e4ae60eaa92bab829ba4fa4ef 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Avoid\susing\sthe\stransient\svalue\sin\sthe\sUTF-16\scollation\sneeded\scallback.\s(CVS\s2816)
-D 2005-12-14T22:51:17
+C Fix\smemory\sallocation\sproblems\son\sthe\sutf-16\sversions\sof\scollating\sfunction\ncontrol\sroutines.\s(CVS\s2817)
+D 2005-12-15T03:04:10
 F Makefile.in e3c6b3a38d734d41574c04f2fc90d18de2b87102
 F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -48,7 +48,7 @@ F src/hash.c 8747cf51d12de46512880dfcf1b68b4e24072863
 F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
 F src/insert.c 5393479164f317ea0aeec954c6500cafa097ef33
 F src/legacy.c 59757d857ab95fcbb0ac27692d3201e35f093dd7
-F src/main.c 95ba159727e4342d871e8c0aae42321ae10d8195
+F src/main.c a12aa72335036bb22249418e222124abfc581b85
 F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
 F src/os.c bdd3a2fd089777e7ad18b57c896f1141d5a0c1fd
 F src/os.h d5ae3f4c1c7731437b6cddec279b7c06f761c44e
@@ -63,13 +63,13 @@ F src/pager.c 49f63a54b57164a70df0b1539141003fd27856c6
 F src/pager.h e7b41ce8e7b5f629d456708b7ad9a8c8ede37140
 F src/parse.y d0b1f9a4d508bf043cdbc7079aa26dff7d358651
 F src/pragma.c 8883b4d34796efa315bdd0ec1b03f580ef1575b9
-F src/prepare.c 9717bd4236020aeabc488819b994d4164a97ffdf
+F src/prepare.c ca4d58a46e74412dba1fcfaeeaa89b01e64f1a8b
 F src/printf.c f47a2f4b5387cd2ebb12e9117a1a5d6bd9a2b812
 F src/random.c ff5e9a8cad790e2a51cd4d2e7737dc8540e09d1d
 F src/select.c 2292b065bc6be61e01aad39a2e1b93e332fb7e57
 F src/shell.c 4872acee1d2a826c73c914961e469e563204b7f9
 F src/sqlite.h.in a52db91dfa4f90e8e42361f6c7824c09b4e101ad
-F src/sqliteInt.h 22b18da438fb1298bfd6ad1e2e3b5a2826100da8
+F src/sqliteInt.h babeb60d34dbaa95a0f1d336e65039ae7ade5aab
 F src/table.c 486dcfce532685b53b5a2b5da8bba0ded6fb2316
 F src/tclsqlite.c c155bf5f9ce9ae8950037931f7f7efcc0d92d9c5
 F src/test1.c d6924b182773b2ad3b22e435e4d3bfd5a846da9e
@@ -81,7 +81,7 @@ F src/test6.c cb811391ec0b7c75f29e545d4820a9cf19f3637e
 F src/tokenize.c 7a3a3d3cc734f684a77c4dfd09eb46fcee25394c
 F src/trigger.c 2925ba96d964d9b717e74006bf7e64b8a6b70d97
 F src/update.c ec8e540617b116725b5a55c8d6b4db8bc67fdd7d
-F src/utf.c a1fd34e5db0dc4da1c37405381a656230c7b922d
+F src/utf.c d2360f55ecd666f3e472738191f8dae717b95e5e
 F src/util.c e525154652f7aecb8773cae55ada9f43024bb2c4
 F src/vacuum.c fbfdd3967fd34e2f260fafed88dcbf3c10856b94
 F src/vdbe.c d09c185f4badac6c79f2a919cbf661e7b5618293
@@ -327,7 +327,7 @@ F www/tclsqlite.tcl ddcf912ea48695603c8ed7efb29f0812ef8d1b49
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 71a49d05bf174025c0d9141b8905c48f43e42541
-R f16c049475a49b8d2690563dd058c2bb
+P ab6241af29b2e9f5f094b83c13afebe44a8ad6bc
+R 12c15b60aaac20b8ef3a98bcc49cb762
 U drh
-Z 92b09f7f2e0683668576a9a0f2bc9232
+Z 29b97667c2714272591c690c9c9d58c8
index 57525ae1d1ea4566e78faf52b3ca57ad3a0990a4..74c7e5eba0bcf4055cf2e23c950dcde7e8e14531 100644 (file)
@@ -1 +1 @@
-ab6241af29b2e9f5f094b83c13afebe44a8ad6bc
\ No newline at end of file
+ad292e27336b8c5afc0acdf111944a456bd23c32
\ No newline at end of file
index ff5bc08752e7bcb092fc1989852746da15147bc3..5117200c99efb60e7d8524b46bfddf4053fcad55 100644 (file)
@@ -14,7 +14,7 @@
 ** other files are for internal use by SQLite and should not be
 ** accessed by users of the library.
 **
-** $Id: main.c,v 1.308 2005/12/12 06:53:04 danielk1977 Exp $
+** $Id: main.c,v 1.309 2005/12/15 03:04:10 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -35,19 +35,6 @@ const int sqlite3one = 1;
 static sqlite3 *pDbList = 0;
 #endif
 
-#ifndef SQLITE_OMIT_UTF16
-/* 
-** Return the transient sqlite3_value object used for encoding conversions
-** during SQL compilation.
-*/
-sqlite3_value *sqlite3GetTransientValue(sqlite3 *db){
-  if( !db->pValue ){
-    db->pValue = sqlite3ValueNew();
-  }
-  return db->pValue;
-}
-#endif
-
 /*
 ** The version of the library
 */
@@ -182,9 +169,6 @@ int sqlite3_close(sqlite3 *db){
 
   sqlite3HashClear(&db->aFunc);
   sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */
-  if( db->pValue ){
-    sqlite3ValueFree(db->pValue);
-  }
   if( db->pErr ){
     sqlite3ValueFree(db->pErr);
   }
@@ -496,21 +480,18 @@ int sqlite3_create_function16(
   void (*xFinal)(sqlite3_context*)
 ){
   int rc;
-  char const *zFunc8;
-  sqlite3_value *pTmp;
+  char *zFunc8;
 
   if( sqlite3SafetyCheck(db) ){
     return SQLITE_MISUSE;
   }
-  pTmp = sqlite3GetTransientValue(db);
-  sqlite3ValueSetStr(pTmp, -1, zFunctionName, SQLITE_UTF16NATIVE,SQLITE_STATIC);
-  zFunc8 = sqlite3ValueText(pTmp, SQLITE_UTF8);
-
+  zFunc8 = sqlite3utf16to8(zFunctionName, -1);
   if( !zFunc8 ){
     return SQLITE_NOMEM;
   }
   rc = sqlite3_create_function(db, zFunc8, nArg, eTextRep, 
       pUserData, xFunc, xStep, xFinal);
+  sqliteFree(zFunc8);
   return rc;
 }
 #endif
@@ -958,15 +939,15 @@ int sqlite3_create_collation16(
   void* pCtx,
   int(*xCompare)(void*,int,const void*,int,const void*)
 ){
-  char const *zName8;
-  sqlite3_value *pTmp;
+  char *zName8;
+  int rc;
   if( sqlite3SafetyCheck(db) ){
     return SQLITE_MISUSE;
   }
-  pTmp = sqlite3GetTransientValue(db);
-  sqlite3ValueSetStr(pTmp, -1, zName, SQLITE_UTF16NATIVE, SQLITE_STATIC);
-  zName8 = sqlite3ValueText(pTmp, SQLITE_UTF8);
-  return sqlite3_create_collation(db, zName8, enc, pCtx, xCompare);
+  zName8 = sqlite3utf16to8(zName, -1);
+  rc = sqlite3_create_collation(db, zName8, enc, pCtx, xCompare);
+  sqliteFree(zName8);
+  return rc;
 }
 #endif /* SQLITE_OMIT_UTF16 */
 
index c702fb9f197741eda4058e797fe23d9148d79826..ca00049e660451efd8905bbdde0294b5b46b809f 100644 (file)
@@ -13,7 +13,7 @@
 ** interface, and routines that contribute to loading the database schema
 ** from disk.
 **
-** $Id: prepare.c,v 1.8 2005/12/12 06:53:04 danielk1977 Exp $
+** $Id: prepare.c,v 1.9 2005/12/15 03:04:11 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -515,17 +515,14 @@ int sqlite3_prepare16(
   ** encoded string to UTF-8, then invoking sqlite3_prepare(). The
   ** tricky bit is figuring out the pointer to return in *pzTail.
   */
-  char const *zSql8 = 0;
-  char const *zTail8 = 0;
+  char *zSql8 = 0;
+  char *zTail8 = 0;
   int rc;
-  sqlite3_value *pTmp;
 
   if( sqlite3SafetyCheck(db) ){
     return SQLITE_MISUSE;
   }
-  pTmp = sqlite3GetTransientValue(db);
-  sqlite3ValueSetStr(pTmp, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
-  zSql8 = sqlite3ValueText(pTmp, SQLITE_UTF8);
+  zSql8 = sqlite3utf16to8(zSql, nBytes);
   if( !zSql8 ){
     sqlite3Error(db, SQLITE_NOMEM, 0);
     return SQLITE_NOMEM;
@@ -541,7 +538,7 @@ int sqlite3_prepare16(
     int chars_parsed = sqlite3utf8CharLen(zSql8, zTail8-zSql8);
     *pzTail = (u8 *)zSql + sqlite3utf16ByteLen(zSql, chars_parsed);
   }
+  sqliteFree(zSql8); 
   return rc;
 }
 #endif /* SQLITE_OMIT_UTF16 */
index 2ce46e0ad5a2536bb1a32f90c5afd23bf7190fa5..aa1bf3e2667fcabbcf80ad2a6d950f5abfd96fef 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.434 2005/12/12 06:53:05 danielk1977 Exp $
+** @(#) $Id: sqliteInt.h,v 1.435 2005/12/15 03:04:11 drh Exp $
 */
 #ifndef _SQLITEINT_H_
 #define _SQLITEINT_H_
@@ -443,7 +443,6 @@ struct sqlite3 {
   void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
   void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
   void *pCollNeededArg;
-  sqlite3_value *pValue;        /* Value used for transient conversions */
   sqlite3_value *pErr;          /* Most recent error message */
   char *zErrMsg;                /* Most recent error message (UTF-8 encoded) */
   char *zErrMsg16;              /* Most recent error message (UTF-16 encoded) */
@@ -1645,7 +1644,7 @@ int sqlite3ValueBytes(sqlite3_value*, u8);
 void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, void(*)(void*));
 void sqlite3ValueFree(sqlite3_value*);
 sqlite3_value *sqlite3ValueNew(void);
-sqlite3_value *sqlite3GetTransientValue(sqlite3*db);
+char *sqlite3utf16to8(const void*, int);
 int sqlite3ValueFromExpr(Expr *, u8, u8, sqlite3_value **);
 void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
 extern const unsigned char sqlite3UpperToLower[];
index f9c944f1ba82e12eb85e054daffe4d9d24ac6c25..3387a576e7aaf575a3f6a3c9a9c046dd269e316d 100644 (file)
--- 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.33 2005/12/09 20:02:06 drh Exp $
+** $Id: utf.c,v 1.34 2005/12/15 03:04:11 drh Exp $
 **
 ** Notes on UTF-8:
 **
@@ -450,6 +450,21 @@ int sqlite3utf8CharLen(const char *z, int nByte){
 }
 
 #ifndef SQLITE_OMIT_UTF16
+/*
+** Convert a UTF-16 string in the native encoding into a UTF-8 string.
+** Memory to hold the UTF-8 string is obtained from malloc and must be
+** freed by the calling function.
+**
+** NULL is returned if there is an allocation error.
+*/
+char *sqlite3utf16to8(const void *z, int nByte){
+  Mem m;
+  memset(&m, 0, sizeof(m));
+  sqlite3VdbeMemSetStr(&m, z, nByte, SQLITE_UTF16NATIVE, SQLITE_STATIC);
+  sqlite3VdbeChangeEncoding(&m, SQLITE_UTF8);
+  return m.z;
+}
+
 /*
 ** pZ is a UTF-16 encoded unicode string. If nChar is less than zero,
 ** return the number of bytes up to (but not including), the first pair