| Date | Tue, 30 Jul 2019 20:51:14 +0200 | From | Pavel Machek <> | Subject | Re: [PATCH 4.19 044/113] iio: iio-utils: Fix possible incorrect mask calculation |
| |
Hi!
> [ Upstream commit 208a68c8393d6041a90862992222f3d7943d44d6 ] > > On some machines, iio-sensor-proxy was returning all 0's for IIO sensor > values. It turns out that the bits_used for this sensor is 32, which makes > the mask calculation: > > *mask = (1 << 32) - 1; > > If the compiler interprets the 1 literals as 32-bit ints, it generates > undefined behavior depending on compiler version and optimization > level.
Ok, it would be problem if code was like that. But it is not:
> @@ -159,9 +159,9 @@ int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used, > *be = (endianchar == 'b'); > *bytes = padint / 8; > if (*bits_used == 64) > - *mask = ~0; > + *mask = ~(0ULL); > else > - *mask = (1ULL << *bits_used) - 1; > + *mask = (1ULL << *bits_used) - 1ULL; >
Note 1ULL already being there before the change. AFAICT this does not change anything; 1ULL << foo will already have long long type, so substraction will be long long too.
AFAICT this does not change the binary code at all, so it can't fix a bug...
Best regards,
Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html [unhandled content-type:application/pgp-signature] |