]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - common.c
refactored MSG_ReadString to be nicer code (and fix a potentially uninitialized varia...
[xonotic/darkplaces.git] / 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;
 }