Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Add null check to Tensor indexer and change which ToSpan method to ca…
Browse files Browse the repository at this point in the history
…ll. (#2121)
  • Loading branch information
ahsonkhan authored Feb 14, 2018
1 parent c176739 commit 3243d04
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/System.Numerics.Tensors/System/Numerics/Tensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -750,12 +750,20 @@ public virtual T this[params int[] indices]
{
get
{
if (indices == null)
{
throw new ArgumentNullException(nameof(indices));
}
var span = new Span<int>(indices);
return this[span];
}

set
{
if (indices == null)
{
throw new ArgumentNullException(nameof(indices));
}
var span = new Span<int>(indices);
this[span] = value;
}
Expand Down
8 changes: 4 additions & 4 deletions src/System.Text.Http.Parser/HttpParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public unsafe bool ParseRequestLine<T>(T handler, in ReadOnlySequence<byte> buff
{
if (TryGetNewLineSpan(buffer, out SequencePosition found))
{
span = Sequence.ToSpan(buffer.Slice(consumed, found));
span = PipelineExtensions.ToSpan(buffer.Slice(consumed, found));
consumed = found;
}
else
Expand Down Expand Up @@ -102,7 +102,7 @@ public unsafe bool ParseRequestLine<T>(ref T handler, in ReadOnlySequence<byte>
return false;
}

span = Sequence.ToSpan(buffer.Slice(0, eol + s_Eol.Length));
span = PipelineExtensions.ToSpan(buffer.Slice(0, eol + s_Eol.Length));
}

// Fix and parse the span
Expand Down Expand Up @@ -335,7 +335,7 @@ public unsafe bool ParseHeaders<T>(T handler, in ReadOnlySequence<byte> buffer,

// Make sure LF is included in lineEnd
lineEnd = subBuffer.GetPosition(lineEnd.Value, 1);
var headerSpan = Sequence.ToSpan(subBuffer.Slice(current, lineEnd.Value));
var headerSpan = PipelineExtensions.ToSpan(subBuffer.Slice(current, lineEnd.Value));
length = headerSpan.Length;

fixed (byte* pHeader = &MemoryMarshal.GetReference(headerSpan))
Expand Down Expand Up @@ -451,7 +451,7 @@ public unsafe bool ParseHeaders<T>(ref T handler, ReadOnlySequence<byte> buffer,
return false;
}

var headerSpan = Sequence.ToSpan(buffer.Slice(index, end - index + 1));
var headerSpan = PipelineExtensions.ToSpan(buffer.Slice(index, end - index + 1));
length = headerSpan.Length;

fixed (byte* pHeader = &MemoryMarshal.GetReference(headerSpan))
Expand Down
1 change: 1 addition & 0 deletions tests/System.Numerics.Tensors.Tests/TensorSliceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ public void SliceIndexOutOfRange(TensorConstructor constructor)
{
var slice = Get3DSlice(constructor);

Assert.Throws<ArgumentNullException>(() => slice[(int[])null]);
Assert.Throws<ArgumentException>(() => slice[new int[] { }]);
Assert.Throws<ArgumentException>(() => slice[default(ReadOnlySpan<int>)]);
Assert.Throws<ArgumentException>(() => slice[2, 0]);
Expand Down

0 comments on commit 3243d04

Please sign in to comment.