Skip to content

Net 8 "Index was outside bounds of array" #190

@hexbyt3

Description

@hexbyt3

image

Latest build in debug mode shows an issue with this in particular on bot start up.

    public async Task<SAV9SV> GetFakeTrainerSAV(CancellationToken token)
    {
        var sav = new SAV9SV();
        var info = sav.MyStatus;
        var read = await SwitchConnection.PointerPeek(info.Data.Length, Offsets.MyStatusPointer, token).ConfigureAwait(false);
        read.CopyTo(info.Data, 0);
        return sav;
    }
Particularly with var read.  

It looks like the issue could be stemming from Decoder.cs line 27

I think that the issue lies in the data being passed to the LoadHexBytesTo method. This error is thrown because the length of the str parameter is not an even multiple of tupleSize, which is expected to be 2 for hexadecimal byte pairs.

    public static void LoadHexBytesTo(ReadOnlySpan<byte> str, Span<byte> dest, int tupleSize)
{
    // The input string is 2-char hex values optionally separated.
    // The destination array should always be larger or equal than the bytes written. Let the runtime bounds check us.
    // Iterate through the string without allocating.
    for (int i = 0, j = 0; i < str.Length; i += tupleSize)
        dest[j++] = DecodeTuple((char)str[i + 0], (char)str[i + 1]);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions