From: havoc Date: Wed, 9 May 2007 09:53:11 +0000 (+0000) Subject: fixed several critical bugs in VM_tokenizebyseparator X-Git-Tag: xonotic-v0.1.0preview~3192 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=3a80f95acd87d20138978b7801d36604a3c12aef fixed several critical bugs in VM_tokenizebyseparator git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7255 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/prvm_cmds.c b/prvm_cmds.c index f4d62ce5..1d1a73bf 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -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; }