# HG changeset patch # User Matti Hamalainen # Date 1579284535 -7200 # Node ID 553db886533ee04292923a34f6da8278ae68f4ea # Parent d5221299656a9903c1f3708938520f3ce60e4b6b 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. diff -r d5221299656a -r 553db886533e th_datastruct.c --- 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; } diff -r d5221299656a -r 553db886533e th_datastruct.h --- a/th_datastruct.h Fri Jan 17 20:07:25 2020 +0200 +++ b/th_datastruct.h Fri Jan 17 20:08:55 2020 +0200 @@ -67,7 +67,7 @@ int th_ringbuf_init(th_ringbuf_t *buf, const size_t size, void (*mdeallocator)(void *data)); th_ringbuf_t * th_ringbuf_new(const size_t size, void (*mdeallocator)(void *data)); -BOOL th_ringbuf_grow(th_ringbuf_t *buf, const size_t n); +int th_ringbuf_grow(th_ringbuf_t *buf, const size_t n); void th_ringbuf_free(th_ringbuf_t *buf); void th_ringbuf_add(th_ringbuf_t *buf, void *ptr);