diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-01-11 23:44:04 +0100 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-01-11 23:44:04 +0100 |
| commit | 964d816726b8c765277b043894d534e9b1e0d60c (patch) | |
| tree | 0a7769532ebd41007a914889a0e96d171ad1ca55 /src/history.c | |
| parent | a9d37006eae7227d498c7c658360ee1e43b3e054 (diff) | |
| download | tmus-964d816726b8c765277b043894d534e9b1e0d60c.tar.gz tmus-964d816726b8c765277b043894d534e9b1e0d60c.zip | |
Check aprintf allocation internally and add astrdup for less OOM_CHECK
Diffstat (limited to 'src/history.c')
| -rw-r--r-- | src/history.c | 16 |
1 files changed, 8 insertions, 8 deletions
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 <err.h> #include <string.h> -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; } |
