From 8b2d91cc207102853fc138cb5d8b11675a26c1a5 Mon Sep 17 00:00:00 2001 From: JUN FANG Date: Wed, 13 May 2015 17:25:40 -0700 Subject: Fix integer overflow in conversion from float to integer. BUG=471991 R=brucedawson@chromium.org Review URL: https://codereview.chromium.org/1141613002 --- core/src/fxcrt/fx_basic_coords.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/src/fxcrt/fx_basic_coords.cpp b/core/src/fxcrt/fx_basic_coords.cpp index 62061704c7..8e7bb3e751 100644 --- a/core/src/fxcrt/fx_basic_coords.cpp +++ b/core/src/fxcrt/fx_basic_coords.cpp @@ -4,6 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com +#include #include "../../include/fxcrt/fx_ext.h" void FX_RECT::Normalize() { @@ -53,15 +54,14 @@ FX_BOOL GetIntersection(FX_FLOAT low1, FX_FLOAT high1, FX_FLOAT low2, FX_FLOAT h } extern "C" int FXSYS_round(FX_FLOAT d) { - int iRet = 0; - if (d >= 0.0f) { - iRet = (int)(d + 0.5f); - if (iRet >= 0) { - return iRet; - } - return -iRet; + if (d < (FX_FLOAT)INT_MIN) { + return INT_MIN; + } + if (d > (FX_FLOAT)INT_MAX) { + return INT_MAX; } - return (int)(d - 0.5f); + + return (int)round(d); } CFX_FloatRect::CFX_FloatRect(const FX_RECT& rect) { -- cgit v1.2.3