X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/1691e80890e5d8ba258c51c214a3e91880e1db2b..236a2b64249d7ffe0c4eaea2ef89b86f759ceda6:/sbr/brkstring.c?ds=inline diff --git a/sbr/brkstring.c b/sbr/brkstring.c index 715aaf5e..bdc8c30a 100644 --- a/sbr/brkstring.c +++ b/sbr/brkstring.c @@ -3,10 +3,13 @@ * brkstring.c -- (destructively) split a string into * -- an array of substrings * - * $Id$ + * This code is Copyright (c) 2002, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. */ #include +#include /* allocate this number of pointers at a time */ #define NUMBROKEN 256 @@ -29,8 +32,7 @@ brkstring (char *str, char *brksep, char *brkterm) /* allocate initial space for pointers on first call */ if (!broken) { len = NUMBROKEN; - if (!(broken = (char **) malloc ((size_t) (len * sizeof(*broken))))) - adios (NULL, "unable to malloc array in brkstring"); + broken = (char **) mh_xmalloc ((size_t) (len * sizeof(*broken))); } /* @@ -44,8 +46,7 @@ brkstring (char *str, char *brksep, char *brkterm) /* enlarge pointer array, if necessary */ if (i >= len) { len += NUMBROKEN; - if (!(broken = realloc (broken, (size_t) (len * sizeof(*broken))))) - adios (NULL, "unable to realloc array in brkstring"); + broken = mh_xrealloc (broken, (size_t) (len * sizeof(*broken))); } while (brkany (c = *s, brksep)) @@ -58,7 +59,7 @@ brkstring (char *str, char *brksep, char *brkterm) if (!c || brkany (c, brkterm)) { *s = '\0'; broken[i] = NULL; - return broken; + break; } /* set next start addr */ @@ -68,7 +69,7 @@ brkstring (char *str, char *brksep, char *brkterm) ; /* empty body */ } - return broken; /* NOT REACHED */ + return broken; }