From 18ebdf763dbed55665bd08d7eabad958bfb345f6 Mon Sep 17 00:00:00 2001 From: havoc Date: Mon, 13 Jun 2011 17:31:58 +0000 Subject: [PATCH] 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 --- common.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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; } -- 2.39.2