From 3503068de0ed1e4e07e4d51a70f86af4ca401e15 Mon Sep 17 00:00:00 2001 From: Yoshi Askharoun Date: Sun, 5 Jun 2022 14:27:09 -0500 Subject: [PATCH] Fixed bitness assumptions in MessageHeap --- .../Iris/Render/Protocol/MessageHeap.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/UIX.RenderApi/Microsoft/Iris/Render/Protocol/MessageHeap.cs b/UIX.RenderApi/Microsoft/Iris/Render/Protocol/MessageHeap.cs index aa06923..58749d9 100644 --- a/UIX.RenderApi/Microsoft/Iris/Render/Protocol/MessageHeap.cs +++ b/UIX.RenderApi/Microsoft/Iris/Render/Protocol/MessageHeap.cs @@ -49,8 +49,8 @@ namespace Microsoft.Iris.Render.Protocol public unsafe void* Alloc(uint size) { size += this.allocExtraSize; - uint num = (uint)(sizeof(void*) - 1); - size = (uint)((int)size + (int)num & ~(int)num); + int num = sizeof(void*) - 1; + size = (uint)((int)size + num & ~num); MessageHeap.BlockInfo block = this.tailBlock; if (size > block.size - block.used) { @@ -63,8 +63,8 @@ namespace Microsoft.Iris.Render.Protocol } block = this.CreateBlock(type, actualSize); } - this.ZeroMemoryBlock(block, block.used, this.allocExtraSize); - void* voidPtr = (void*)((int)block.data + ((int)block.used + (int)this.allocExtraSize)); + this.ZeroMemoryBlock(block, block.used, allocExtraSize); + void* voidPtr = (void*)((nint)block.data + (block.used + allocExtraSize)); block.used += size; ++this.key; return voidPtr; @@ -170,7 +170,7 @@ namespace Microsoft.Iris.Render.Protocol { if (p >= blockInfo.data) { - void* voidPtr = (void*)((int)blockInfo.data + (int)blockInfo.used); + void* voidPtr = (void*)((nint)blockInfo.data + blockInfo.used); if (p < voidPtr) return blockInfo; } @@ -181,9 +181,9 @@ namespace Microsoft.Iris.Render.Protocol private unsafe void ZeroMemoryBlock(MessageHeap.BlockInfo block, uint offset, uint size) { Debug2.Validate(offset + size <= block.size, typeof(ArgumentOutOfRangeException), "Invalid memory range for block"); - byte* numPtr1 = (byte*)((int)block.data + (int)offset); - for (byte* numPtr2 = numPtr1 + (int)size; numPtr1 < numPtr2; ++numPtr1) - *numPtr1 = 0; + byte* start = (byte*)((nint)block.data + offset); + for (byte* current = start + size; start < current; ++start) + *start = 0; } protected override void Invariant() => Debug2.Validate(!this.IsDisposed, typeof(InvalidOperationException), "MessageHeap has already been disposed");