Fix a bug in the sqlite3Utf16ByteLen() function so that it computes the
correct length even for strings that contain surrogate pairs. Ticket #3766. (CVS 6427) FossilOrigin-Name: 766bb7e59c28884e40ce13e3fc55c870d06d7e34
This commit is contained in:
parent
856cc0fde9
commit
aed382f9f1
16
manifest
16
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
|
||||
|
@ -1 +1 @@
|
||||
3a92c95644ead7c4728ffec1ec70676663518188
|
||||
766bb7e59c28884e40ce13e3fc55c870d06d7e34
|
11
src/test1.c
11
src/test1.c
@ -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 */
|
||||
|
20
src/utf.c
20
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user