]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix a bug in the sqlite3Utf16ByteLen() function so that it computes the
authordrh <drh@noemail.net>
Wed, 1 Apr 2009 18:40:32 +0000 (18:40 +0000)
committerdrh <drh@noemail.net>
Wed, 1 Apr 2009 18:40:32 +0000 (18:40 +0000)
correct length even for strings that contain surrogate pairs.
Ticket #3766. (CVS 6427)

FossilOrigin-Name: 766bb7e59c28884e40ce13e3fc55c870d06d7e34

manifest
manifest.uuid
src/test1.c
src/utf.c

index 0d0d3cc1b2d294a2b94a51b236de940e06b8a2aa..6832a0b272dfd0918874e2e4340c47df9adb8937 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Test\sthat\stwo\sdatabase\sconnections\sthat\suse\sdifferent\sVFS\simplementations\smay\snot\sshare\sa\scache.\s(CVS\s6426)
-D 2009-04-01T18:25:54
+C Fix\sa\sbug\sin\sthe\ssqlite3Utf16ByteLen()\sfunction\sso\sthat\sit\scomputes\sthe\ncorrect\slength\seven\sfor\sstrings\sthat\scontain\ssurrogate\spairs.\nTicket\s#3766.\s(CVS\s6427)
+D 2009-04-01T18:40:32
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -164,7 +164,7 @@ F src/sqliteLimit.h ffe93f5a0c4e7bd13e70cd7bf84cfb5c3465f45d
 F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76
 F src/table.c 332ab0ea691e63862e2a8bdfe2c0617ee61062a3
 F src/tclsqlite.c d3195e0738c101a155404ecdb1cd9532a2fd34f2
-F src/test1.c fc09299ecf3e7d1235293ba43dcc7ea003240a54
+F src/test1.c eaac64fe5415e14d8268dd925b10ca39251e0120
 F src/test2.c 71c22e2974f8094fe0fd1eba8f27872dde9b2a39
 F src/test3.c d3115b301c6ee761b102f315fe24125f3d6c3a4d
 F src/test4.c f79ab52d27ff49b784b631a42e2ccd52cfd5c84c
@@ -197,7 +197,7 @@ F src/test_wsd.c 3ae5101de6cbfda2720152ab659ea84079719241
 F src/tokenize.c 7bd3b6dd56566604ad24ed4aa017e6618166b500
 F src/trigger.c 21f39db410cdc32166a94900ac1b3df98ea560e6
 F src/update.c 8ededddcde6f7b6da981dd0429a5d34518a475b7
-F src/utf.c 7bec2eeae2b26f28b8a8ede529705ccf531cd21b
+F src/utf.c 9541d28f40441812c0b40f00334372a0542c00ff
 F src/util.c 469d74f5bf09ed6398702c7da2ef8a34e979a1c1
 F src/vacuum.c 4929a585ef0fb1dfaf46302f8a9c4aa30c2d9cf5
 F src/vdbe.c 624922027b8b5fe203bd89e204aaed447e8b7ce7
@@ -714,7 +714,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P fdd78962fcb988edfb4147394045fc5d3944c620
-R a659db632b7a8a1ae5444e52a2d0dea6
-U danielk1977
-Z c2cd1ad66ce2a9347f9799395978b43a
+P 3a92c95644ead7c4728ffec1ec70676663518188
+R a8645e4c19e0d7546ed7b3fc51d85afa
+U drh
+Z f7ca868d3c85446b0badce3658c2c808
index 8e6733ae874949c5e6614a25e9bc809c38eccc20..4e6aa45b329b7c7804eb7b5b1cdf1d640df3bd93 100644 (file)
@@ -1 +1 @@
-3a92c95644ead7c4728ffec1ec70676663518188
\ No newline at end of file
+766bb7e59c28884e40ce13e3fc55c870d06d7e34
\ No newline at end of file
index 0fe3e28b184025b0a4d2e4bf9f9e9ed0dc2aa20c..c427f460dc420331c0e4073c800e46443f8b116e 100644 (file)
@@ -13,7 +13,7 @@
 ** is not included in the SQLite library.  It is used for automated
 ** testing of the SQLite library.
 **
-** $Id: test1.c,v 1.349 2009/03/27 12:32:55 drh Exp $
+** $Id: test1.c,v 1.350 2009/04/01 18:40:32 drh Exp $
 */
 #include "sqliteInt.h"
 #include "tcl.h"
@@ -3261,6 +3261,7 @@ static int test_errmsg16(
 #ifndef SQLITE_OMIT_UTF16
   sqlite3 *db;
   const void *zErr;
+  const char *z;
   int bytes = 0;
 
   if( objc!=2 ){
@@ -3272,7 +3273,8 @@ static int test_errmsg16(
 
   zErr = sqlite3_errmsg16(db);
   if( zErr ){
-    bytes = sqlite3Utf16ByteLen(zErr, -1);
+    z = zErr;
+    for(bytes=0; z[bytes] || z[bytes+1]; bytes+=2){}
   }
   Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(zErr, bytes));
 #endif /* SQLITE_OMIT_UTF16 */
@@ -3953,7 +3955,10 @@ static int test_stmt_utf16(
 
   zName16 = xFunc(pStmt, col);
   if( zName16 ){
-    pRet = Tcl_NewByteArrayObj(zName16, sqlite3Utf16ByteLen(zName16, -1)+2);
+    int n;
+    const char *z = zName16;
+    for(n=0; z[n] || z[n+1]; n+=2){}
+    pRet = Tcl_NewByteArrayObj(zName16, n+2);
     Tcl_SetObjResult(interp, pRet);
   }
 #endif /* SQLITE_OMIT_UTF16 */
index 9540e285c2f1881baee598c5e8f52b33fd19cd4c..ceb0ab641dd35b3c315d88f7fdcdfcf425a3a456 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.72 2009/04/01 16:33:38 drh Exp $
+** $Id: utf.c,v 1.73 2009/04/01 18:40:32 drh Exp $
 **
 ** Notes on UTF-8:
 **
@@ -455,15 +455,13 @@ char *sqlite3Utf16to8(sqlite3 *db, const void *z, int nByte){
 }
 
 /*
-** 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
-** of consecutive 0x00 bytes in pZ. If nChar is not less than zero,
-** then return the number of bytes in the first nChar unicode characters
-** in pZ (or up until the first pair of 0x00 bytes, whichever comes first).
+** pZ is a UTF-16 encoded unicode string at least nChar characters long.
+** Return the number of bytes in the first nChar unicode characters
+** in pZ.  nChar must be non-negative.
 */
 int sqlite3Utf16ByteLen(const void *zIn, int nChar){
-  unsigned int c = 1;
-  char const *z = zIn;
+  int c;
+  unsigned char const *z = zIn;
   int n = 0;
   if( SQLITE_UTF16NATIVE==SQLITE_UTF16BE ){
     /* Using an "if (SQLITE_UTF16NATIVE==SQLITE_UTF16BE)" construct here
@@ -475,17 +473,17 @@ int sqlite3Utf16ByteLen(const void *zIn, int nChar){
     ** which branch will be followed. It is therefore assumed that no runtime
     ** penalty is paid for this "if" statement.
     */
-    while( c && ((nChar<0) || n<nChar) ){
+    while( n<nChar ){
       READ_UTF16BE(z, c);
       n++;
     }
   }else{
-    while( c && ((nChar<0) || n<nChar) ){
+    while( n<nChar ){
       READ_UTF16LE(z, c);
       n++;
     }
   }
-  return (int)(z-(char const *)zIn)-((c==0)?2:0);
+  return (int)(z-(unsigned char const *)zIn);
 }
 
 #if defined(SQLITE_TEST)