Update of /usr/cvsroot/asterisk In directory mongoose.digium.com:/tmp/cvs-serv11351
Modified Files: app.c Log Message: 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 Index: app.c =================================================================== RCS file: /usr/cvsroot/asterisk/app.c,v retrieving revision 1.58 retrieving revision 1.59 diff -u -d -r1.58 -r1.59 --- app.c 29 Apr 2005 17:00:33 -0000 1.58 +++ app.c 4 May 2005 03:43:10 -0000 1.59 @@ -1069,16 +1069,29 @@ 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; } _______________________________________________ Asterisk-Cvs mailing list Asterisk-Cvs@lists.digium.com http://lists.digium.com/mailman/listinfo/asterisk-cvs