]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add a comment to the output buffer allocation in sqlite3VdbeMemTranslate() (CVS 1673)
authordanielk1977 <danielk1977@noemail.net>
Wed, 23 Jun 2004 00:23:49 +0000 (00:23 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Wed, 23 Jun 2004 00:23:49 +0000 (00:23 +0000)
FossilOrigin-Name: e2f7f182987fbfe8611ead8bd1f12b2e8b47f6dc

manifest
manifest.uuid
src/utf.c

index 40eb78a9d1c51c35e31e7fae1abb6423ba41213b..52e8c13c5a8f36d70c64dd312d4f6645eb82369a 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sanother\suninitialized\sMem.xDel\sproblem.\s(CVS\s1672)
-D 2004-06-22T22:54:23
+C Add\sa\scomment\sto\sthe\soutput\sbuffer\sallocation\sin\ssqlite3VdbeMemTranslate()\s(CVS\s1673)
+D 2004-06-23T00:23:49
 F Makefile.in 0a3d7aaefa50717bd550b0cf568a51072c4c103c
 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -70,7 +70,7 @@ F src/test5.c 1b7c275b2929dbd034a567255d2aca339410d1d6
 F src/tokenize.c 900374b6b37f04748bcd48c2d29a41c251542935
 F src/trigger.c 296e888ae931e9774e1761996b2b66db40f7d216
 F src/update.c b66b1896c9da54678ba3eff2bf0b4d291a95986a
-F src/utf.c c5ae076b5b9e1a4fac72a48f0005508ab4118d1b
+F src/utf.c 9c66605c5eac4c4aa999207634fabe7885e5b0b3
 F src/util.c e31e35d3d76cab7a02045095064897eca49cbce3
 F src/vacuum.c fcb930215a3f6c50087300782555f61ad11dd80c
 F src/vdbe.c 0d8f2fea386c173997fb8eab555ab999497591fe
@@ -229,7 +229,7 @@ F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075
 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
 F www/version3.tcl 563ba3ac02f64da27ab17f3edbe8e56bfd0293fb
 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
-P e17ea666b1eb1df12a1d4d78bda2e025e2aa30bd
-R 4e9bb61466aecc430c6837fcb2b3e202
-U drh
-Z 76bcb96ce9daaf4663984472a800f8fe
+P cb4e242e83ba111c5da1f9662fda5a890051e7b0
+R bd4ff00f259823f00b7fc8204e6c5fa3
+U danielk1977
+Z ed06ef82d5f64ca5dbd5ac31ceda856c
index d7640078877ea358733b3bda8b7299b31cd1dcf5..e7598a175695d3adde53ffacdb81714109b56782 100644 (file)
@@ -1 +1 @@
-cb4e242e83ba111c5da1f9662fda5a890051e7b0
\ No newline at end of file
+e2f7f182987fbfe8611ead8bd1f12b2e8b47f6dc
\ No newline at end of file
index 16454c2ffd8a3555f8dd4392a79f8b76583e4024..4bb08b5e07e885d097e42fd38b86e11c356ef235 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.23 2004/06/22 22:04:46 drh Exp $
+** $Id: utf.c,v 1.24 2004/06/23 00:23:49 danielk1977 Exp $
 **
 ** Notes on UTF-8:
 **
@@ -262,6 +262,23 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
     goto translate_out;
   }
 
+  /* Set len to the maximum number of bytes required in the output buffer. */
+  if( desiredEnc==SQLITE_UTF8 ){
+    /* When converting from UTF-16, the maximum growth results from
+    ** translating a 2-byte character to a 3-byte UTF-8 character (i.e.
+    ** code-point 0xFFFC). A single byte is required for the output string
+    ** nul-terminator.
+    */
+    len = (pMem->n/2) * 3 + 1;
+  }else{
+    /* When converting from UTF-8 to UTF-16 the maximum growth is caused
+    ** when a 1-byte UTF-8 character is translated into a 2-byte UTF-16
+    ** character. Two bytes are required in the output buffer for the
+    ** nul-terminator.
+    */
+    len = pMem->n * 2 + 2;
+  }
+
   /* Set zIn to point at the start of the input buffer and zTerm to point 1
   ** byte past the end.
   **
@@ -271,7 +288,6 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
   */
   zIn = pMem->z;
   zTerm = &zIn[pMem->n];
-  len = pMem->n*2 + 2;
   if( len>NBFS ){
     zOut = sqliteMallocRaw(len);
     if( !zOut ) return SQLITE_NOMEM;
@@ -321,8 +337,8 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
       WRITE_UTF8(z, 0);
       pMem->n = (z-zOut)-1;
     }
-    assert( pMem->n+1<=len );
   }
+  assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );
 
   sqlite3VdbeMemRelease(pMem);
   pMem->flags &= ~(MEM_Static|MEM_Dyn|MEM_Ephem|MEM_Short);