From f789158ddfa90933678dc927a05719ba692d0854 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Thu, 17 Sep 2015 19:49:49 +0400 Subject: The patch for MDEV-8466 revealed a bug in str2my_decimal, which did not return a correct "end_of_num" pointer in case of character sets with mbminlen>1 (ucs2, utf16, utf16le, utf32). The bug caused sporadic test failures on BuildBot, as well "uninitialized memory read" errors in valgrind builds. --- sql/my_decimal.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'sql') diff --git a/sql/my_decimal.cc b/sql/my_decimal.cc index 91455c7cb84..37d4dd25473 100644 --- a/sql/my_decimal.cc +++ b/sql/my_decimal.cc @@ -243,21 +243,21 @@ int str2my_decimal(uint mask, const char *from, uint length, const char **end_ptr) { int err; - char buff[STRING_BUFFER_USUAL_SIZE]; - String tmp(buff, sizeof(buff), &my_charset_bin); if (charset->mbminlen > 1) { + StringBuffer tmp; uint dummy_errors; tmp.copy(from, length, charset, &my_charset_latin1, &dummy_errors); - from= tmp.ptr(); - length= tmp.length(); - charset= &my_charset_bin; + char *end= (char*) tmp.end(); + err= string2decimal(tmp.ptr(), (decimal_t*) decimal_value, &end); + *end_ptr= from + charset->mbminlen * (size_t) (end - tmp.ptr()); + } + else + { + char *end= (char*) from + length; + err= string2decimal(from, (decimal_t*) decimal_value, &end); + *end_ptr= end; } - char *end= (char*) from + length; - err= string2decimal((char *)from, (decimal_t*) decimal_value, &end); - if (charset->mbminlen > 1) - end= (char *) from + charset->mbminlen * (size_t) (end - buff); - *end_ptr= end; check_result_and_overflow(mask, err, decimal_value); return err; } -- cgit v1.2.1