| XML_HIDDEN void | |
| xmlInitMemoryInternal(void); | |
| XML_HIDDEN void | |
| xmlCleanupMemoryInternal(void); | |
| /** | |
| * @array: pointer to array | |
| * @capacity: pointer to capacity (in/out) | |
| * @elemSize: size of an element in bytes | |
| * @min: elements in initial allocation | |
| * @max: maximum elements in the array | |
| * | |
| * Grow an array by at least one element, checking for overflow. | |
| * | |
| * Returns the new array size on success, -1 on failure. | |
| */ | |
| static XML_INLINE int | |
| xmlGrowCapacity(int capacity, size_t elemSize, int min, int max) { | |
| int extra; | |
| if (capacity <= 0) { | |
| (void) min; | |
| return(1); | |
| return(min); | |
| } | |
| if ((capacity >= max) || | |
| ((size_t) capacity > SIZE_MAX / 2 / elemSize)) | |
| return(-1); | |
| /* Grow by 50% */ | |
| extra = (capacity + 1) / 2; | |
| if (capacity > max - extra) | |
| return(max); | |
| return(capacity + extra); | |
| } | |