mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 11:55:49 +00:00
Bug 381074 - Add overflow check for unit conversion in NSFloatPixelsToAppUnits. r=bz sr=roc blocking1.9=dbaron
This commit is contained in:
parent
b023149d49
commit
e81193d88b
@ -88,9 +88,27 @@ inline PRInt32 NSToIntRound(float aValue)
|
||||
*/
|
||||
inline nscoord NSFloatPixelsToAppUnits(float aPixels, PRInt32 aAppUnitsPerPixel)
|
||||
{
|
||||
nscoord r = NSToCoordRound(aPixels * aAppUnitsPerPixel);
|
||||
VERIFY_COORD(r);
|
||||
return r;
|
||||
float product = aPixels * aAppUnitsPerPixel;
|
||||
nscoord result;
|
||||
|
||||
#ifdef NS_COORD_IS_FLOAT
|
||||
// No need to bounds-check if converting float to float
|
||||
result = NSToCoordRound(product);
|
||||
#else
|
||||
// Bounds-check before converting out of float, to avoid overflow
|
||||
if (product >= nscoord_MAX) {
|
||||
NS_WARNING("Overflowed nscoord_MAX in conversion to nscoord");
|
||||
result = nscoord_MAX;
|
||||
} else if (product <= nscoord_MIN) {
|
||||
NS_WARNING("Overflowed nscoord_MIN in conversion to nscoord");
|
||||
result = nscoord_MIN;
|
||||
} else {
|
||||
result = NSToCoordRound(product);
|
||||
}
|
||||
#endif
|
||||
|
||||
VERIFY_COORD(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline nscoord NSIntPixelsToAppUnits(PRInt32 aPixels, PRInt32 aAppUnitsPerPixel)
|
||||
|
Loading…
Reference in New Issue
Block a user