Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undefined layout behaviour, and remove pinning: Uint256 and Uint160 #1387

Merged
merged 17 commits into from
Jan 15, 2020
9 changes: 4 additions & 5 deletions src/neo/UInt256.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;

namespace Neo
{
/// <summary>
/// This class stores a 256 bit unsigned int, represented as a 32-byte little-endian byte array
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public class UInt256 : UIntBase, IComparable<UInt256>, IEquatable<UInt256>
{
public const int Length = 32;
Expand All @@ -25,11 +27,8 @@ public UInt256()

public unsafe UInt256(ReadOnlySpan<byte> value)
john-h-k marked this conversation as resolved.
Show resolved Hide resolved
{
fixed (ulong* p = &value1)
{
Span<byte> dst = new Span<byte>(p, Length);
value[..Length].CopyTo(dst);
}
Span<byte> dst = MemoryMarshal.AsBytes(MemoryMarshal.CreateSpan(ref value1, Length / sizeof(ulong)));
value[..Length].CopyTo(dst);
}
shargon marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
Expand Down