mirror of https://github.com/dahall/Vanara.git
Fix and test for #101 - Bug when using SafeAnysizeStruct.
parent
16aa08ec14
commit
cc7170875f
|
@ -123,9 +123,9 @@ namespace Vanara.InteropServices
|
||||||
Size = memSz;
|
Size = memSz;
|
||||||
// Marshal base structure - don't use Write to prevent loops
|
// Marshal base structure - don't use Write to prevent loops
|
||||||
Marshal.StructureToPtr(value, handle, false);
|
Marshal.StructureToPtr(value, handle, false);
|
||||||
// Push each element of the array into memory
|
// Push each element of the array into memory, starting with second item in array since first was pushed by StructureToPtr
|
||||||
for (var i = 0; i < arrLen; i++)
|
for (var i = 1; i < arrLen; i++)
|
||||||
handle.Write(((Array)arrVal).GetValue(i), baseSz - arrElemSz * (i - 1), memSz);
|
handle.Write(((Array)arrVal).GetValue(i), baseSz + arrElemSz * (i - 1), memSz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace Vanara.InteropServices.Tests
|
||||||
[Test]
|
[Test]
|
||||||
public void ConvertTest()
|
public void ConvertTest()
|
||||||
{
|
{
|
||||||
var array = new[] { long.MinValue, 0L, long.MaxValue };
|
var array = new[] { long.MinValue, 1L, long.MaxValue };
|
||||||
var ts = new TestStruct { iVal = array.Length, array = array };
|
var ts = new TestStruct { iVal = array.Length, array = array };
|
||||||
|
|
||||||
using var mem = new SafeAnysizeStruct<TestStruct>(ts);
|
using var mem = new SafeAnysizeStruct<TestStruct>(ts);
|
||||||
|
|
Loading…
Reference in New Issue