Commit a9ca8198 authored by Monty's avatar Monty

Call alloc() instead of realloc()

Use alloc() if we don't need original string (avoid copy)
Removed not needed test of str_length in sql_string.cc
parent 5180eda3
...@@ -916,7 +916,7 @@ String *Item_func_point::val_str(String *str) ...@@ -916,7 +916,7 @@ String *Item_func_point::val_str(String *str)
if ((null_value= (args[0]->null_value || if ((null_value= (args[0]->null_value ||
args[1]->null_value || args[1]->null_value ||
str->realloc(4/*SRID*/ + 1 + 4 + SIZEOF_STORED_DOUBLE * 2)))) str->alloc(4/*SRID*/ + 1 + 4 + SIZEOF_STORED_DOUBLE * 2))))
return 0; return 0;
str->set_charset(&my_charset_bin); str->set_charset(&my_charset_bin);
......
...@@ -255,7 +255,7 @@ String *Item_func_sha2::val_str_ascii(String *str) ...@@ -255,7 +255,7 @@ String *Item_func_sha2::val_str_ascii(String *str)
Since we're subverting the usual String methods, we must make sure that Since we're subverting the usual String methods, we must make sure that
the destination has space for the bytes we're about to write. the destination has space for the bytes we're about to write.
*/ */
str->realloc((uint) digest_length*2 + 1); /* Each byte as two nybbles */ str->alloc((uint) digest_length*2 + 1); /* Each byte as two nybbles */
/* Convert the large number to a string-hex representation. */ /* Convert the large number to a string-hex representation. */
array_to_hex((char *) str->ptr(), digest_buf, (uint)digest_length); array_to_hex((char *) str->ptr(), digest_buf, (uint)digest_length);
...@@ -762,7 +762,7 @@ String *Item_func_des_encrypt::val_str(String *str) ...@@ -762,7 +762,7 @@ String *Item_func_des_encrypt::val_str(String *str)
tail= 8 - (res_length % 8); // 1..8 marking extra length tail= 8 - (res_length % 8); // 1..8 marking extra length
res_length+=tail; res_length+=tail;
if (tmp_arg.realloc(res_length)) if (tmp_arg.alloc(res_length))
goto error; goto error;
tmp_arg.length(0); tmp_arg.length(0);
tmp_arg.append(res->ptr(), res->length()); tmp_arg.append(res->ptr(), res->length());
...@@ -770,7 +770,6 @@ String *Item_func_des_encrypt::val_str(String *str) ...@@ -770,7 +770,6 @@ String *Item_func_des_encrypt::val_str(String *str)
if (tmp_arg.append(append_str, tail) || str->alloc(res_length+1)) if (tmp_arg.append(append_str, tail) || str->alloc(res_length+1))
goto error; goto error;
tmp_arg[res_length-1]=tail; // save extra length tmp_arg[res_length-1]=tail; // save extra length
str->realloc(res_length+1);
str->length(res_length+1); str->length(res_length+1);
str->set_charset(&my_charset_bin); str->set_charset(&my_charset_bin);
(*str)[0]=(char) (128 | key_number); (*str)[0]=(char) (128 | key_number);
...@@ -1017,7 +1016,7 @@ String *Item_func_concat_ws::val_str(String *str) ...@@ -1017,7 +1016,7 @@ String *Item_func_concat_ws::val_str(String *str)
{ {
uint new_len = MY_MAX(tmp_value.alloced_length() * 2, concat_len); uint new_len = MY_MAX(tmp_value.alloced_length() * 2, concat_len);
if (tmp_value.realloc(new_len)) if (tmp_value.alloc(new_len))
goto null; goto null;
} }
} }
...@@ -1072,8 +1071,7 @@ String *Item_func_reverse::val_str(String *str) ...@@ -1072,8 +1071,7 @@ String *Item_func_reverse::val_str(String *str)
/* An empty string is a special case as the string pointer may be null */ /* An empty string is a special case as the string pointer may be null */
if (!res->length()) if (!res->length())
return make_empty_result(); return make_empty_result();
if (str->alloced_length() < res->length() && if (str->alloc(res->length()))
str->realloc(res->length()))
{ {
null_value= 1; null_value= 1;
return 0; return 0;
...@@ -4178,7 +4176,7 @@ String *Item_func_compress::val_str(String *str) ...@@ -4178,7 +4176,7 @@ String *Item_func_compress::val_str(String *str)
// Check new_size overflow: new_size <= res->length() // Check new_size overflow: new_size <= res->length()
if (((uint32) (new_size+5) <= res->length()) || if (((uint32) (new_size+5) <= res->length()) ||
str->realloc((uint32) new_size + 4 + 1)) str->alloc((uint32) new_size + 4 + 1))
{ {
null_value= 1; null_value= 1;
return 0; return 0;
...@@ -4250,7 +4248,7 @@ String *Item_func_uncompress::val_str(String *str) ...@@ -4250,7 +4248,7 @@ String *Item_func_uncompress::val_str(String *str)
max_allowed_packet)); max_allowed_packet));
goto err; goto err;
} }
if (str->realloc((uint32)new_size)) if (str->alloc((uint32)new_size))
goto err; goto err;
if ((err= uncompress((Byte*)str->ptr(), &new_size, if ((err= uncompress((Byte*)str->ptr(), &new_size,
...@@ -4279,7 +4277,7 @@ String *Item_func_uuid::val_str(String *str) ...@@ -4279,7 +4277,7 @@ String *Item_func_uuid::val_str(String *str)
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
uchar guid[MY_UUID_SIZE]; uchar guid[MY_UUID_SIZE];
str->realloc(MY_UUID_STRING_LENGTH+1); str->alloc(MY_UUID_STRING_LENGTH+1);
str->length(MY_UUID_STRING_LENGTH); str->length(MY_UUID_STRING_LENGTH);
str->set_charset(system_charset_info); str->set_charset(system_charset_info);
my_uuid(guid); my_uuid(guid);
......
...@@ -480,8 +480,7 @@ static void make_base_query(String *new_query, ...@@ -480,8 +480,7 @@ static void make_base_query(String *new_query,
/* We do not support UCS2, UTF16, UTF32 as a client character set */ /* We do not support UCS2, UTF16, UTF32 as a client character set */
DBUG_ASSERT(current_thd->variables.character_set_client->mbminlen == 1); DBUG_ASSERT(current_thd->variables.character_set_client->mbminlen == 1);
new_query->length(0); // Don't copy anything from old buffer if (new_query->alloc(query_length + additional_length))
if (new_query->realloc(query_length + additional_length))
{ {
/* /*
We could not allocate the query. Use original query for We could not allocate the query. Use original query for
......
...@@ -3220,7 +3220,7 @@ int select_export::send_data(List<Item> &items) ...@@ -3220,7 +3220,7 @@ int select_export::send_data(List<Item> &items)
((uint64) res->length() / res->charset()->mbminlen + 1) * ((uint64) res->length() / res->charset()->mbminlen + 1) *
write_cs->mbmaxlen + 1; write_cs->mbmaxlen + 1;
set_if_smaller(estimated_bytes, UINT_MAX32); set_if_smaller(estimated_bytes, UINT_MAX32);
if (cvt_str.realloc((uint32) estimated_bytes)) if (cvt_str.alloc((uint32) estimated_bytes))
{ {
my_error(ER_OUTOFMEMORY, MYF(ME_FATAL), (uint32) estimated_bytes); my_error(ER_OUTOFMEMORY, MYF(ME_FATAL), (uint32) estimated_bytes);
goto err; goto err;
......
...@@ -103,8 +103,7 @@ bool String::realloc_raw(size_t alloc_length) ...@@ -103,8 +103,7 @@ bool String::realloc_raw(size_t alloc_length)
(thread_specific ? (thread_specific ?
MY_THREAD_SPECIFIC : 0))))) MY_THREAD_SPECIFIC : 0)))))
{ {
if (str_length > len - 1) DBUG_ASSERT(str_length < len);
str_length= 0;
if (str_length) // Avoid bugs in memcpy on AIX if (str_length) // Avoid bugs in memcpy on AIX
memcpy(new_ptr,Ptr,str_length); memcpy(new_ptr,Ptr,str_length);
new_ptr[str_length]=0; new_ptr[str_length]=0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment