Bug #30981 CHAR(0x41 USING ucs2) doesn't add leading zero

Submitted: 12 Sep 2007 15:43 Modified: 30 Oct 2007 0:44
Reporter: Alexander Barkov Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Charsets Severity:S3 (Non-critical)
Version:5.0/5.1 OS:Any
Assigned to: Sergei Glukhov CPU Architecture:Any

[12 Sep 2007 15:43] Alexander Barkov
Description:
CHAR(0x41 USING ucs2)  doesn't add leading zero and returns a wrong ucs2 string.

How to repeat:
mysql> select hex(char(0x41 using ucs2));
+----------------------------+
| hex(char(0x41 using ucs2)) |
+----------------------------+
| 41                         |
+----------------------------+
1 row in set, 1 warning (0.00 sec)

The expected result is 0041.

Note, a hex literal with character set introducer works fine:

mysql> select hex(_ucs2 0x41);
+-----------------+
| hex(_ucs2 0x41) |
+-----------------+
| 0041            |
+-----------------+
1 row in set (0.00 sec)

Suggested fix:
Fix CHAR(..USING..) to pad leading zero, like a literal with introducer does.
[12 Sep 2007 16:07] MySQL Verification Team
Thank you for the bug report.
[10 Oct 2007 14:59] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/35292

ChangeSet@1.2536, 2007-10-10 19:55:01+05:00, gluh@mysql.com +9 -0
  Bug#30981 CHAR(0x41 USING ucs2) doesn't add leading zero
  Bug#30982 CHAR(..USING..) can return a not-well-formed string
  Bug#30986 Character set introducer followed by a HEX string can return bad result
  check_well_formed_result moved to Item
  fixed Item_func_char::val_str for proper ucs symbols converting
  added check for well formed strings for correct conversion of constants with underscore carset
[11 Oct 2007 8:51] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/35327

ChangeSet@1.2536, 2007-10-11 13:46:50+05:00, gluh@mysql.com +9 -0
  Bug#30981 CHAR(0x41 USING ucs2) doesn't add leading zero
  Bug#30982 CHAR(..USING..) can return a not-well-formed string
  Bug#30986 Character set introducer followed by a HEX string can return bad result
  check_well_formed_result moved to Item from Item_str_func
  fixed Item_func_char::val_str for proper ucs symbols converting
  added check for well formed strings for correct conversion of constants with underscore
  charset
[11 Oct 2007 10:22] Alexander Barkov
Ok to push
[11 Oct 2007 11:11] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/35339

ChangeSet@1.2537, 2007-10-11 16:07:10+05:00, gluh@mysql.com +9 -0
  Bug#30981 CHAR(0x41 USING ucs2) doesn't add leading zero
  Bug#30982 CHAR(..USING..) can return a not-well-formed string
  Bug#30986 Character set introducer followed by a HEX string can return bad result
  check_well_formed_result moved to Item from Item_str_func
  fixed Item_func_char::val_str for proper ucs symbols converting
  added check for well formed strings for correct conversion of constants with underscore
  charset
[29 Oct 2007 8:43] Bugs System
Pushed into 5.0.52
[29 Oct 2007 8:47] Bugs System
Pushed into 5.1.23-beta
[29 Oct 2007 8:51] Bugs System
Pushed into 6.0.4-alpha
[30 Oct 2007 0:44] Paul DuBois
Noted in 5.0.52, 5.1.23, 6.0.4 changelogs.

The result from CHAR(str USING ucs2) did not add a leading 0x00 byte
for input strings with an odd number of bytes.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.069 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.