[mw-devel] MW3 r1322 - trunk/src

welshbyte at sucs.org welshbyte at sucs.org
Sun Jan 13 19:24:17 GMT 2013


Author: welshbyte
Date: 2013-01-13 19:24:17 +0000 (Sun, 13 Jan 2013)
New Revision: 1322

Modified:
   trunk/src/perms.c
Log:
Separate the bit index from the string index in show_user_stats() so that when 'flag' is false there are no uninitialised garbage gaps left in the string.

Fixes #61


Modified: trunk/src/perms.c
===================================================================
--- trunk/src/perms.c	2013-01-13 16:15:45 UTC (rev 1321)
+++ trunk/src/perms.c	2013-01-13 19:24:17 UTC (rev 1322)
@@ -184,13 +184,16 @@
 
 static void show_stats(unsigned char st, char *tmp, size_t tmpsize, const char *map, int flag)
 {
-	int i;
-	for (i = 0; i < tmpsize; i++)
-		if (st & (1<<i))
-			tmp[i] = map[i];
+	int bit = 0;
+	int pos = 0;
+	while(bit < tmpsize) {
+		if (st & (1<<bit))
+			tmp[pos++] = map[bit];
 		else if (flag)
-			tmp[i] = '-';
-	tmp[i] = '\0';
+			tmp[pos++] = '-';
+		bit++;
+	}
+	tmp[pos] = '\0';
 }
 
 void show_user_stats(unsigned char ustat, char *tmp, int flag)




More information about the mw-devel mailing list