diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-05-04 03:43:10 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-05-04 03:43:10 +0000 |
commit | 1d2cc0bca445bdfd8a45920b6f52553215ca5414 (patch) | |
tree | 56af51f8a78199fe20d1dfb4a5cfe4f66c80df50 /app.c | |
parent | 741dead410df7e0efc12ceecd447f5da832d5d72 (diff) |
re-implement ast_separate_app_args with clearer code and in a way that doesn't fail with certain combinations of array size and delimiter count
add doxygen docs for ast_separate_app_args
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5566 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'app.c')
-rwxr-xr-x | app.c | 29 |
1 files changed, 21 insertions, 8 deletions
@@ -1069,16 +1069,29 @@ int ast_app_group_match_get_count(char *groupmatch, char *category) int ast_separate_app_args(char *buf, char delim, char **array, int arraylen) { - int x = 0; - memset(array, 0, arraylen * sizeof(char *)); - if (!buf) + int x; + char *scan; + char delims[2]; + + if (!buf || !array || !arraylen) return 0; - for (array[x] = buf ; x < arraylen && array[x]; x++) { - if ((array[x+1] = strchr(array[x], delim))) { - *array[x+1] = '\0'; - array[x+1]++; - } + + memset(array, 0, arraylen * sizeof(*array)); + + scan = buf; + delims[0] = delim; + delims[1] = '\0'; + x = 0; + + while (x < arraylen - 1) { + array[x] = strsep(&scan, delims); + x++; + if (!scan) + break; } + + array[x++] = scan; + return x; } |