common: Add 'append_to_strlist_try' which can fail.
authorJustus Winter <justus@g10code.com>
Thu, 21 Apr 2016 10:36:04 +0000 (12:36 +0200)
committerJustus Winter <justus@g10code.com>
Thu, 21 Apr 2016 12:38:53 +0000 (14:38 +0200)
* 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 <justus@g10code.com>
common/strlist.c
common/strlist.h

index 760a460..2ba0209 100644 (file)
@@ -112,9 +112,24 @@ 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 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;
index acb92f7..94dd32f 100644 (file)
@@ -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);