Pelles C forum

Pelles C => Bug reports => Topic started by: bitcoin on July 22, 2019, 10:54:12 PM

Title: Possible bug with integer?
Post by: bitcoin on July 22, 2019, 10:54:12 PM
I have algo to compute CRC32. It similar to ntdll.RtlComputeCrc32 , but in Pelles it return another number. In VS all ok. Why? This is bug or feature?

So, code is

Code: [Select]
unsigned int crc32(unsigned int seed, void *msg, size_t len)
{
unsigned int crc = ~seed;

while (len--) {
crc ^= *((unsigned char *)msg)++;

for (size_t i = 0; i < 8; ++i)
crc = (crc >> 1) ^ (0xEDB88320 & ~(crc & 1) + 1);
}

return ~crc;
}

VS return 1267612143, RtlComputeCrc32 return 1267612143 , but Pelles return 3818104785

Code: [Select]
tmp = crc32(0, "abcdef", 6);
Title: Re: Possible bug with integer?
Post by: TimoVJL on July 23, 2019, 08:27:28 AM
a fixed version ?
Code: [Select]
unsigned int crc32(unsigned int seed, void *msg, size_t len)
{
unsigned int crc = ~seed;
unsigned char *p = msg;

while (len--) {
//crc ^= *((unsigned char *)msg)++;
crc ^= *(p++);

for (size_t i = 0; i < 8; ++i)
crc = (crc >> 1) ^ (0xEDB88320 & (~(crc & 1) + 1));
}

return ~crc;
}
clang:
Code: [Select]
test_crc.c(9,4): error: assignment to cast is illegal, lvalue casts are not supported
                ((unsigned char *)msg)++;
                ~^~~~~~~~~~~~~~~~~~~~~~~
Title: Re: Possible bug with integer?
Post by: bitcoin on July 23, 2019, 02:27:56 PM
Yes, it works! I don't know C well.