[NUI] Fix Size2D not greater than int.MaxValue or less than int.MinValue
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Wed, 15 Dec 2021 07:08:19 +0000 (16:08 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 21 Dec 2021 09:32:16 +0000 (18:32 +0900)
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

index 91199a4..783d2f9 100755 (executable)
@@ -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;
     }
 }