]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
string.c: fix split_args()
authorAndre <maan@p133.(none)>
Mon, 12 Jun 2006 07:34:08 +0000 (09:34 +0200)
committerAndre <maan@p133.(none)>
Mon, 12 Jun 2006 07:34:08 +0000 (09:34 +0200)
If the submitted command started with a newline, the number of
arguments was calculated as zero.

string.c

index 78b862c933ced61396aadb6df04f43d8185eee21..2bdc7e89687cfe31235efb63b9a2af77469d460b 100644 (file)
--- a/string.c
+++ b/string.c
@@ -389,14 +389,19 @@ __must_check unsigned split_args(char *args, char ***argv_ptr, const char *delim
        char **argv;
        size_t n = 0, i, j;
 
        char **argv;
        size_t n = 0, i, j;
 
-       while ((i = strcspn(p, delim)) && (p += i)) {
-               p += strspn(p, delim);
+       p = args + strspn(args, delim);
+       for (;;) {
+               i = strcspn(p, delim);
+               if (!i)
+                       break;
+               p += i;
                n++;
                n++;
+               p += strspn(p, delim);
        }
        *argv_ptr = para_malloc((n + 1) * sizeof(char *));
        argv = *argv_ptr;
        i = 0;
        }
        *argv_ptr = para_malloc((n + 1) * sizeof(char *));
        argv = *argv_ptr;
        i = 0;
-       p = args;
+       p = args + strspn(args, delim);
        while (p) {
                argv[i] = p;
                j = strcspn(p, delim);
        while (p) {
                argv[i] = p;
                j = strcspn(p, delim);