mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 791428 - Limit pixel sizes so that they can't exceed app unit limits. r=roc
This commit is contained in:
parent
ff8dcd1bcd
commit
dcf38e4630
@ -444,6 +444,22 @@ inline nscoord NSIntPixelsToAppUnits(int32_t aPixels, int32_t aAppUnitsPerPixel)
|
||||
{
|
||||
// The cast to nscoord makes sure we don't overflow if we ever change
|
||||
// nscoord to float
|
||||
#ifndef NS_COORD_IS_FLOAT
|
||||
const int pixels_MAX = nscoord_MAX / aAppUnitsPerPixel;
|
||||
// Bounds-check before converting out of float, to avoid overflow
|
||||
NS_WARN_IF_FALSE(aPixels <= pixels_MAX,
|
||||
"Overflowed nscoord_MAX in conversion to nscoord");
|
||||
if (aPixels >= pixels_MAX) {
|
||||
aPixels = pixels_MAX;
|
||||
} else {
|
||||
const int pixels_MIN = nscoord_MIN / aAppUnitsPerPixel;
|
||||
NS_WARN_IF_FALSE(aPixels >= pixels_MIN,
|
||||
"Overflowed nscoord_MIN in conversion to nscoord");
|
||||
if (aPixels <= pixels_MIN) {
|
||||
aPixels = pixels_MIN;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
nscoord r = aPixels * (nscoord)aAppUnitsPerPixel;
|
||||
VERIFY_COORD(r);
|
||||
return r;
|
||||
|
Loading…
Reference in New Issue
Block a user