It seems like Reflector of version 5.1.6.0 has problems disassembling some pointer operations, notably increments.
public class Test
{
public static unsafe void Main(string[] args)
{
int[] _data = { 1, 2, 3, 4, 5 };
fixed(int *p = _data)
System.Console.Out.WriteLine("{0}", Sum(p, _data.Length));
}
private static unsafe int Sum(int *p, int length)
{
int sum = 0;
for(int i = 0; i < length; i++)
sum += *p++;
return sum;
}
}
The for-loop in Sum gets disassemblied as:
for (int i = 0; i < length; i++)
{
p++;
sum = p[0];
}
Which will skip the first element and access the memory beyond the last element in the array.
/Andreas
The for-loop in Sum gets disassemblied as:
Which will skip the first element and access the memory beyond the last element in the array.
/Andreas