summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2010-12-21 01:22:03 +0000
committerIngo Schwarze <schwarze@openbsd.org>2010-12-21 01:22:03 +0000
commit89afd774a62676944d20a0310ee40c58522e2c3e (patch)
tree2b35ffa204eb7c7e2b07198d1ab1433f44ce74b1 /main.c
parent2dd3befffd75653b5591451707b63f7343e9670c (diff)
downloadmandoc-89afd774a62676944d20a0310ee40c58522e2c3e.tar.gz
Sane behaviour for the growing of very small buffers:
Always grow at least to the minimum requested size. Before this, a buffer of 1 byte was grown to 2 bytes, which was too small and sometimes caused segfaults. ok kristaps@
Diffstat (limited to 'main.c')
-rw-r--r--main.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/main.c b/main.c
index f77f0aee..f6c625ec 100644
--- a/main.c
+++ b/main.c
@@ -389,7 +389,7 @@ static void
resize_buf(struct buf *buf, size_t initial)
{
- buf->sz = buf->sz ? 2 * buf->sz : initial;
+ buf->sz = buf->sz > initial/2 ? 2 * buf->sz : initial;
buf->buf = realloc(buf->buf, buf->sz);
if (NULL == buf->buf) {
perror(NULL);