This is really a build error. x64, .net 4.7.1, build release.
disassembly:
for(int i = 0; i < N - Old.Length; i++) 00007FF942690ADD xor eax,eax for(int i = 0; i < N - Old.Length; i++) 00007FF942690ADF mov ebx,esi 00007FF942690AE1 sub ebx,ebp 00007FF942690AE3 test ebx,ebx 00007FF942690AE5 jle 00007FF942690AFF dd[i] = d; 00007FF942690AE7 mov rdx,qword ptr [rdi] 00007FF942690AEA cmp eax,dword ptr [rdx+8] 00007FF942690AED jae 00007FF942690B11 00007FF942690AEF movsxd rcx,eax 00007FF942690AF2 vmovsd qword ptr [rdx+rcx*8+10h],xmm6 for(int i = 0; i < N - Old.Length; i++) 00007FF942690AF9 inc eax 00007FF942690AFB cmp ebx,eax 00007FF942690AFD jg 00007FF942690AE7 00007FF942690AFF vmovaps xmm6,xmmword ptr [rsp+20h] 00007FF942690B06 add rsp,30h 00007FF942690B0A pop rbx 00007FF942690B0B pop rbp 00007FF942690B0C pop rsi 00007FF942690B0D pop rdi 00007FF942690B0E pop r14 00007FF942690B10 ret
The question is located at 00007FF942690AFD, jg 00007FF942690AE7. It bounces back if ebx (which contains 4, the final value of the loop) is larger (jg) than eax, the value of i. This fails when 4 is of course, so it does not write the last element in the array.
It does not work because it registers the value (eax, 0x00007FF942690AF9) and then checks it for 4, but it should still write that value down. It's a little tricky to determine exactly where the problem is, since it looks like it might be the result of an optimization (N-Old.Length), since the debug build contains this code, but the release build predicts this. So for jit people fix;)
Frans Bouma Dec 06 '17 at 15:32 2017-12-06 15:32
source share