]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
refactored MSG_ReadString to be nicer code (and fix a potentially uninitialized varia...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 13 Jun 2011 17:31:58 +0000 (17:31 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 13 Jun 2011 17:31:58 +0000 (17:31 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11196 d7cf8633-e32d-0410-b094-e92efae38249

common.c

index 5539b0aff0adfd752d3302eededaacada4bb1fa7..78cbd40a87bc4949f10a8a959c150f8f6f5c413b 100644 (file)
--- 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;
 }