fixed several critical bugs in VM_tokenizebyseparator
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 9 May 2007 09:53:11 +0000 (09:53 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 9 May 2007 09:53:11 +0000 (09:53 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7255 d7cf8633-e32d-0410-b094-e92efae38249

prvm_cmds.c

index f4d62ce..1d1a73b 100644 (file)
@@ -2011,6 +2011,7 @@ void VM_tokenizebyseparator (void)
        int separatorlen[7];
        const char *separators[7];
        const char *p;
+       const char *token;
        char tokentext[MAX_INPUTLINE];
 
        VM_SAFEPARMCOUNTRANGE(2, 8,VM_tokenizebyseparator);
@@ -2030,8 +2031,11 @@ void VM_tokenizebyseparator (void)
        }
 
        num_tokens = 0;
-       for (num_tokens = 0;num_tokens < (int)(sizeof(tokens)/sizeof(tokens[0]));num_tokens++)
+       j = 0;
+
+       while (num_tokens < (int)(sizeof(tokens)/sizeof(tokens[0])))
        {
+               token = tokentext + j;
                while (*p)
                {
                        for (k = 0;k < numseparators;k++)
@@ -2044,12 +2048,14 @@ void VM_tokenizebyseparator (void)
                        }
                        if (k < numseparators)
                                break;
-                       if (j < (int)sizeof(tokentext[MAX_INPUTLINE]-1))
+                       if (j < (int)sizeof(tokentext)-1)
                                tokentext[j++] = *p;
                        p++;
                }
-               tokentext[j] = 0;
-               tokens[num_tokens] = PRVM_SetTempString(tokentext);
+               if (j >= (int)sizeof(tokentext))
+                       break;
+               tokentext[j++] = 0;
+               tokens[num_tokens++] = PRVM_SetTempString(token);
                if (!*p)
                        break;
        }