void svn_stringbuf_ensure(svn_stringbuf_t *str, apr_size_t minimum_size) { /* Keep doubling capacity until have enough. */ if (str->blocksize < minimum_size) { if (str->blocksize == 0) str->blocksize = minimum_size; else while (str->blocksize < minimum_size) { apr_size_t prev_size = str->blocksize; str->blocksize *= 2; /* check for apr_size_t overflow */ if (prev_size > str->blocksize) { str->blocksize = minimum_size; break; } } str->data = (char *) my__realloc(str->data, str->len + 1, /* We need to maintain (and thus copy) the trailing nul */ str->blocksize, str->pool); } }
void svn_stringbuf_ensure(svn_stringbuf_t *str, apr_size_t minimum_size) { /* Keep doubling capacity until have enough. */ if (str->blocksize < minimum_size) { if (str->blocksize == 0) /* APR will increase odd allocation sizes to the next * multiple for 8, for instance. Take advantage of that * knowledge and allow for the extra size to be used. */ str->blocksize = APR_ALIGN_DEFAULT(minimum_size); else while (str->blocksize < minimum_size) { /* str->blocksize is aligned; * doubling it should keep it aligned */ apr_size_t prev_size = str->blocksize; str->blocksize *= 2; /* check for apr_size_t overflow */ if (prev_size > str->blocksize) { str->blocksize = minimum_size; break; } } str->data = (char *) my__realloc(str->data, str->len + 1, /* We need to maintain (and thus copy) the trailing nul */ str->blocksize, str->pool); } }