pool_get_name(buf->pool));
}
- buffer_alloc(buf, pool_get_exp_grown_size(buf->pool, buf->alloc,
- new_size + 1));
+ size_t new_alloc_size =
+ pool_get_exp_grown_size(buf->pool, buf->alloc,
+ new_size + 1);
+ if (new_alloc_size > buf->max_size) {
+ /* limit to max_size, but do include +1 for
+ str_c() NUL */
+ new_alloc_size = buf->max_size + 1;
+ }
+ buffer_alloc(buf, new_alloc_size);
}
#if 0
else if (new_size > buf->used && buf->alloced &&
current size it's grown. */
buffer_t *buffer_create_dynamic(pool_t pool, size_t init_size);
/* Create a dynamically growing buffer with a maximum size. Writes past the
- maximum size will i_panic(). */
+ maximum size will i_panic(). Internally allow it to grow max_size+1 so
+ str_c() NUL can be used. */
buffer_t *buffer_create_dynamic_max(pool_t pool, size_t init_size,
size_t max_size);