Skip to content

Commit f789158

Browse files
author
Alexander Barkov
committed
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.
1 parent c83810f commit f789158

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

sql/my_decimal.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,21 +243,21 @@ int str2my_decimal(uint mask, const char *from, uint length,
243243
const char **end_ptr)
244244
{
245245
int err;
246-
char buff[STRING_BUFFER_USUAL_SIZE];
247-
String tmp(buff, sizeof(buff), &my_charset_bin);
248246
if (charset->mbminlen > 1)
249247
{
248+
StringBuffer<STRING_BUFFER_USUAL_SIZE> tmp;
250249
uint dummy_errors;
251250
tmp.copy(from, length, charset, &my_charset_latin1, &dummy_errors);
252-
from= tmp.ptr();
253-
length= tmp.length();
254-
charset= &my_charset_bin;
251+
char *end= (char*) tmp.end();
252+
err= string2decimal(tmp.ptr(), (decimal_t*) decimal_value, &end);
253+
*end_ptr= from + charset->mbminlen * (size_t) (end - tmp.ptr());
254+
}
255+
else
256+
{
257+
char *end= (char*) from + length;
258+
err= string2decimal(from, (decimal_t*) decimal_value, &end);
259+
*end_ptr= end;
255260
}
256-
char *end= (char*) from + length;
257-
err= string2decimal((char *)from, (decimal_t*) decimal_value, &end);
258-
if (charset->mbminlen > 1)
259-
end= (char *) from + charset->mbminlen * (size_t) (end - buff);
260-
*end_ptr= end;
261261
check_result_and_overflow(mask, err, decimal_value);
262262
return err;
263263
}

0 commit comments

Comments
 (0)