From: havoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Date: Mon, 13 Jun 2011 17:31:58 +0000 (+0000)
Subject: refactored MSG_ReadString to be nicer code (and fix a potentially uninitialized varia... 
X-Git-Tag: xonotic-v0.6.0~163^2~350
X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=18ebdf763dbed55665bd08d7eabad958bfb345f6;p=xonotic%2Fdarkplaces.git

refactored MSG_ReadString to be nicer code (and fix a potentially uninitialized variable warning)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11196 d7cf8633-e32d-0410-b094-e92efae38249
---

diff --git a/common.c b/common.c
index 5539b0af..78cbd40a 100644
--- a/common.c
+++ b/common.c
@@ -493,12 +493,12 @@ float MSG_ReadBigFloat (void)
 char *MSG_ReadString (void)
 {
 	static char string[MAX_INPUTLINE];
-	int l,c;
-	for (l = 0;l < (int) sizeof(string) - 1 && (c = MSG_ReadByte()) != -1 && c != 0;l++)
-		string[l] = c;
-	// read the rest of the string anyway
-	while(c != -1 && c != 0)
-		c = MSG_ReadByte();
+	const int maxstring = sizeof(string);
+	int l = 0,c;
+	// read string into buffer, but only store as many characters as will fit
+	while ((c = MSG_ReadByte()) > 0)
+		if (l < maxstring - 1)
+			string[l++] = c;
 	string[l] = 0;
 	return string;
 }