changeset 306:21528fe535fb

Don't use void pointers in the ringbuffer implementation.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 11 Jun 2011 05:36:09 +0300
parents 6918c46015d0
children a6304a3719ee
files th_util.c th_util.h
diffstat 2 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/th_util.c	Sat Jun 11 05:10:41 2011 +0300
+++ b/th_util.c	Sat Jun 11 05:36:09 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;
 }
 
 
--- a/th_util.h	Sat Jun 11 05:10:41 2011 +0300
+++ b/th_util.h	Sat Jun 11 05:36:09 2011 +0300
@@ -114,7 +114,7 @@
 /* Ringbuffer implementation
  */
 typedef struct {
-    void **data;
+    char **data;
     int n, size;
     void (*deallocator)(void *);
 } qringbuf_t;