From 8b7fb6009be60df04246a3e4f874e47f74a8dcbb Mon Sep 17 00:00:00 2001 From: "huayong.xu" Date: Wed, 2 Aug 2023 10:27:38 +0800 Subject: [PATCH] [NUI] Fix some SVACE issues. --- src/Tizen.NUI.Components/Controls/Control.cs | 4 ---- src/Tizen.NUI.Components/Controls/Picker.cs | 8 ++++---- .../Controls/RecyclerView/Item/RecyclerViewItem.cs | 2 +- src/Tizen.NUI.Components/Controls/ScrollableBase.cs | 2 +- src/Tizen.NUI/src/internal/Common/EnumHelper.cs | 9 ++++++--- src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs | 2 +- .../src/internal/XamlBinding/BindingExpression.cs | 18 +++++++++--------- .../src/public/BaseComponents/DirectRenderingGLView.cs | 5 +++-- src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs | 6 ++++-- src/Tizen.NUI/src/public/BaseComponents/TextField.cs | 6 ++++-- src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs | 9 ++++++--- src/Tizen.NUI/src/public/Rendering/VertexBuffer.cs | 3 ++- .../public/XamlBinding/BindablePropertyConverter.cs | 2 +- 13 files changed, 42 insertions(+), 34 deletions(-) diff --git a/src/Tizen.NUI.Components/Controls/Control.cs b/src/Tizen.NUI.Components/Controls/Control.cs index 009f9b6..3145db3 100755 --- a/src/Tizen.NUI.Components/Controls/Control.cs +++ b/src/Tizen.NUI.Components/Controls/Control.cs @@ -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 { diff --git a/src/Tizen.NUI.Components/Controls/Picker.cs b/src/Tizen.NUI.Components/Controls/Picker.cs index 5d33969..2d53aa0 100755 --- a/src/Tizen.NUI.Components/Controls/Picker.cs +++ b/src/Tizen.NUI.Components/Controls/Picker.cs @@ -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); } } diff --git a/src/Tizen.NUI.Components/Controls/RecyclerView/Item/RecyclerViewItem.cs b/src/Tizen.NUI.Components/Controls/RecyclerView/Item/RecyclerViewItem.cs index 43f080e..3f387ca 100755 --- a/src/Tizen.NUI.Components/Controls/RecyclerView/Item/RecyclerViewItem.cs +++ b/src/Tizen.NUI.Components/Controls/RecyclerView/Item/RecyclerViewItem.cs @@ -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) diff --git a/src/Tizen.NUI.Components/Controls/ScrollableBase.cs b/src/Tizen.NUI.Components/Controls/ScrollableBase.cs index ae69472..22b2fb5 100755 --- a/src/Tizen.NUI.Components/Controls/ScrollableBase.cs +++ b/src/Tizen.NUI.Components/Controls/ScrollableBase.cs @@ -1121,7 +1121,7 @@ namespace Tizen.NUI.Components /// 8 public void ScrollToIndex(int index) { - if (ContentContainer.ChildCount - 1 < index || index < 0) + if ((int)ContentContainer.ChildCount - 1 < index || index < 0) { return; } diff --git a/src/Tizen.NUI/src/internal/Common/EnumHelper.cs b/src/Tizen.NUI/src/internal/Common/EnumHelper.cs index bfef6f3..2e5d4d3 100755 --- a/src/Tizen.NUI/src/internal/Common/EnumHelper.cs +++ b/src/Tizen.NUI/src/internal/Common/EnumHelper.cs @@ -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"); } diff --git a/src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs b/src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs index 97462a7..266e0b4 100755 --- a/src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs +++ b/src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs @@ -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); } diff --git a/src/Tizen.NUI/src/internal/XamlBinding/BindingExpression.cs b/src/Tizen.NUI/src/internal/XamlBinding/BindingExpression.cs index 78d3426..53e0a91 100755 --- a/src/Tizen.NUI/src/internal/XamlBinding/BindingExpression.cs +++ b/src/Tizen.NUI/src/internal/XamlBinding/BindingExpression.cs @@ -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(); } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/DirectRenderingGLView.cs b/src/Tizen.NUI/src/public/BaseComponents/DirectRenderingGLView.cs index d98bb17..b2bf0d9 100644 --- a/src/Tizen.NUI/src/public/BaseComponents/DirectRenderingGLView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/DirectRenderingGLView.cs @@ -178,13 +178,14 @@ namespace Tizen.NUI.BaseComponents /// You can get the bind IDs in RenderCallbackInput in the glRenderFrame callback. /// /// List of Textures + /// Thrown when length of textures list is overflow. public void BindTextureResources(List 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++) { diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs b/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs index 0220e89..9c6e7a9 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs @@ -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); diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextField.cs b/src/Tizen.NUI/src/public/BaseComponents/TextField.cs index f97b826..d239256 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextField.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextField.cs @@ -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); diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs b/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs index 51e5427..f3b532f 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs @@ -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); diff --git a/src/Tizen.NUI/src/public/Rendering/VertexBuffer.cs b/src/Tizen.NUI/src/public/Rendering/VertexBuffer.cs index 71a0a23..8c4fd0d 100755 --- a/src/Tizen.NUI/src/public/Rendering/VertexBuffer.cs +++ b/src/Tizen.NUI/src/public/Rendering/VertexBuffer.cs @@ -50,6 +50,7 @@ namespace Tizen.NUI /// /// The vertex data that will be copied to the buffer. /// Thrown when vertices is null or length of the vertices is 0. + /// Thrown when length of the vertices is overflow. /// 8 public void SetData(VertexType[] vertices) where VertexType : struct @@ -60,7 +61,7 @@ namespace Tizen.NUI } int structSize = Marshal.SizeOf(); - 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++) { diff --git a/src/Tizen.NUI/src/public/XamlBinding/BindablePropertyConverter.cs b/src/Tizen.NUI/src/public/XamlBinding/BindablePropertyConverter.cs index 963cccc..3e349f9 100755 --- a/src/Tizen.NUI/src/public/XamlBinding/BindablePropertyConverter.cs +++ b/src/Tizen.NUI/src/public/XamlBinding/BindablePropertyConverter.cs @@ -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; -- 2.7.4