[Scummvm-cvs-logs] CVS: scummvm/scumm imuse.cpp,2.135,2.136

Max Horn fingolfin at users.sourceforge.net
Thu May 26 04:31:23 CEST 2005


Update of /cvsroot/scummvm/scummvm/scumm
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25049

Modified Files:
	imuse.cpp 
Log Message:
Properly use operator '%' to compute a queue wrap around, instead of relying on the queue size to be a power of 2 and then abusing the '&' operator

Index: imuse.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse.cpp,v
retrieving revision 2.135
retrieving revision 2.136
diff -u -d -r2.135 -r2.136
--- imuse.cpp	26 May 2005 11:13:41 -0000	2.135
+++ imuse.cpp	26 May 2005 11:30:56 -0000	2.136
@@ -376,7 +376,7 @@
 		p = _cmd_queue[pos].array;
 		if (p[0] == TRIGGER_ID && p[1] == id && p[2] == data)
 			break;
-		pos = (pos + 1) & (ARRAYSIZE(_cmd_queue) - 1);
+		pos = (pos + 1) % ARRAYSIZE(_cmd_queue);
 	}
 
 	if (pos == _queue_pos)
@@ -388,7 +388,7 @@
 	_trigger_count--;
 	_queue_cleared = false;
 	do {
-		pos = (pos + 1) & (ARRAYSIZE(_cmd_queue) - 1);
+		pos = (pos + 1) % ARRAYSIZE(_cmd_queue);
 		if (_queue_pos == pos)
 			break;
 		p = _cmd_queue[pos].array;
@@ -460,7 +460,7 @@
 		a = _cmd_queue[i].array;
 		if (a[0] == COMMAND_ID && a[1] == 8 && a[2] == (uint16)sound)
 			return 2;
-		i = (i + 1) & (ARRAYSIZE(_cmd_queue) - 1);
+		i = (i + 1) % ARRAYSIZE(_cmd_queue);
 	}
 
 	for (i = 0; i < ARRAYSIZE (_deferredCommands); ++i) {
@@ -550,13 +550,13 @@
 	p[6] = f;
 	p[7] = g;
 
-	i = (i + 1) & (ARRAYSIZE(_cmd_queue) - 1);
+	i = (i + 1) % ARRAYSIZE(_cmd_queue);
 
 	if (_queue_end != i) {
 		_queue_pos = i;
 		return 0;
 	} else {
-		_queue_pos = (i - 1) & (ARRAYSIZE(_cmd_queue) - 1);
+		_queue_pos = (i - 1) % ARRAYSIZE(_cmd_queue);
 		return -1;
 	}
 }
@@ -644,9 +644,9 @@
 	p[1] = sound;
 	p[2] = marker;
 
-	pos = (pos + 1) & (ARRAYSIZE(_cmd_queue) - 1);
+	pos = (pos + 1) % ARRAYSIZE(_cmd_queue);
 	if (_queue_end == pos) {
-		_queue_pos = (pos - 1) & (ARRAYSIZE(_cmd_queue) - 1);
+		_queue_pos = (pos - 1) % ARRAYSIZE(_cmd_queue);
 		return -1;
 	}
 





More information about the Scummvm-git-logs mailing list