From 082e84c273052e7aebc04bb30529de7cc10bd297 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 16 Dec 2003 14:20:45 +0000 Subject: [PATCH] Fixed blatant allocation bug. --- tools/watchgnupg.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tools/watchgnupg.c b/tools/watchgnupg.c index d6ed36415..d74119a1a 100644 --- a/tools/watchgnupg.c +++ b/tools/watchgnupg.c @@ -139,19 +139,14 @@ print_line (client_t c, const char *line) line = s + 1; } n = strlen (line); - if (!c->buffer) + if (n) { - c->size = 256 - (n + 256) % 256; - c->buffer = xmalloc (c->size); - memcpy (c->buffer, line, n); - c->len = n; - } - else - { - if (c->len + n > c->size) + if (c->len + n >= c->size) { - c->size += 256 - (n + 256) % 256; - c->buffer = xrealloc (c->buffer, c->size); + c->size += ((n + 255) & ~255); + c->buffer = (c->buffer + ? xrealloc (c->buffer, c->size) + : xmalloc (c->size)); } memcpy (c->buffer + c->len, line, n); c->len += n;