G
Guest
Probably there is bug in VC 64-bit compiler (in all versions)
Compile and run the following code with speed optimization (-O2):
#include <stdio.h>
typedef int (*fp)(const unsigned char *buf, unsigned int pos, unsigned int
num);
int f(const unsigned char *buf, unsigned int pos, unsigned int num)
{
int sum = 0;
for (; num != 0; num--)
sum += buf[(size_t)pos++];
return sum;
}
fp t = f;
int main()
{
unsigned char buffer[1] = { 0 };
unsigned int pos = 0x80000000;
return t(buffer - pos, pos, 1);
}
Bug description:
pos is unsigned int, but VC compiler uses
movsxd r9, edx
command to extend from unsigned int to size_t
Compile and run the following code with speed optimization (-O2):
#include <stdio.h>
typedef int (*fp)(const unsigned char *buf, unsigned int pos, unsigned int
num);
int f(const unsigned char *buf, unsigned int pos, unsigned int num)
{
int sum = 0;
for (; num != 0; num--)
sum += buf[(size_t)pos++];
return sum;
}
fp t = f;
int main()
{
unsigned char buffer[1] = { 0 };
unsigned int pos = 0x80000000;
return t(buffer - pos, pos, 1);
}
Bug description:
pos is unsigned int, but VC compiler uses
movsxd r9, edx
command to extend from unsigned int to size_t