HexMate icon indicating copy to clipboard operation
HexMate copied to clipboard

TryFromHexChars gives wrong results if the target bytes buffer is not all 0s

Open rwasef1830 opened this issue 1 year ago • 0 comments

Hello, The following code demonstrates the problem. Windows 11 x64. CPU: AMD 5950x

void Main()
{
    var bytes = new byte[1] { 0 };
    var hex = "31";
    if (!HexMate.Convert.TryFromHexChars(hex, bytes, out var written) || written != 1)
    {
        throw new Exception("Error");
    }
    var generatedHex = Convert.ToHexString(bytes);
    Debug.Assert(generatedHex == hex); // passes

    bytes[0] = 0x8a;
    if (!HexMate.Convert.TryFromHexChars(hex, bytes, out written) || written != 1)
    {
        throw new Exception("Error");
    }
    generatedHex = Convert.ToHexString(bytes);
    Debug.Assert(generatedHex == hex); // fails
}

rwasef1830 avatar Jul 03 '23 19:07 rwasef1830