sfeed_curses

[fork] sfeed (atom feed) reader
Log | Files | Refs | README | LICENSE

commit 575011773b97937f498b09ec5c9ad29b9e07ea1d
parent e607a1214c4407c645a12945de2a051fdbf2dae9
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Wed, 24 Jun 2020 20:02:06 +0200

add erealloc wrapper

Diffstat:
Msfeed_curses.c | 14++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/sfeed_curses.c b/sfeed_curses.c @@ -169,6 +169,16 @@ errx(int code, const char *fmt, ...) } void * +erealloc(void *ptr, size_t size) +{ + void *p; + + if (!(p = realloc(ptr, size))) + err(1, "realloc"); + return p; +} + +void * ecalloc(size_t nmemb, size_t size) { void *p; @@ -859,11 +869,11 @@ feed_getitems(struct item **items, size_t *nitems, ssize_t want, cap = 0; } else { /* `want` is also a hint of amount to allocate. */ cap = (size_t)want; - *items = realloc(*items, cap * sizeof(struct item)); + *items = erealloc(*items, cap * sizeof(struct item)); } for (i = 0; want == -1 || i < want; i++) { if (i + 1 >= cap) - *items = realloc(*items, ++cap * sizeof(struct item)); + *items = erealloc(*items, ++cap * sizeof(struct item)); if ((linelen = getline(&line, &linesize, fp)) > 0) { item = (*items) + i; offset += linelen;