r701 - trunk/game

black at icculus.org black at icculus.org
Tue Apr 18 07:01:00 EDT 2006


Author: black
Date: 2006-04-18 07:01:00 -0400 (Tue, 18 Apr 2006)
New Revision: 701

Modified:
   trunk/game/g_util.c
Log:
Some small changes, either to make the code simpler/easier to understand or to keep it from breaking under special circumstances.


Modified: trunk/game/g_util.c
===================================================================
--- trunk/game/g_util.c	2006-04-18 10:27:00 UTC (rev 700)
+++ trunk/game/g_util.c	2006-04-18 11:01:00 UTC (rev 701)
@@ -1,7 +1,6 @@
 
 #include "ncommon.h"
 #include "game/g_util.h"
-#include "game/g_main.h"
 #include "lhnet.h"
 
 void G_GenerateChallenge(char *s, NUint32 challengebufferlength)
@@ -10,7 +9,7 @@
 	if (challengebufferlength < 1)
 		return;
 	for (i = 0;i < challengebufferlength - 1;i++)
-		*s++ = 'A' + (rand() % 26);
+		*s++ = 'A' + (rand() % ('Z' - 'A' + 1));
 	*s = 0;
 }
 
@@ -19,6 +18,9 @@
 	Nbool isvalue;
 	Nbool found = false;
 	int bufferpos;
+	// make sure the optimized code doesnt break when the key name is longer than the temp buffer
+	assert( strlen( key ) < bufferlength );
+
 	// skip leading text (such as in a packet)
 	while (*infostring && *infostring != '\\')
 		infostring++;
@@ -79,17 +81,19 @@
 			return;
 		}
 		inkey = in + 1;
-		for (i = 0;inkey[i] && inkey[i] != '\\';i++);
+		for (i = 0;inkey[i] && inkey[i] != '\\';i++) 
+			;
 		// if we reached the end of the input key, but not the end of the
 		// key we're looking for, then it's not a match
-		match = !key[i] && !String_NICompare(inkey, key, i);
+		match = strlen(key) == i && !String_NICompare(inkey, key, i);
 		if (inkey[i] != '\\')
 		{
 			Console_Printf("G_InfoString_Set: infostring improperly terminated\n");
 			return;
 		}
 		invalue = inkey + i + 1;
-		for (i = 0;invalue[i] && invalue[i] != '\\';i++);
+		for (i = 0;invalue[i] && invalue[i] != '\\';i++)
+			;
 		in = invalue + i;
 		if (match)
 		{
@@ -117,9 +121,11 @@
 	{
 		while (*string && *string <= ' ')
 			string++;
-		if (!*string)
+		if (!*string || numargs == maxargs)
 			break;
-		arg = numargs < maxargs ? (args + numargs++ * maxargsize) : NULL;
+
+		arg = args + numargs++ * maxargsize;
+
 		if ((quoted = *string == '"'))
 			string++;
 		for (i = 0;*string && (quoted ? *string != '"' : *string > ' ');i++)
@@ -131,14 +137,14 @@
 				if (c == 0)
 					break;
 				if (c == 'n')
-					c = '\n';
+					c = '\n';				
 			}
-			if (arg && i < maxargsize - 1)
+			if (i < maxargsize - 1)
 			{
 				arg[i] = c;
-				arg[i+1] = 0;
 			}
 		}
+		arg[i] = 0;
 		if (quoted && *string == '"')
 			string++;
 	}




More information about the neither-commits mailing list