且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

找到代码生成器漏洞。

更新时间:2022-10-23 21:24:49

你应该报告这个问题@ Microsoft连接一个重现问题的小项目!


https: //connect.microsoft.com/


In some cases, the compiler generates wrong code.

look at this code:

unsigned char ary[2];
ary[0] = 0x77;
ary[1] = 0xCB;
unsigned char val;
val = ary[0] >> 4;
// expected: val = 0x07. Got: 0x07.
val = ary[1] >> 4;
// expected: val = 0x0C. Got: 0xFC!

This happens, because the compiler emits a SAR instruction when shifting, even when using unsigned values. For unsigned values, the compiler should use SHR. Due to this, the sign bit is extended even for unsigned values. Ok, there is a easy workaround for this problem (val = (ary[0] >> 4) & 0x0F;), but it's ugly and, in some cases, troublesome.

Verified with Microsoft Visual Studio 2010, Version 10.0.40219.1 SP1Rel

You should report this issue @ Microsoft connect with a small project that reproduces the issue!

https://connect.microsoft.com/