[Mono-dev] libgdiplus-2.8 - no need to go long long
Alexander.Stohr at gmx.de
Tue Oct 12 06:22:41 EDT 2010
Ralph Leckett (rleckett at gmail.com) wrote on Mon Oct 11 11:56:00 EDT 2010:
> The following is a better way:
> long size;
> size = bmi.biWidth;
> if (size > G_MAXINT32 / 4)
> goto error;
> size *= 4;
it does the comparison based upon the numbers length in a unit of hexadecimal digits and thus saves the code from the "long long" type.
it misses the point that you might have fractions of nibbles if the used constant would represent fractions of 4-bit nibbles. its less likely in most current architectures but the C standard only specifies a _minimum_ length for its core data types and some "sizeof x must be <= sizeof y" terms. you might never know if that even propagates to your line of code and making the constant e.g. bearing a value of 33 bits or even more (it might be some non-avoidable extra sign bit).
my proposal for a correct rounding up rule for the center line:
if (size > (G_MAXINT32 + (4 - 1)) / 4)
this should be optimized away at compile time already, so runtime performance is no issue. indeed its hard to say whats the best choice unless looking the whole context of what that snippet is intended to do. sometimes a clipping down or even hard coding of 32 bits (8 nibbles) might be the better choice. i suppose there is some dependent code afterwards i have not looked at.
PS: you have supplied a zipped archive with a smaller amount of source files.
i think when someone else talked about a patch he meant you should execute something like this:
user at machine:~> diff -Nru mono-2.8.original mono-2.8.altered >leckett-longlong-elimination.patch
Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief!
Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail
More information about the Mono-devel-list