Author: alanmc
Date: 2007-06-21 23:18:36 -0400 (Thu, 21 Jun 2007)
New Revision: 80520
Modified:
trunk/bitsharp/src/MonoTorrent/Common/BitField.cs
Log:
Bugfix: No overrunning the array when pieces are an exact multiple of 32
Modified: trunk/bitsharp/src/MonoTorrent/Common/BitField.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Common/BitField.cs 2007-06-22 03:17:02 UTC
(rev 80519)
+++ trunk/bitsharp/src/MonoTorrent/Common/BitField.cs 2007-06-22 03:18:36 UTC
(rev 80520)
@@ -368,7 +368,9 @@
int start;
int end;
- for (int i = (startIndex / 32); i <= (endIndex / 32); i++)
+ // If the number of pieces is an exact multiple of 32, we need to
decrement by 1 so we don't overrun the array
+ int loopEnd = (endIndex / 32) - ((endIndex % 32 == 0) ? 1 : 0);
+ for (int i = (startIndex / 32); i <= loopEnd; i++)
{
if (this.array[i] == 0) // This one has no true values
continue;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches