X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Fbrkstring.c;h=a9446fef299512d5409b596b09a7ae1540bb3c19;hp=da42d619e7157e010e91d259fcb02b728233f034;hb=f78e7c6e6e616cc4ff2bee8a726365fafef2d8ce;hpb=909cdf33782fb9803b8e18f7f378bfcec21e4b15 diff --git a/sbr/brkstring.c b/sbr/brkstring.c index da42d61..a9446fe 100644 --- a/sbr/brkstring.c +++ b/sbr/brkstring.c @@ -7,6 +7,7 @@ ** complete copyright information. */ +#include #include #include @@ -29,7 +30,7 @@ brkstring(char *str, char *brksep, char *brkterm) /* allocate initial space for pointers on first call */ if (!broken) { len = NUMBROKEN; - broken = (char **)mh_xmalloc((size_t)(len * sizeof(*broken))); + broken = mh_xcalloc(len, sizeof(*broken)); } /* @@ -41,12 +42,11 @@ brkstring(char *str, char *brksep, char *brkterm) /* enlarge pointer array, if necessary */ if (i >= len) { len += NUMBROKEN; - broken = mh_xrealloc(broken, - (size_t)(len * sizeof(*broken))); + broken = mh_xrealloc(broken, len * sizeof(*broken)); } /* handle separators */ - while ((c=*s) && strchr(brksep, c)) { + while ((c=*s) && brksep && strchr(brksep, c)) { *s++ = '\0'; } @@ -54,7 +54,7 @@ brkstring(char *str, char *brksep, char *brkterm) ** we are either at the end of the string, or the ** terminator found has been found, so finish up. */ - if (!c || strchr(brkterm, c)) { + if (!c || (brkterm && strchr(brkterm, c))) { *s = '\0'; broken[i] = NULL; return broken; @@ -62,9 +62,14 @@ brkstring(char *str, char *brksep, char *brkterm) /* set next start addr and walk over word */ broken[i] = s; - while ((c=*++s) && !strchr(brksep, c) && !strchr(brkterm, c)) { - continue; + while ((c = *++s)) { + if (brksep && strchr(brksep, c)) { + break; + } + if (brkterm && strchr(brkterm, c)) { + break; + } } } - adios("brkstring()", "reached unreachable point"); + adios(EX_SOFTWARE, "brkstring()", "reached unreachable point"); }