#At file:///misc/mysql/forest/35848/60-35848/
2720 Tatiana A. Nurnberg 2008-07-16 [merge]
auto-merge
modified:
mysql-test/r/ctype_ucs.result
mysql-test/r/ctype_utf32.result
mysql-test/t/ctype_ucs.test
mysql-test/t/ctype_utf32.test
sql/item_strfunc.cc
sql/sql_string.cc
=== modified file 'mysql-test/r/ctype_ucs.result'
--- a/mysql-test/r/ctype_ucs.result 2008-03-27 19:02:15 +0000
+++ b/mysql-test/r/ctype_ucs.result 2008-07-16 10:39:12 +0000
@@ -1261,3 +1261,15 @@ FF9EFF9DFF9CFFDFFFDF
select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
DFFFDFFF9CFF9DFF9EFF
+select hex(char(0x01 using ucs2));
+hex(char(0x01 using ucs2))
+0001
+select hex(char(0x0102 using ucs2));
+hex(char(0x0102 using ucs2))
+0102
+select hex(char(0x010203 using ucs2));
+hex(char(0x010203 using ucs2))
+00010203
+select hex(char(0x01020304 using ucs2));
+hex(char(0x01020304 using ucs2))
+01020304
=== modified file 'mysql-test/r/ctype_utf32.result'
--- a/mysql-test/r/ctype_utf32.result 2007-12-06 07:42:19 +0000
+++ b/mysql-test/r/ctype_utf32.result 2008-07-16 10:39:12 +0000
@@ -1049,3 +1049,24 @@ NULL
NULL
drop table t1;
set names latin1;
+select hex(char(0x01 using utf32));
+hex(char(0x01 using utf32))
+00000001
+select hex(char(0x0102 using utf32));
+hex(char(0x0102 using utf32))
+00000102
+select hex(char(0x010203 using utf32));
+hex(char(0x010203 using utf32))
+00010203
+select hex(char(0x01020304 using utf32));
+hex(char(0x01020304 using utf32))
+
+Warnings:
+Warning 1300 Invalid utf32 character string: '010203'
+create table t1 (s1 varchar(1) character set utf32, s2 text character set utf32);
+create index i on t1 (s1);
+insert into t1 values (char(256 using utf32), char(256 using utf32));
+select hex(s1), hex(s2) from t1;
+hex(s1) hex(s2)
+00000100 00000100
+drop table t1;
=== modified file 'mysql-test/t/ctype_ucs.test'
--- a/mysql-test/t/ctype_ucs.test 2008-03-27 19:02:15 +0000
+++ b/mysql-test/t/ctype_ucs.test 2008-07-16 10:39:12 +0000
@@ -654,3 +654,11 @@ set collation_connection=ucs2_general_ci
set collation_connection=ucs2_bin;
-- source include/weight_string.inc
--source include/weight_string_l1.inc
+
+#
+# Bug #36418 Character sets: crash if char(256 using utf32)
+#
+select hex(char(0x01 using ucs2));
+select hex(char(0x0102 using ucs2));
+select hex(char(0x010203 using ucs2));
+select hex(char(0x01020304 using ucs2));
=== modified file 'mysql-test/t/ctype_utf32.test'
--- a/mysql-test/t/ctype_utf32.test 2007-12-06 07:42:19 +0000
+++ b/mysql-test/t/ctype_utf32.test 2008-07-16 10:39:12 +0000
@@ -718,3 +718,16 @@ set collation_connection=utf32_general_c
set names latin1;
# TODO: add tests for all engines
+
+#
+# Bug #36418 Character sets: crash if char(256 using utf32)
+#
+select hex(char(0x01 using utf32));
+select hex(char(0x0102 using utf32));
+select hex(char(0x010203 using utf32));
+select hex(char(0x01020304 using utf32));
+create table t1 (s1 varchar(1) character set utf32, s2 text character set utf32);
+create index i on t1 (s1);
+insert into t1 values (char(256 using utf32), char(256 using utf32));
+select hex(s1), hex(s2) from t1;
+drop table t1;
=== modified file 'sql/item_strfunc.cc'
--- a/sql/item_strfunc.cc 2008-07-11 00:00:15 +0000
+++ b/sql/item_strfunc.cc 2008-07-16 10:39:12 +0000
@@ -2465,17 +2465,27 @@ String *Item_func_char::val_str(String *
int32 num=(int32) args[i]->val_int();
if (!args[i]->null_value)
{
- char char_num= (char) num;
- if (num&0xFF000000L) {
- str->append((char)(num>>24));
- goto b2;
- } else if (num&0xFF0000L) {
- b2: str->append((char)(num>>16));
- goto b1;
- } else if (num&0xFF00L) {
- b1: str->append((char)(num>>8));
+ char tmp[4];
+ if (num & 0xFF000000L)
+ {
+ mi_int4store(tmp, num);
+ str->append(tmp, 4, &my_charset_bin);
+ }
+ else if (num & 0xFF0000L)
+ {
+ mi_int3store(tmp, num);
+ str->append(tmp, 3, &my_charset_bin);
+ }
+ else if (num & 0xFF00L)
+ {
+ mi_int2store(tmp, num);
+ str->append(tmp, 2, &my_charset_bin);
+ }
+ else
+ {
+ tmp[0]= (char) num;
+ str->append(tmp, 1, &my_charset_bin);
}
- str->append(&char_num, 1);
}
}
str->realloc(str->length()); // Add end 0 (for Purify)
=== modified file 'sql/sql_string.cc'
--- a/sql/sql_string.cc 2008-05-22 18:40:15 +0000
+++ b/sql/sql_string.cc 2008-07-16 10:39:12 +0000
@@ -407,11 +407,25 @@ bool String::append(const char *s)
bool String::append(const char *s,uint32 arg_length, CHARSET_INFO *cs)
{
- uint32 dummy_offset;
+ uint32 offset;
- if (needs_conversion(arg_length, cs, str_charset, &dummy_offset))
+ if (needs_conversion(arg_length, cs, str_charset, &offset))
{
- uint32 add_length= arg_length / cs->mbminlen * str_charset->mbmaxlen;
+ uint32 add_length;
+ if ((cs == &my_charset_bin) && offset)
+ {
+ DBUG_ASSERT(str_charset->mbminlen > offset);
+ offset= str_charset->mbminlen - offset; // How many characters to pad
+ add_length= arg_length + offset;
+ if (realloc(str_length + add_length))
+ return TRUE;
+ bzero((char*) Ptr + str_length, offset);
+ memcpy(Ptr + str_length + offset, s, arg_length);
+ str_length+= add_length;
+ return FALSE;
+ }
+
+ add_length= arg_length / cs->mbminlen * str_charset->mbmaxlen;
uint dummy_errors;
if (realloc(str_length + add_length))
return TRUE;
| Thread |
|---|
| • bzr commit into mysql-6.0 branch (azundris:2720) | Tatiana A. Nurnberg | 16 Jul |