Allocates a new buffer on the heap for this String. - If the String's internal buffer is privately owned and heap allocated, one of the following is performed. - If the requested length is greater than what fits in the buffer, a new buffer is allocated, data moved and the old buffer freed. - If the requested length is less or equal to what fits in the buffer, a n
| 80 | @retval true An error occured when attempting to allocate memory. |
| 81 | */ |
| 82 | bool String::realloc(uint32 alloc_length) |
| 83 | { |
| 84 | uint32 len=ALIGN_SIZE(alloc_length+1); |
| 85 | DBUG_ASSERT(len > alloc_length); |
| 86 | if (len <= alloc_length) |
| 87 | return TRUE; /* Overflow */ |
| 88 | if (Alloced_length < len) |
| 89 | { |
| 90 | char *new_ptr; |
| 91 | if (alloced) |
| 92 | { |
| 93 | if (!(new_ptr= (char*) my_realloc(Ptr,len,MYF(MY_WME)))) |
| 94 | return TRUE; // Signal error |
| 95 | } |
| 96 | else if ((new_ptr= (char*) my_malloc(len,MYF(MY_WME)))) |
| 97 | { |
| 98 | if (str_length > len - 1) |
| 99 | str_length= 0; |
| 100 | if (str_length) // Avoid bugs in memcpy on AIX |
| 101 | memcpy(new_ptr,Ptr,str_length); |
| 102 | new_ptr[str_length]=0; |
| 103 | alloced=1; |
| 104 | } |
| 105 | else |
| 106 | return TRUE; // Signal error |
| 107 | Ptr= new_ptr; |
| 108 | Alloced_length= len; |
| 109 | } |
| 110 | Ptr[alloc_length]=0; // This make other funcs shorter |
| 111 | return FALSE; |
| 112 | } |
| 113 | |
| 114 | bool String::set_int(longlong num, bool unsigned_flag, const CHARSET_INFO *cs) |
| 115 | { |
no test coverage detected