aboutsummaryrefslogtreecommitdiffstatshomepage
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
commit0fc999dcd0160527c2539c66f03e914f5678f5c8 (patch)
tree944cceacf12f832dd1d175295f6548004dc4d88a /main.c
parent85c74441826371ba4a7f855c3400e2694aa595d5 (diff)
downloadmandoc-0fc999dcd0160527c2539c66f03e914f5678f5c8.tar.gz
mandoc-0fc999dcd0160527c2539c66f03e914f5678f5c8.tar.zst
mandoc-0fc999dcd0160527c2539c66f03e914f5678f5c8.zip
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.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/main.c b/main.c
index 79a252e9..59f8fc69 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.123 2010/12/15 23:39:40 kristaps Exp $ */
+/* $Id: main.c,v 1.124 2010/12/21 01:22:03 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -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);