From ef151ba28bfabf12e7a2fe046daf6f7806fad55d Mon Sep 17 00:00:00 2001 From: Chip Locke Date: Fri, 9 Dec 2016 17:24:17 -0800 Subject: [PATCH] Test+fix for allocating int.MaxValue stream size. --- UnitTests/Tests.cs | 3 +++ src/RecyclableMemoryStream.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/UnitTests/Tests.cs b/UnitTests/Tests.cs index b0b2443a..cd56777e 100644 --- a/UnitTests/Tests.cs +++ b/UnitTests/Tests.cs @@ -444,6 +444,9 @@ public void GiantAllocationSucceeds() var stream = mgr.GetStream(null, requestedSize); Assert.IsTrue(stream.Capacity >= requestedSize); } + + var maxStream = mgr.GetStream(null, int.MaxValue); + Assert.IsTrue(maxStream.Capacity == int.MaxValue); } #endregion diff --git a/src/RecyclableMemoryStream.cs b/src/RecyclableMemoryStream.cs index d85d518a..c9b41c48 100644 --- a/src/RecyclableMemoryStream.cs +++ b/src/RecyclableMemoryStream.cs @@ -314,7 +314,7 @@ public override int Capacity return this.largeBuffer.Length; } - long size = this.blocks.Count * this.memoryManager.BlockSize; + long size = (long)this.blocks.Count * this.memoryManager.BlockSize; return (int)Math.Min(int.MaxValue, size); } set