Avoid warnings in String::copy when copying string on itself (ok to do)

This commit is contained in:
Monty 2018-05-24 19:09:33 +03:00
parent 5a16fe0e6f
commit 199517f501

View File

@ -183,7 +183,16 @@ bool String::copy(const char *str,uint32 arg_length, CHARSET_INFO *cs)
{
if (alloc(arg_length))
return TRUE;
if ((str_length=arg_length))
if (Ptr == str && arg_length == str_length)
{
/*
This can happen in some cases. This code is here mainly to avoid
warnings from valgrind, but can also be an indication of error.
*/
DBUG_PRINT("warning", ("Copying string on itself: %p %lu",
str, arg_length));
}
else if ((str_length=arg_length))
memcpy(Ptr,str,arg_length);
Ptr[arg_length]=0;
str_charset=cs;