From 95303ee11df12f284e98d02dba993eda9e425383 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 21 Apr 2016 12:36:04 +0200 Subject: [PATCH] common: Add 'append_to_strlist_try' which can fail. * common/strlist.c (append_to_strlist): Use the new function. (append_to_strlist_try): New function. * common/strlist.h (append_to_strlist_try): New prototype. Signed-off-by: Justus Winter --- common/strlist.c | 15 +++++++++++++++ common/strlist.h | 1 + 2 files changed, 16 insertions(+) diff --git a/common/strlist.c b/common/strlist.c index 760a46040..2ba0209f9 100644 --- a/common/strlist.c +++ b/common/strlist.c @@ -111,10 +111,25 @@ add_to_strlist2( strlist_t *list, const char *string, int is_utf8 ) process on memory shortage. */ strlist_t append_to_strlist( strlist_t *list, const char *string ) +{ + strlist_t sl; + sl = append_to_strlist_try (list, string); + if (sl == NULL) + abort (); + return sl; +} + + +/* Add STRING to the LIST at the end. */ +strlist_t +append_to_strlist_try (strlist_t *list, const char *string) { strlist_t r, sl; sl = xmalloc( sizeof *sl + strlen(string)); + if (sl == NULL) + return NULL; + sl->flags = 0; strcpy(sl->d, string); sl->next = NULL; diff --git a/common/strlist.h b/common/strlist.h index acb92f700..94dd32f05 100644 --- a/common/strlist.h +++ b/common/strlist.h @@ -46,6 +46,7 @@ strlist_t add_to_strlist_try (strlist_t *list, const char *string); strlist_t add_to_strlist2( strlist_t *list, const char *string, int is_utf8); strlist_t append_to_strlist (strlist_t *list, const char *string); +strlist_t append_to_strlist_try (strlist_t *list, const char *string); strlist_t append_to_strlist2 (strlist_t *list, const char *string, int is_utf8);