X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilcstrutil.c;h=914adc98f58659a7cc739afed2a19dbec508827e;hp=1655f213459470ab4a4765d0d55a12b9ba7c9440;hb=96ae4adfa8757be98b0587941e26d0733e1fb22e;hpb=f449c0a95327fd4e60a5b9d3c9d50fae0f8d835a diff --git a/lib/silcutil/silcstrutil.c b/lib/silcutil/silcstrutil.c index 1655f213..914adc98 100644 --- a/lib/silcutil/silcstrutil.c +++ b/lib/silcutil/silcstrutil.c @@ -121,7 +121,7 @@ int silc_string_compare(char *string1, char *string2) char **silc_string_split(const char *string, char ch, int *ret_count) { - char **splitted = NULL, sep[1], *item, *cp; + char **splitted = NULL, sep[2], *item, *cp; int i = 0, len; if (!string || !ret_count) { @@ -140,9 +140,13 @@ char **silc_string_split(const char *string, char ch, int *ret_count) } sep[0] = ch; + sep[1] = '\0'; cp = (char *)string; - while(cp) { + while (cp) { len = strcspn(cp, sep); + if (!len) + break; + item = silc_memdup(cp, len); if (!item) { silc_free(splitted); @@ -155,10 +159,13 @@ char **silc_string_split(const char *string, char ch, int *ret_count) else cp++; - splitted = silc_realloc(splitted, (i + 1) * sizeof(*splitted)); - if (!splitted) - return NULL; splitted[i++] = item; + + if (cp) { + splitted = silc_realloc(splitted, (i + 1) * sizeof(*splitted)); + if (!splitted) + return NULL; + } } *ret_count = i; @@ -246,18 +253,15 @@ char *silc_string_regex_combine(const char *string1, const char *string2) int silc_string_regex_match(const char *regex, const char *string) { - regex_t preg; - int ret = FALSE; + SilcRegexStruct preg; + SilcBool ret; - if (regcomp(&preg, regex, REG_NOSUB | REG_EXTENDED) != 0) { - silc_set_errno(SILC_ERR_INVALID_ARGUMENT); + if (!silc_regex_compile(&preg, regex, 0)) return FALSE; - } - if (regexec(&preg, string, 0, NULL, 0) == 0) - ret = TRUE; + ret = silc_regex_match(&preg, string, 0, NULL, 0); - regfree(&preg); + silc_regex_free(&preg); return ret; }