diff --git a/src/ImageSharp/Image.WrapMemory.cs b/src/ImageSharp/Image.WrapMemory.cs index e44af5d0d1..eac202a41f 100644 --- a/src/ImageSharp/Image.WrapMemory.cs +++ b/src/ImageSharp/Image.WrapMemory.cs @@ -609,14 +609,14 @@ public abstract partial class Image ImageMetadata metadata) where TPixel : unmanaged, IPixel { - Guard.IsFalse(pointer == null, nameof(pointer), "Pointer must be not null"); + Guard.IsFalse(pointer == null, nameof(pointer), "Pointer must not be null"); Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(metadata, nameof(metadata)); int rowStride = GetPixelRowStrideFromByteStride(width, rowStrideInBytes, nameof(rowStrideInBytes)); long requiredLength = GetRequiredLength(width, height, rowStride); - Guard.MustBeLessThanOrEqualTo(requiredLength, int.MaxValue, nameof(height)); + Guard.MustBeLessThanOrEqualTo(requiredLength, int.MaxValue, nameof(requiredLength)); Guard.MustBeGreaterThanOrEqualTo(bufferSizeInBytes / Unsafe.SizeOf(), requiredLength, nameof(bufferSizeInBytes)); UnmanagedMemoryManager memoryManager = new(pointer, (int)requiredLength); diff --git a/src/ImageSharp/Memory/Buffer2D{T}.cs b/src/ImageSharp/Memory/Buffer2D{T}.cs index 3194aebae7..fe997a4fbf 100644 --- a/src/ImageSharp/Memory/Buffer2D{T}.cs +++ b/src/ImageSharp/Memory/Buffer2D{T}.cs @@ -356,7 +356,7 @@ public sealed class Buffer2D : IDisposable /// Thrown when the backing group is discontiguous. /// [MethodImpl(InliningOptions.ShortMethod)] - internal Span DangerousGetSingleSpan() => this.FastMemoryGroup[0].Span; + internal Span DangerousGetSingleSpan() => this.FastMemoryGroup.Single().Span; /// /// Gets a to the backing data of if the backing group consists of a single contiguous memory buffer. @@ -367,7 +367,7 @@ public sealed class Buffer2D : IDisposable /// Thrown when the backing group is discontiguous. /// [MethodImpl(InliningOptions.ShortMethod)] - internal Memory DangerousGetSingleMemory() => this.FastMemoryGroup[0]; + internal Memory DangerousGetSingleMemory() => this.FastMemoryGroup.Single(); /// /// Swaps the contents of 'destination' with 'source' if the buffers are owned (1), @@ -414,5 +414,5 @@ public sealed class Buffer2D : IDisposable [MethodImpl(InliningOptions.ShortMethod)] private static long GetRequiredLength(int width, int height, int stride) - => ((long)(height - 1) * stride) + width; + => checked(((long)(height - 1) * stride) + width); }