diff th_datastruct.c @ 632:553db886533e

Return a THERR_* error value from th_ringbuf_grow() instead of BOOL. This breaks the API, but checking against BOOL will result in failure in case of actual success (THERR_OK == 0) which should be "easy" to detect.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 17 Jan 2020 20:08:55 +0200
parents d5221299656a
children b383f4e6ab89
line wrap: on
line diff
--- a/th_datastruct.c	Fri Jan 17 20:07:25 2020 +0200
+++ b/th_datastruct.c	Fri Jan 17 20:08:55 2020 +0200
@@ -360,17 +360,19 @@
 }
 
 
-BOOL th_ringbuf_grow(th_ringbuf_t *buf, const size_t n)
+int th_ringbuf_grow(th_ringbuf_t *buf, const size_t nadd)
 {
-    buf->data = (void **) th_realloc(buf->data, (buf->size + n) * sizeof(void *));
-    if (buf->data != NULL)
-    {
-        memset(buf->data + buf->size, 0, sizeof(void *) * n);
-        buf->size += n;
-        return TRUE;
-    }
-    else
-        return FALSE;
+    if (buf == NULL)
+        return THERR_NULLPTR;
+
+    buf->data = (void **) th_realloc(buf->data, (buf->size + nadd) * sizeof(void *));
+    if (buf->data == NULL)
+        return THERR_MALLOC;
+
+    memset(buf->data + buf->size, 0, sizeof(void *) * nadd);
+    buf->size += nadd;
+
+    return THERR_OK;
 }