From 0624e2c93bab235ffe26421685719cc439d56814 Mon Sep 17 00:00:00 2001 From: Jaehyun Cho Date: Wed, 15 Dec 2021 16:08:19 +0900 Subject: [PATCH] [NUI] Fix Size2D not greater than int.MaxValue or less than int.MinValue Since Size2D converts Width/Height from float to int internally, Width/Height values may be greater than int.MaxValue or less than int.MinValue. To resolve the above issue, Width/Height values are checked if they are greater than int.MaxValue or less than int.MinValue. --- src/Tizen.NUI/src/public/Common/Size2D.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Tizen.NUI/src/public/Common/Size2D.cs b/src/Tizen.NUI/src/public/Common/Size2D.cs index 91199a4..783d2f9 100755 --- a/src/Tizen.NUI/src/public/Common/Size2D.cs +++ b/src/Tizen.NUI/src/public/Common/Size2D.cs @@ -133,7 +133,7 @@ namespace Tizen.NUI { float ret = Interop.Vector2.WidthGet(SwigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return (int)ret; + return ClampToInt(ret); } } @@ -166,7 +166,7 @@ namespace Tizen.NUI { float ret = Interop.Vector2.HeightGet(SwigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return (int)ret; + return ClampToInt(ret); } } @@ -457,5 +457,10 @@ namespace Tizen.NUI if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } + + private static int ClampToInt(double v) => + v > int.MaxValue ? int.MaxValue + : v < int.MinValue ? int.MinValue + : (int)v; } } -- 2.7.4