]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
If the last character in a string to be parsed is the delimiter, then we should
authorTilghman Lesher <tilghman@meg.abyt.es>
Fri, 20 Jun 2008 22:02:55 +0000 (22:02 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Fri, 20 Jun 2008 22:02:55 +0000 (22:02 +0000)
count that final empty string as an additional argument.

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@124395 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/app.c

index 5e7b982724895afe9916ae5c65e6ebf09ed7a680..c9fdb4f0c7eb954809fcb5dc0171123ae3f431d9 100644 (file)
@@ -955,7 +955,7 @@ int ast_app_group_list_unlock(void)
 unsigned int ast_app_separate_args(char *buf, char delim, char **array, int arraylen)
 {
        int argc;
-       char *scan;
+       char *scan, *wasdelim = NULL;
        int paren = 0, quote = 0;
 
        if (!buf || !array || !arraylen)
@@ -982,14 +982,18 @@ unsigned int ast_app_separate_args(char *buf, char delim, char **array, int arra
                                /* Literal character, don't parse */
                                memmove(scan, scan + 1, strlen(scan));
                        } else if ((*scan == delim) && !paren && !quote) {
+                               wasdelim = scan;
                                *scan++ = '\0';
                                break;
                        }
                }
        }
 
-       if (*scan)
+       /* If the last character in the original string was the delimiter, then
+        * there is one additional argument. */
+       if (*scan || (scan > buf && (scan - 1) == wasdelim)) {
                array[argc++] = scan;
+       }
 
        return argc;
 }