From: Peter Verthez Date: Sat, 21 Dec 2002 15:37:00 +0000 (+0000) Subject: Fix for initialization of buffer in grow_buffer. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=15c373d0e5dfc9d970e41f705dcfdbe2812be019;p=gedcom-parse.git Fix for initialization of buffer in grow_buffer. --- diff --git a/gedcom/buffer.c b/gedcom/buffer.c index 8873529..0c3e17c 100644 --- a/gedcom/buffer.c +++ b/gedcom/buffer.c @@ -70,9 +70,17 @@ void init_buffer(struct safe_buffer *b) void grow_buffer(struct safe_buffer *b) { + char* new_buffer; + size_t old_size = b->bufsize; b->bufsize *= 2; - b->buffer = realloc(b->buffer, b->bufsize); - b->buf_end = b->buffer + b->buflen; + new_buffer = realloc(b->buffer, b->bufsize); + if (new_buffer) { + b->buffer = new_buffer; + memset(b->buffer + old_size, 0, b->bufsize - old_size); + b->buf_end = b->buffer + b->buflen; + } + else + b->buffer = NULL; } int safe_buf_vappend(struct safe_buffer *b, const char *s, va_list ap)