Mercurial > hg > th-libs
comparison 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 |
comparison
equal
deleted
inserted
replaced
631:d5221299656a | 632:553db886533e |
---|---|
358 buf->allocated = TRUE; | 358 buf->allocated = TRUE; |
359 return buf; | 359 return buf; |
360 } | 360 } |
361 | 361 |
362 | 362 |
363 BOOL th_ringbuf_grow(th_ringbuf_t *buf, const size_t n) | 363 int th_ringbuf_grow(th_ringbuf_t *buf, const size_t nadd) |
364 { | 364 { |
365 buf->data = (void **) th_realloc(buf->data, (buf->size + n) * sizeof(void *)); | 365 if (buf == NULL) |
366 if (buf->data != NULL) | 366 return THERR_NULLPTR; |
367 { | 367 |
368 memset(buf->data + buf->size, 0, sizeof(void *) * n); | 368 buf->data = (void **) th_realloc(buf->data, (buf->size + nadd) * sizeof(void *)); |
369 buf->size += n; | 369 if (buf->data == NULL) |
370 return TRUE; | 370 return THERR_MALLOC; |
371 } | 371 |
372 else | 372 memset(buf->data + buf->size, 0, sizeof(void *) * nadd); |
373 return FALSE; | 373 buf->size += nadd; |
374 | |
375 return THERR_OK; | |
374 } | 376 } |
375 | 377 |
376 | 378 |
377 void th_ringbuf_free(th_ringbuf_t *buf) | 379 void th_ringbuf_free(th_ringbuf_t *buf) |
378 { | 380 { |