Bug 791428 - Limit pixel sizes so that they can't exceed app unit limits. r=roc

This commit is contained in:
Anthony Jones 2012-10-22 22:22:27 -04:00
Родитель ff8dcd1bcd
Коммит dcf38e4630
1 изменённых файлов: 16 добавлений и 0 удалений

Просмотреть файл

@ -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;