Skip to content

Commit

Permalink
fix(storage): Ensure that the array return by the Buffer.GetSegment c…
Browse files Browse the repository at this point in the history
…annot be null
  • Loading branch information
dr1rrb committed Oct 9, 2020
1 parent 874fd8e commit 8784b73
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Uno.UWP/Storage/Streams/Buffer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Windows.Foundation;

Expand Down Expand Up @@ -52,9 +53,14 @@ internal byte GetByte(int index)
/// <summary>
/// Retrieve the underlying data array
/// </summary>
/// <remarks>
/// The <see cref="ArraySegment{T}.Array"/> of the return cannot be null.
/// This method will throw an <see cref="InvalidOperationException"/> in that case.
/// </remarks>
internal ArraySegment<byte> GetSegment()
{
if (MemoryMarshal.TryGetArray<byte>(_data, out var array))
if (MemoryMarshal.TryGetArray<byte>(_data, out var array)
&& array.Array != null)
{
return array;
}
Expand Down

0 comments on commit 8784b73

Please sign in to comment.