From: huayong.xu Date: Wed, 2 Aug 2023 02:27:38 +0000 (+0800) Subject: [NUI] Fix some SVACE issues. X-Git-Tag: submit/tizen/20230809.080417~1^2~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8b7fb6009be60df04246a3e4f874e47f74a8dcbb;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Fix some SVACE issues. --- diff --git a/src/Tizen.NUI.Components/Controls/Control.cs b/src/Tizen.NUI.Components/Controls/Control.cs index 009f9b637..3145db3dc 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 5d3396940..2d53aa025 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 43f080eab..3f387cae3 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 ae694727d..22b2fb50d 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 bfef6f3ff..2e5d4d3fd 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 97462a726..266e0b460 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 78d342607..53e0a919f 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 d98bb173b..b2bf0d905 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 0220e8991..9c6e7a997 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 f97b826cd..d23925630 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 51e5427d8..f3b532f8c 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 71a0a23bb..8c4fd0dd1 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 963cccc90..3e349f972 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;