0

I can't seem to find a problem in my load and indexes function. I need help. Thank you!!

bool load(FILE* file, BYTE** content, size_t* length)
{
    *content = NULL;
    *length = 0;
    BYTE temp;

    while (fread(&temp, sizeof(BYTE), 1, file) == 1)
    {
        *length += 1;
        *content = realloc (*content, *length);
        memcpy(&content, &temp, 1);
    }

    return true;
}


char* indexes(const char* path)
{
    char* temp = NULL;
    char php[] = "/index.php";
    char html[] = "/index.html";

    temp = malloc(sizeof(strlen(path) + strlen(php)) + 1 - 2);

    strcpy(temp, path);
    strcat(temp, php);

    if (access(temp, F_OK))
        return temp;

    free(temp);

    temp = malloc(sizeof(strlen(path) + strlen(html)) + 1 - 2);

    strcpy(temp, path);
    strcat(temp, html);

    if (access(temp, F_OK))
        return temp;

    free(temp);

    return NULL;
}

1 Answer 1

1

Low hanging fruit (since you give no indication what problems you are experiencing).

indexes

Read the man page on access and pay special attention to the return value. Spoiler: it ain't a bool.

load

memcpy(&content, &temp, 1); is always copying temp into the first byte of content.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .