[NUI] Fix some SVACE issues.
authorhuayong.xu <huayong.xu@samsung.com>
Wed, 2 Aug 2023 02:27:38 +0000 (10:27 +0800)
committerEunki Hong <h.pichulia@gmail.com>
Wed, 9 Aug 2023 07:58:31 +0000 (16:58 +0900)
13 files changed:
src/Tizen.NUI.Components/Controls/Control.cs
src/Tizen.NUI.Components/Controls/Picker.cs
src/Tizen.NUI.Components/Controls/RecyclerView/Item/RecyclerViewItem.cs
src/Tizen.NUI.Components/Controls/ScrollableBase.cs
src/Tizen.NUI/src/internal/Common/EnumHelper.cs
src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs
src/Tizen.NUI/src/internal/XamlBinding/BindingExpression.cs
src/Tizen.NUI/src/public/BaseComponents/DirectRenderingGLView.cs
src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs
src/Tizen.NUI/src/public/BaseComponents/TextField.cs
src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs
src/Tizen.NUI/src/public/Rendering/VertexBuffer.cs
src/Tizen.NUI/src/public/XamlBinding/BindablePropertyConverter.cs

index 009f9b6..3145db3 100755 (executable)
@@ -153,10 +153,6 @@ namespace Tizen.NUI.Components
                     {
                         Log.Error("NUI", $"[ERROR] Fail to initialize Feedback: {e}");
                     }
-                    catch (NullReferenceException e)
-                    {
-                        Log.Error("NUI", $"[ERROR] Null reference error in Feedback: {e}");
-                    }
                 }
                 else
                 {
index 5d33969..2d53aa0 100755 (executable)
@@ -850,14 +850,14 @@ namespace Tizen.NUI.Components
                     startScrollOffset = (int)pickerStyle.StartScrollOffset.Height;
                 }
 
-                if (pickerStyle.ItemTextLabel?.Size != null)
+                if (pickerStyle.ItemTextLabel?.Size is var itemSize && itemSize != null)
                 {
-                    itemHeight = (int)pickerStyle.ItemTextLabel.Size.Height;
+                    itemHeight = (int)itemSize.Height;
                 }
 
-                if (pickerStyle.Size != null)
+                if (pickerStyle.Size is var pSize && pSize != null)
                 {
-                    Size = new Size(-1, pickerStyle.Size.Height);
+                    Size = new Size(-1, pSize.Height);
                 }
             }
 
index 43f080e..3f387ca 100755 (executable)
@@ -68,7 +68,7 @@ namespace Tizen.NUI.Components
                         else if (collectionView.SelectionMode is ItemSelectionMode.Multiple)
                         {
                             var selectedList = collectionView.SelectedItems;
-                            if (selectedList != null)
+                            if (selectedList != null && context != null)
                             {
                                 bool contains = selectedList.Contains(context);
                                 if (newSelected && !contains)
index ae69472..22b2fb5 100755 (executable)
@@ -1121,7 +1121,7 @@ namespace Tizen.NUI.Components
         /// <since_tizen> 8 </since_tizen>
         public void ScrollToIndex(int index)
         {
-            if (ContentContainer.ChildCount - 1 < index || index < 0)
+            if ((int)ContentContainer.ChildCount - 1 < index || index < 0)
             {
                 return;
             }
index bfef6f3..2e5d4d3 100755 (executable)
@@ -59,7 +59,8 @@ namespace Tizen.NUI
             {
                 if (description == field.Name)
                 {
-                    return (T)field.GetValue(null);
+                    var fvalue = field.GetValue(null);
+                    return fvalue != null ? (T)fvalue : default(T);
                 }
 
                 var attributes = (DescriptionAttribute[])field.GetCustomAttributes(typeof(DescriptionAttribute), true);
@@ -67,12 +68,14 @@ namespace Tizen.NUI
                 {
                     if (description == attributes.First().Description)
                     {
-                        return (T)field.GetValue(null);
+                        var fvalue = field.GetValue(null);
+                        return fvalue != null ? (T)fvalue : default(T);
                     }
                 }
             }
 
-            return (T)type.GetFields(BindingFlags.Public | BindingFlags.Static).FirstOrDefault().GetValue(null);
+            var value = type.GetFields(BindingFlags.Public | BindingFlags.Static).FirstOrDefault().GetValue(null);
+            return value != null ? (T)value : default(T);
             //throw new ArgumentException($"{description} can't be found.", "Description");
         }
 
index 97462a7..266e0b4 100755 (executable)
@@ -203,7 +203,7 @@ namespace Tizen.NUI.Xaml
                 Values[node] = value;
             }
 
-            if (value is BindableObject)
+            if (value != null && value is BindableObject)
                 NameScope.SetNameScope(value as BindableObject, node.Namescope);
         }
 
index 78d3426..53e0a91 100755 (executable)
@@ -99,19 +99,19 @@ namespace Tizen.NUI.Binding
             object sourceObject;
             if (_weakSource != null && _weakSource.TryGetTarget(out sourceObject))
             {
-                if (_parts.Count > 1)
+                for (var i = 0; i < _parts.Count; i++)
                 {
-                    for (var i = 0; i < _parts.Count - 1; i++)
-                    {
-                        BindingExpressionPart part = _parts[i];
+                    if (i + 1 == _parts.Count) //do not handle the last.
+                        break;
 
-                        if (!part.IsSelf)
-                        {
-                            part.TryGetValue(sourceObject, out sourceObject);
-                        }
+                    BindingExpressionPart part = _parts[i];
 
-                        part.Unsubscribe();
+                    if (!part.IsSelf)
+                    {
+                        part.TryGetValue(sourceObject, out sourceObject);
                     }
+
+                    part.Unsubscribe();
                 }
             }
 
index d98bb17..b2bf0d9 100644 (file)
@@ -178,13 +178,14 @@ namespace Tizen.NUI.BaseComponents
         /// You can get the bind IDs in RenderCallbackInput in the glRenderFrame callback.
         /// </summary>
         /// <param name="textures">List of Textures</param>
+        /// <exception cref="OverflowException"> Thrown when length of textures list is overflow. </exception>
         public void BindTextureResources(List<Texture> textures)
         {
             unsafe
             {
-                if (textures != null && textures.Count > 0)
+                if (textures != null && sizeof(IntPtr) * textures.Count > 0)
                 {
-                    IntPtr unmanagedPointer = Marshal.AllocHGlobal(sizeof(IntPtr) * textures.Count);
+                    IntPtr unmanagedPointer = Marshal.AllocHGlobal(checked(sizeof(IntPtr) * textures.Count));
                     IntPtr[] texturesArray = new IntPtr[textures.Count];
                     for (int i = 0; i < textures.Count; i++)
                     {
index 0220e89..9c6e7a9 100755 (executable)
@@ -2858,12 +2858,14 @@ namespace Tizen.NUI.BaseComponents
 
                 if (widthMeasureSpec.Mode != MeasureSpecification.ModeType.Exactly)
                 {
-                    totalWidth = Math.Min(Math.Max(naturalSize.Width, minSize.Width), maxSize.Width);
+                    float width = naturalSize != null ? naturalSize.Width : 0;
+                    totalWidth = Math.Min(Math.Max(width, minSize.Width), maxSize.Width);
                 }
 
                 if (heightMeasureSpec.Mode != MeasureSpecification.ModeType.Exactly)
                 {
-                    totalHeight = Math.Min(Math.Max(naturalSize.Height, minSize.Height), maxSize.Height);
+                    float height = naturalSize != null ? naturalSize.Height : 0;
+                    totalHeight = Math.Min(Math.Max(height, minSize.Height), maxSize.Height);
                 }
 
                 widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);
index f97b826..d239256 100755 (executable)
@@ -2863,12 +2863,14 @@ namespace Tizen.NUI.BaseComponents
 
                 if (widthMeasureSpec.Mode != MeasureSpecification.ModeType.Exactly)
                 {
-                    totalWidth = Math.Min(Math.Max(naturalSize.Width, minSize.Width), maxSize.Width);
+                    float width = naturalSize != null ? naturalSize.Width : 0;
+                    totalWidth = Math.Min(Math.Max(width, minSize.Width), maxSize.Width);
                 }
 
                 if (heightMeasureSpec.Mode != MeasureSpecification.ModeType.Exactly)
                 {
-                    totalHeight = Math.Min(Math.Max(naturalSize.Height, minSize.Height), maxSize.Height);
+                    float height = naturalSize != null ? naturalSize.Height : 0;
+                    totalHeight = Math.Min(Math.Max(height, minSize.Height), maxSize.Height);
                 }
 
                 widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);
index 51e5427..f3b532f 100755 (executable)
@@ -58,13 +58,16 @@ namespace Tizen.NUI.BaseComponents
                     if (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
                     {
                         // GetWidthForHeight is not implemented.
-                        totalWidth = Math.Min(Math.Max(naturalSize.Width, minSize.Width), (maxSize.Width < 0 ? Int32.MaxValue : maxSize.Width));
+                        float width = naturalSize != null ? naturalSize.Width : 0;
+                        totalWidth = Math.Min(Math.Max(width, minSize.Width), (maxSize.Width < 0 ? Int32.MaxValue : maxSize.Width));
                         widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);
                     }
                     else
                     {
-                        totalWidth = Math.Min(Math.Max(naturalSize.Width, minSize.Width), (maxSize.Width < 0 ? Int32.MaxValue : maxSize.Width));
-                        totalHeight = Math.Min(Math.Max(naturalSize.Height, minSize.Height), (maxSize.Height < 0 ? Int32.MaxValue : maxSize.Height));
+                        float width = naturalSize != null ? naturalSize.Width : 0;
+                        float height = naturalSize != null ? naturalSize.Height : 0;
+                        totalWidth = Math.Min(Math.Max(width, minSize.Width), (maxSize.Width < 0 ? Int32.MaxValue : maxSize.Width));
+                        totalHeight = Math.Min(Math.Max(height, minSize.Height), (maxSize.Height < 0 ? Int32.MaxValue : maxSize.Height));
 
                         heightMeasureSpec = new MeasureSpecification(new LayoutLength(totalHeight), MeasureSpecification.ModeType.Exactly);
                         widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);
index 71a0a23..8c4fd0d 100755 (executable)
@@ -50,6 +50,7 @@ namespace Tizen.NUI
         /// </summary>
         /// <param name="vertices">The vertex data that will be copied to the buffer.</param>
         /// <exception cref="ArgumentNullException"> Thrown when vertices is null or length of the vertices is 0. </exception>
+        /// <exception cref="OverflowException"> Thrown when length of the vertices is overflow. </exception>
         /// <since_tizen> 8 </since_tizen>
 
         public void SetData<VertexType>(VertexType[] vertices) where VertexType : struct
@@ -60,7 +61,7 @@ namespace Tizen.NUI
             }
 
             int structSize = Marshal.SizeOf<VertexType>();
-            global::System.IntPtr buffer = Marshal.AllocHGlobal(structSize * vertices.Length);
+            global::System.IntPtr buffer = Marshal.AllocHGlobal(checked(structSize * vertices.Length));
 
             for (int i = 0; i < vertices.Length; i++)
             {
index 963cccc..3e349f9 100755 (executable)
@@ -71,7 +71,7 @@ namespace Tizen.NUI.Binding
                         type = xamlStyle.TargetType;
                 }
                 else if (parentValuesProvider.TargetObject is Trigger)
-                    type = (parentValuesProvider.TargetObject as Trigger).TargetType;
+                    type = (parentValuesProvider.TargetObject as Trigger)?.TargetType;
                 else if (parentValuesProvider.TargetObject is XamlPropertyCondition && (parent as TriggerBase) != null)
                     type = (parent as TriggerBase).TargetType;