| 128 | */ |
| 129 | |
| 130 | void *alloc_dynamic(DYNAMIC_ARRAY *array) |
| 131 | { |
| 132 | if (array->elements == array->max_element) |
| 133 | { |
| 134 | char *new_ptr; |
| 135 | if (array->buffer == (uchar *)(array + 1)) |
| 136 | { |
| 137 | /* |
| 138 | In this senerio, the buffer is statically preallocated, |
| 139 | so we have to create an all-new malloc since we overflowed |
| 140 | */ |
| 141 | if (!(new_ptr= (char *) my_malloc((array->max_element+ |
| 142 | array->alloc_increment) * |
| 143 | array->size_of_element, |
| 144 | MYF(MY_WME)))) |
| 145 | return 0; |
| 146 | memcpy(new_ptr, array->buffer, |
| 147 | array->elements * array->size_of_element); |
| 148 | } |
| 149 | else |
| 150 | if (!(new_ptr=(char*) my_realloc(array->buffer,(array->max_element+ |
| 151 | array->alloc_increment)* |
| 152 | array->size_of_element, |
| 153 | MYF(MY_WME | MY_ALLOW_ZERO_PTR)))) |
| 154 | return 0; |
| 155 | array->buffer= (uchar*) new_ptr; |
| 156 | array->max_element+=array->alloc_increment; |
| 157 | } |
| 158 | return array->buffer+(array->elements++ * array->size_of_element); |
| 159 | } |
| 160 | |
| 161 | |
| 162 | /* |
no test coverage detected