diff options
author | Werner Koch <wk@gnupg.org> | 2003-12-16 15:20:45 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2003-12-16 15:20:45 +0100 |
commit | 082e84c273052e7aebc04bb30529de7cc10bd297 (patch) | |
tree | 6d225626922b48ac9976e2a18a71ced5d7f54d44 /tools/watchgnupg.c | |
parent | Add simple tool to watch the log output of gnupg and related modules. (diff) | |
download | gnupg2-082e84c273052e7aebc04bb30529de7cc10bd297.tar.xz gnupg2-082e84c273052e7aebc04bb30529de7cc10bd297.zip |
Fixed blatant allocation bug.
Diffstat (limited to 'tools/watchgnupg.c')
-rw-r--r-- | tools/watchgnupg.c | 17 |
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; |