Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange difference between .net 3.5 and .net 4.0

Tags:

c#

.net

I've got a code

byte[] bytes = new byte[] { 0x80, 1, 192, 33, 0 };

if (bytes[0] != 0x80 || ((bytes[1] & ~1) != 0) || bytes[4] != 0)
{
//signature wrong (.net 4.0 result)
}
else
{
//signture okay (.net 3.5 result)
}

In .net 3.5 expression evaluates as false, but in 4.0 it evaluates as true. My question is why? and how can i check all of my old (.net 3.5) code to prevent this behaviour?

like image 710
qmor Avatar asked Oct 21 '15 15:10

qmor


1 Answers

So it's not lost in the comments, I believe you have hit a bug in RyuJIT, the new JIT compiler for 64 bit applications in .NET 4.6.

This is not the first one, for example see this blog post showing how the Stack Overflow team tracked down another issue.

As discussed in the comments, it is not triggered if you target .NET 3.5, nor if you target x86 in .NET 4.

This bug may or may not have been reported to Microsoft yet - if anyone is aware of a bug report for this, or has .NET 4.6 installed to track down the underlying cause more, feel free to edit.

like image 93
James Thorpe Avatar answered Oct 29 '22 17:10

James Thorpe