From 964d816726b8c765277b043894d534e9b1e0d60c Mon Sep 17 00:00:00 2001 From: Louis Burda Date: Wed, 11 Jan 2023 23:44:04 +0100 Subject: Check aprintf allocation internally and add astrdup for less OOM_CHECK --- src/history.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/history.c') diff --git a/src/history.c b/src/history.c index 9550dbc..f9426f1 100644 --- a/src/history.c +++ b/src/history.c @@ -3,13 +3,14 @@ #include "history.h" #include "util.h" +#include #include -static struct inputln * -history_list_prev(struct inputln *cur, const char *search); +static struct inputln *history_list_prev( + struct inputln *cur, const char *search); -static struct inputln * -history_list_next(struct inputln *cur, const char *search); +static struct inputln *history_list_next( + struct inputln *cur, const char *search); struct inputln * history_list_prev(struct inputln *cur, const char *search) @@ -139,7 +140,7 @@ inputln_alloc(void) struct inputln *ln; ln = malloc(sizeof(struct inputln)); - OOM_CHECK(ln); + if (!ln) err(1, "malloc"); inputln_init(ln); return ln; @@ -159,7 +160,7 @@ inputln_resize(struct inputln *ln, size_t size) ln->cap = size; ln->buf = realloc(ln->buf, ln->cap * sizeof(char)); - OOM_CHECK(ln->buf); + if (!ln->buf) err(1, "realloc"); ln->len = MIN(ln->len, ln->cap-1); ln->buf[ln->len] = '\0'; } @@ -222,8 +223,7 @@ inputln_copy(struct inputln *dst, struct inputln *src) dst->buf = NULL; } dst->len = src->len; - dst->buf = strdup(src->buf); - OOM_CHECK(dst->buf); + dst->buf = astrdup(src->buf); dst->cap = src->len + 1; dst->cur = dst->len; } -- cgit v1.2.3-71-gd317