aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2003-12-16 14:20:45 +0000
committerWerner Koch <[email protected]>2003-12-16 14:20:45 +0000
commit082e84c273052e7aebc04bb30529de7cc10bd297 (patch)
tree6d225626922b48ac9976e2a18a71ced5d7f54d44
parentAdd simple tool to watch the log output of gnupg and related modules. (diff)
downloadgnupg-082e84c273052e7aebc04bb30529de7cc10bd297.tar.gz
gnupg-082e84c273052e7aebc04bb30529de7cc10bd297.zip
Fixed blatant allocation bug.
-rw-r--r--tools/watchgnupg.c17
1 files 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;