aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Common/Memory/SpanReader.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2023-06-12 21:12:06 -0300
committerGitHub <noreply@github.com>2023-06-13 00:12:06 +0000
commitcf4c78b9c825f61ff3ee83eff88442a149ae01d9 (patch)
tree79c336bb501224d510aa63503380a9475235df8e /src/Ryujinx.Common/Memory/SpanReader.cs
parent52aa4b6c22ce697f82ae59c6c6610eadf6bbeacf (diff)
Make LM skip instead of crashing for invalid messages (#5290)1.1.888
Diffstat (limited to 'src/Ryujinx.Common/Memory/SpanReader.cs')
-rw-r--r--src/Ryujinx.Common/Memory/SpanReader.cs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Ryujinx.Common/Memory/SpanReader.cs b/src/Ryujinx.Common/Memory/SpanReader.cs
index 673932d0..9a1a0a3f 100644
--- a/src/Ryujinx.Common/Memory/SpanReader.cs
+++ b/src/Ryujinx.Common/Memory/SpanReader.cs
@@ -24,6 +24,24 @@ namespace Ryujinx.Common.Memory
return value;
}
+ public bool TryRead<T>(out T value) where T : unmanaged
+ {
+ int valueSize = Unsafe.SizeOf<T>();
+
+ if (valueSize > _input.Length)
+ {
+ value = default;
+
+ return false;
+ }
+
+ value = MemoryMarshal.Cast<byte, T>(_input)[0];
+
+ _input = _input.Slice(valueSize);
+
+ return true;
+ }
+
public ReadOnlySpan<byte> GetSpan(int size)
{
ReadOnlySpan<byte> data = _input.Slice(0, size);