Changed unspecified size to uint.Max instead of UIntPtr.Max to prevent overflow

pull/83/head
David Hall 2019-11-25 19:32:51 -07:00
parent 2036104502
commit 80b7256543
1 changed files with 3 additions and 3 deletions

View File

@ -404,7 +404,7 @@ namespace Vanara.Extensions
var stSize = SizeOf(type);
if (allocatedBytes > 0 && stSize * count + prefixBytes > allocatedBytes)
throw new InsufficientMemoryException();
if (allocatedBytes == default) allocatedBytes = SizeT.MaxValue;
if (allocatedBytes == default) allocatedBytes = uint.MaxValue;
for (var i = 0; i < count; i++)
{
var offset = prefixBytes + i * stSize;
@ -437,7 +437,7 @@ namespace Vanara.Extensions
var stSize = SizeOf(type);
if (allocatedBytes > 0 && stSize * count + prefixBytes > allocatedBytes)
throw new InsufficientMemoryException();
if (allocatedBytes == default) allocatedBytes = SizeT.MaxValue;
if (allocatedBytes == default) allocatedBytes = uint.MaxValue;
for (var i = 0; i < count; i++)
{
var offset = prefixBytes + i * stSize;
@ -588,7 +588,7 @@ namespace Vanara.Extensions
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public static T ToStructure<T>(this IntPtr ptr, SizeT allocatedBytes = default, int offset = 0)
{
if (allocatedBytes == default) allocatedBytes = SizeT.MaxValue;
if (allocatedBytes == default) allocatedBytes = uint.MaxValue;
return ptr.Offset(offset).Convert<T>(allocatedBytes - (uint)offset);
}