diff --git a/src/Tmds.DBus.Protocol/AddressReader.cs b/src/Tmds.DBus.Protocol/AddressReader.cs index 611a37e..96c1bdf 100644 --- a/src/Tmds.DBus.Protocol/AddressReader.cs +++ b/src/Tmds.DBus.Protocol/AddressReader.cs @@ -19,7 +19,7 @@ internal AddressEntry(string s, int offset, int count) => public static bool TryGetNextEntry(string addresses, ref AddressEntry address) { int offset = address.String is null ? 0 : address.Offset + address.Count + 1; - if (offset >= addresses.Length - 1) + if (offset >= addresses.Length) { return false; } @@ -145,7 +145,9 @@ private static string Unescape(ReadOnlySpan value) { return value.AsString(); } - Span unescaped = stackalloc char[Constants.StackAllocCharThreshold]; + Span unescaped = value.Length <= Constants.StackAllocCharThreshold + ? stackalloc char[Constants.StackAllocCharThreshold] + : new char[value.Length]; int pos = 0; for (int i = 0; i < value.Length;) { @@ -154,7 +156,7 @@ private static string Unescape(ReadOnlySpan value) { unescaped[pos++] = c; } - else if (i + 2 < value.Length) + else if (i + 2 <= value.Length) { int a = FromHexChar(value[i++]); int b = FromHexChar(value[i++]);