|
|
@ -313,19 +313,20 @@ enlargeStringInfo(StringInfo str, int needed) |
|
|
|
* for efficiency, double the buffer size each time it overflows. |
|
|
|
* for efficiency, double the buffer size each time it overflows. |
|
|
|
* Actually, we might need to more than double it if 'needed' is big... |
|
|
|
* Actually, we might need to more than double it if 'needed' is big... |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
newlen = 2 * str->maxlen; |
|
|
|
newlen = 2 * (Size) str->maxlen; |
|
|
|
while (needed > newlen) |
|
|
|
while ((Size) needed > newlen) |
|
|
|
newlen = 2 * newlen; |
|
|
|
newlen = 2 * newlen; |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Clamp to the limit in case we went past it. Note we are assuming here |
|
|
|
* Clamp to the limit in case we went past it. (We used to depend on |
|
|
|
* that limit <= INT_MAX/2, else the above loop could overflow. We will |
|
|
|
* limit <= INT32_MAX/2, to avoid overflow in the loop above; we no longer |
|
|
|
* still have newlen >= needed. |
|
|
|
* depend on that, but if "needed" and str->maxlen ever become wider, we |
|
|
|
|
|
|
|
* will need similar caution here.) We will still have newlen >= needed. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
if (newlen > limit) |
|
|
|
if (newlen > limit) |
|
|
|
newlen = limit; |
|
|
|
newlen = limit; |
|
|
|
|
|
|
|
|
|
|
|
str->data = (char *) repalloc_huge(str->data, (Size) newlen); |
|
|
|
str->data = (char *) repalloc_huge(str->data, newlen); |
|
|
|
|
|
|
|
|
|
|
|
str->maxlen = newlen; |
|
|
|
str->maxlen = newlen; |
|
|
|
} |
|
|
|
} |
|
|
|