From 8a5c6502caf55a317ba86957b0ed7260d04201a5 Mon Sep 17 00:00:00 2001 From: "bar@noter.(none)" <> Date: Tue, 10 May 2005 14:13:58 +0500 Subject: [PATCH] bug#10344: some string function fail for UCS2 substr fix --- mysql-test/r/ctype_ucs.result | 18 ++++++++++++++++++ mysql-test/t/ctype_ucs.test | 10 ++++++++++ strings/ctype-ucs2.c | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/ctype_ucs.result b/mysql-test/r/ctype_ucs.result index 3face9b1ba6..5902dd247ce 100644 --- a/mysql-test/r/ctype_ucs.result +++ b/mysql-test/r/ctype_ucs.result @@ -598,6 +598,24 @@ ucs2_bin 00610009 ucs2_bin 0061 ucs2_bin 00610020 drop table t1; +select hex(substr(_ucs2 0x00e400e50068,1)); +hex(substr(_ucs2 0x00e400e50068,1)) +00E400E50068 +select hex(substr(_ucs2 0x00e400e50068,2)); +hex(substr(_ucs2 0x00e400e50068,2)) +00E50068 +select hex(substr(_ucs2 0x00e400e50068,3)); +hex(substr(_ucs2 0x00e400e50068,3)) +0068 +select hex(substr(_ucs2 0x00e400e50068,-1)); +hex(substr(_ucs2 0x00e400e50068,-1)) +0068 +select hex(substr(_ucs2 0x00e400e50068,-2)); +hex(substr(_ucs2 0x00e400e50068,-2)) +00E50068 +select hex(substr(_ucs2 0x00e400e50068,-3)); +hex(substr(_ucs2 0x00e400e50068,-3)) +00E400E50068 SET NAMES latin1; SET collation_connection='ucs2_swedish_ci'; CREATE TABLE t1 (Field1 int(10) default '0'); diff --git a/mysql-test/t/ctype_ucs.test b/mysql-test/t/ctype_ucs.test index db5b13cf1b4..6c72c409463 100644 --- a/mysql-test/t/ctype_ucs.test +++ b/mysql-test/t/ctype_ucs.test @@ -374,6 +374,16 @@ SET NAMES latin1; SET collation_connection='ucs2_bin'; -- source include/ctype_filesort.inc +# +# Bug#10344 Some string functions fail for UCS2 +# +select hex(substr(_ucs2 0x00e400e50068,1)); +select hex(substr(_ucs2 0x00e400e50068,2)); +select hex(substr(_ucs2 0x00e400e50068,3)); +select hex(substr(_ucs2 0x00e400e50068,-1)); +select hex(substr(_ucs2 0x00e400e50068,-2)); +select hex(substr(_ucs2 0x00e400e50068,-3)); + SET NAMES latin1; # # Bug#8235 diff --git a/strings/ctype-ucs2.c b/strings/ctype-ucs2.c index f5d0721fa9b..f12cfe3256e 100644 --- a/strings/ctype-ucs2.c +++ b/strings/ctype-ucs2.c @@ -1261,7 +1261,7 @@ uint my_charpos_ucs2(CHARSET_INFO *cs __attribute__((unused)), const char *e __attribute__((unused)), uint pos) { - return pos*2; + return pos > e - b ? e - b + 2 : pos * 2; }