From 0fc999dcd0160527c2539c66f03e914f5678f5c8 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Tue, 21 Dec 2010 01:22:03 +0000 Subject: 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@ --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'main.c') 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 * Copyright (c) 2010 Ingo Schwarze @@ -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); -- cgit v1.2.3