-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing 0 length issue with constructor #107427
Fixing 0 length issue with constructor #107427
Conversation
This expression can be simplified... if ((maxElements >= span.Length && span.Length != 0) || (span.Length == 0 && maxElements > 0))
ThrowHelper.ThrowArgument_InvalidStridesAndLengths(); ... to: if (maxElements > 0 && maxElements >= span.Length)
ThrowHelper.ThrowArgument_InvalidStridesAndLengths(); Explanation: For simplicity, let's represent if ((a >= b && b != 0) || (b == 0 && a > 0))
error; We can normalize the condition by switching the order of the expressions if ((a >= b && b != 0) || (a > 0 && b == 0))
error; This can be interpreted as: if ((a >= b && b != 0) // a > 0, b > 0, a >= b
|| (a > 0 && b == 0)) // a > 0, b = 0
error; Thus, we are only interested in cases where In the end, we get: if (a > 0 && a >= b)
error; The final expression will look like this: if (maxElements > 0 && maxElements >= span.Length)
ThrowHelper.ThrowArgument_InvalidStridesAndLengths(); |
src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan.cs
Outdated
Show resolved
Hide resolved
…ors/netcore/ReadOnlyTensorSpan.cs Co-authored-by: Stephen Toub <stoub@microsoft.com>
src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorSpan.cs
Outdated
Show resolved
Hide resolved
/backport to release/9.0 |
Started backporting to release/9.0: https://github.com/dotnet/runtime/actions/runs/10889241013 |
* fixing 0 length issue with constructor * Update src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> * comments from PR --------- Co-authored-by: Stephen Toub <stoub@microsoft.com>
* fixing 0 length issue with constructor * Update src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> * comments from PR --------- Co-authored-by: Stephen Toub <stoub@microsoft.com>
Fixes #106538 by modifying the check in the constructor to also throw an error if the base memory length is 0.