Skip to content

Commit

Permalink
Test+fix for allocating int.MaxValue stream size.
Browse files Browse the repository at this point in the history
  • Loading branch information
doubleyewdee committed Dec 10, 2016
1 parent dac6386 commit ef151ba
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions UnitTests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/RecyclableMemoryStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ef151ba

Please sign in to comment.