0
votes

Alright, I can't figure this one out. The debugger isn't giving much information about this particular exception.

Here is the function being called:

NC_LIBEXPORT(VOID) ncKeyExpand(unsigned char* key, int initlen)
{
    int abspos = initlen;
    int curkpos = 0;
    do
    {
        key[abspos] = key[curkpos];
        ++abspos;
        ++curkpos;
        if(curkpos >= initlen)
            curkpos = 0;

    } while (curkpos < NC_KEY_MAX_LENGTH);
}

And the access violation happens on the second line here:

unsigned char apkey[NC_KEY_MAX_LENGTH];
ncKeyExpand(&apkey[0], NC_PRIV_KEY_LENGTH);

Any insight as to why this is happening? Nothing I do is fixing it.

Unhandled exception at 0x776e7094 in Test Application.exe: 0xC0000005:

That is the exact error.

Access violation.

Aren't access violations when a pointer points to an address that isn't accessible, like if it's been freed or out of scope, or null, etc.? If so, why is it being raised here? The char array is right there.

1
What are the values of NC_KEY_MAX_LENGTH and NC_PRIV_KEY_LENGTH? - Retired Ninja

1 Answers

1
votes

Your array is declared with length NC_KEY_MAX_LENGTH which means you can access locations of it from apkey[0] thr' apkey[NC_KEY_MAX_LENGTH-1].

if you look at your function

do
{
    key[abspos] = key[curkpos];
    ++abspos;

you are accessing beyond your array size..