Mercurial > hg > th-libs
changeset 33:06a72c643460
Sync.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 11 Jun 2011 12:52:57 +0300 |
parents | 7e0a2a125830 |
children | 8dac45860fc7 |
files | th_util.c th_util.h |
diffstat | 2 files changed, 10 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/th_util.c Sat Jun 11 05:05:22 2011 +0300 +++ b/th_util.c Sat Jun 11 12:52:57 2011 +0300 @@ -403,7 +403,7 @@ { qringbuf_t *res = th_calloc(1, sizeof(qringbuf_t)); - res->data = (void **) th_malloc(size * sizeof(void *)); + res->data = (char **) th_calloc(size, sizeof(char *)); res->size = size; res->n = 0; res->deallocator = mdeallocator; @@ -414,9 +414,13 @@ BOOL th_ringbuf_grow(qringbuf_t *buf, const size_t n) { - buf->size += n; - buf->data = (void **) th_realloc(buf->data, buf->size * sizeof(void *)); - return (buf->data != NULL); + buf->data = (char **) th_realloc(buf->data, (buf->size + n) * sizeof(char *)); + if (buf->data != NULL) { + memset(buf->data + buf->size, 0, sizeof(char *) * n); + buf->size += n; + return TRUE; + } else + return FALSE; } @@ -424,7 +428,7 @@ { int i; - for (i = 0; i < buf->n; i++) + for (i = 0; i < buf->size; i++) if (buf->data[i] != NULL) buf->deallocator(buf->data[i]);