From de1f178f303878da3ad45a2b22e9a2fbec7b9d04 Mon Sep 17 00:00:00 2001 From: Matthew Endsley Date: Wed, 31 Mar 2021 11:56:47 -0700 Subject: [PATCH] Add additional context for invalid ByteSpans --- Hazel/ByteSpan.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Hazel/ByteSpan.cs b/Hazel/ByteSpan.cs index 9d33193..506b153 100644 --- a/Hazel/ByteSpan.cs +++ b/Hazel/ByteSpan.cs @@ -54,9 +54,13 @@ namespace Hazel { throw new ArgumentException("Invalid offset", nameof(offset)); } - if (length < 0 || (offset + length) > array.Length) + if (length < 0) { - throw new ArgumentException("Invalid length", nameof(length)); + throw new ArgumentException($"Invalid length: {length}", nameof(length)); + } + if ((offset + length) > array.Length) + { + throw new ArgumentException($"Invalid length. Length: {length} Offset: {offset} Array size: {array.Length}", nameof(length)); } this.array_ = array; -- 2.39.5