if (!buf)
return;
+ if (!buf->dptr)
+ buf->dptr = buf->data;
+
if (new_size <= buf->dsize)
return;
- size_t offset = buf->dptr - buf->data;
+ size_t offset = (buf->dptr && buf->data) ? buf->dptr - buf->data : 0;
+
buf->dsize = new_size;
mutt_mem_realloc(&buf->data, buf->dsize);
buf->dptr = buf->data + offset;
mutt_buffer_increase_size(NULL, 10);
TEST_CHECK_(1, "mutt_buffer_increase_size(NULL, 10)");
}
+
+ {
+ struct Buffer *buf = mutt_buffer_new();
+ mutt_buffer_increase_size(buf, 10);
+ TEST_CHECK_(1, "mutt_buffer_increase_size(buf, 10)");
+ mutt_buffer_free(&buf);
+ }
+
+ {
+ const int orig_size = 64;
+ static int sizes[] = { 0, 32, 64, 128 };
+
+ for (size_t i = 0; i < mutt_array_size(sizes); i++)
+ {
+ struct Buffer *buf = mutt_buffer_alloc(orig_size);
+ TEST_CASE_("%d", sizes[i]);
+ mutt_buffer_increase_size(buf, sizes[i]);
+ TEST_CHECK(buf->dsize == MAX(orig_size, sizes[i]));
+ mutt_buffer_free(&buf);
+ }
+
+ }
+
+
}