1

I was trying to copy the first 20% of an int array into another one but every time I tried, the VS debugger showed this error:

Unhandled exception at 0x00DB592A in Anti Virus.exe: 0xC0000005: Access violation reading location 0x00B41000.

here is the code:

/*
regularStr - the full arr
regularLen - its size
mode - what part of the array (first 20% or last)
quickFileLen - a pointer to where to put the shorten array size
*/
int* stringToQuickStr(int* regularStr, int regularLen, int mode, int* quickFileLen)
{
    int i = 0, start = 0;
    *quickFileLen = (regularLen / 5);
    int* quickStr = (int*)malloc(sizeof(int) * (*quickFileLen));
    if (!(quickStr))
    {
        printf("quickStr calloc() ERROR!\n");
        return -1;
    }
    if (mode == FIRST_20)
    {
        for (i = 0; i < *quickFileLen; i++)
        {
            quickStr[i] = regularStr[i];
        }
    }
    return quickStr;
    free(quickStr);
}

the program was always crashing in the FIRST_20 copy after some copying.

Guy Shilman
  • 45
  • 12

0 Answers0