| 229 | */ |
| 230 | |
| 231 | my_bool allocate_dynamic(DYNAMIC_ARRAY *array, ulong max_elements) |
| 232 | { |
| 233 | if (max_elements >= array->max_element) |
| 234 | { |
| 235 | ulong size; |
| 236 | uchar *new_ptr; |
| 237 | size= (max_elements + array->alloc_increment)/array->alloc_increment; |
| 238 | size*= array->alloc_increment; |
| 239 | if (array->buffer == (uchar *)(array + 1)) |
| 240 | { |
| 241 | /* |
| 242 | In this senerio, the buffer is statically preallocated, |
| 243 | so we have to create an all-new malloc since we overflowed |
| 244 | */ |
| 245 | if (!(new_ptr= (uchar *) my_malloc(size * |
| 246 | array->size_of_element, |
| 247 | MYF(MY_WME)))) |
| 248 | return 0; |
| 249 | memcpy(new_ptr, array->buffer, |
| 250 | array->elements * array->size_of_element); |
| 251 | } |
| 252 | else |
| 253 | |
| 254 | |
| 255 | if (!(new_ptr= (uchar*) my_realloc(array->buffer,size* |
| 256 | array->size_of_element, |
| 257 | MYF(MY_WME | MY_ALLOW_ZERO_PTR)))) |
| 258 | return TRUE; |
| 259 | array->buffer= new_ptr; |
| 260 | array->max_element= size; |
| 261 | } |
| 262 | return FALSE; |
| 263 | } |
| 264 | |
| 265 | |
| 266 | /* |
no test coverage detected