From: divverent Date: Sat, 4 Sep 2010 15:32:09 +0000 (+0000) Subject: Since u8_prevbyte skips invalid chars on purpose, it can go before the ] if invalid... X-Git-Tag: xonotic-v0.1.0preview~230^2~45 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=de39b9746aa912589462b418e2a9af3d69b063c2;p=xonotic%2Fdarkplaces.git Since u8_prevbyte skips invalid chars on purpose, it can go before the ] if invalid utf8 chars get pasted in the console edit line. It's even possible to delete the ]. Fix this bug by giving to u8_prevbyte the edit line without ]. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10439 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/keys.c b/keys.c index 18765a16..478e8a16 100644 --- a/keys.c +++ b/keys.c @@ -713,7 +713,7 @@ Key_Console (int key, int unicode) { int pos; size_t inchar = 0; - pos = u8_prevbyte(key_line, key_linepos); + pos = u8_prevbyte(key_line+1, key_linepos-1) + 1; // do NOT give the ']' to u8_prevbyte while (pos) if(pos-1 > 0 && key_line[pos-1] == STRING_COLOR_TAG && isdigit(key_line[pos])) pos-=2; @@ -733,7 +733,7 @@ Key_Console (int key, int unicode) } else { - key_linepos = u8_prevbyte(key_line, key_linepos); + key_linepos = u8_prevbyte(key_line+1, key_linepos-1) + 1; // do NOT give the ']' to u8_prevbyte } return; } @@ -743,7 +743,7 @@ Key_Console (int key, int unicode) { if (key_linepos > 1) { - int newpos = u8_prevbyte(key_line, key_linepos); + int newpos = u8_prevbyte(key_line+1, key_linepos-1) + 1; // do NOT give the ']' to u8_prevbyte strlcpy(key_line + newpos, key_line + key_linepos, sizeof(key_line) + 1 - key_linepos); key_linepos = newpos; }