Christoph Hellwig <[EMAIL PROTECTED]> writes:
>> +static unsigned int
>> +scdrv_buffer_to_int(char *buf)
>> +{
>> + int i;
>> + unsigned int n = 0;
>> + for( i = 0; i < sizeof(n); i++ ) {
>> + n |= ((unsigned)(*(unsigned char *)buf++)
>> + << (8 * ((sizeof(n) - i) - 1)));
>
> urgg. the (*(unsigned char *)buf++) should be just *(buf++), no?
> address arithmetics on signed and unsigned char are the same.
But not value promotion. The latter gives you a different value when *buf
is negative. For example if *buf == -1 then (unsigned)*buf == 0xffffffff,
but (unsigned char)*buf == 0xff.
> So
> for (i = 0; i < sizeof(n); i++)
> n |= ((unsigned int)buf[i] << (8 * (sizeof(n) - i - 1)));
>
> should do the same, no?
This should be better:
for (i = 0; i < sizeof(n); i++)
n |= ((unsigned char)buf[i] << (8 * (sizeof(n) - i - 1)));
Or even better: replace scdrv_buffer_to_int by be32_to_cpup.
Andreas.
--
Andreas Schwab, SuSE Labs, [EMAIL PROTECTED]
SuSE Linux Products GmbH, Maxfeldstra�e 5, 90409 N�rnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
-
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html