| 268 | */ |
| 269 | |
| 270 | my_bool allocate_dynamic(DYNAMIC_ARRAY *array, size_t max_elements) |
| 271 | { |
| 272 | DBUG_ENTER("allocate_dynamic"); |
| 273 | |
| 274 | if (max_elements >= array->max_element) |
| 275 | { |
| 276 | size_t size; |
| 277 | uchar *new_ptr; |
| 278 | size= (max_elements + array->alloc_increment)/array->alloc_increment; |
| 279 | size*= array->alloc_increment; |
| 280 | if (array->malloc_flags & MY_INIT_BUFFER_USED) |
| 281 | { |
| 282 | /* |
| 283 | In this scenario, the buffer is statically preallocated, |
| 284 | so we have to create an all-new malloc since we overflowed |
| 285 | */ |
| 286 | if (!(new_ptr= (uchar *) my_malloc(array->m_psi_key, size * |
| 287 | array->size_of_element, |
| 288 | MYF(array->malloc_flags | MY_WME)))) |
| 289 | DBUG_RETURN(TRUE); |
| 290 | memcpy(new_ptr, array->buffer, |
| 291 | array->elements * array->size_of_element); |
| 292 | array->malloc_flags&= ~MY_INIT_BUFFER_USED; |
| 293 | } |
| 294 | else if (!(new_ptr= (uchar*) my_realloc(array->m_psi_key, |
| 295 | array->buffer,size * |
| 296 | array->size_of_element, |
| 297 | MYF(MY_WME | MY_ALLOW_ZERO_PTR | |
| 298 | array->malloc_flags)))) |
| 299 | DBUG_RETURN(TRUE); |
| 300 | array->buffer= new_ptr; |
| 301 | array->max_element= size; |
| 302 | } |
| 303 | DBUG_RETURN(FALSE); |
| 304 | } |
| 305 | |
| 306 | |
| 307 | /* |
no test coverage detected