0

Was wondering if anybody could take a look at my code and find any issues. I ran check50 after implementing lookup and parse, and I passed everything, so I am assuming the problem is in my load and/or indexes function. When I manually check my code with curl, I can request all the files in the public directory and receive a 200 OK response for each one. When I try to upload it to check50 to check50, it always stops uploading and gives an "unexpected end of input" error message. I fixed a couple bugs, but can't find any more that would cause this problem.

bool load(FILE* file, BYTE** content, size_t* length)
{
    int c;
    *length = 0;
    BYTE* buffer = malloc(1000 * sizeof(BYTE));
    if (buffer == NULL)
    {
        free(buffer);
        return false;
    }

    // read file char by char until end of file
    while ((c = fgetc(file)) != EOF)
    {

        // store char from file in buffer
        buffer[*length] = c;

        // increase length counter
        *length += 1;

        // reallocate memory if necessary
        if (*length % 1000 == 0)
        {
            buffer = realloc(buffer, (*length + 1000) * sizeof(BYTE));
            if (buffer == NULL)
            {
                free(buffer);
                return false;
            }
        }
    }

    // reallocate memory for exact amount needed
    buffer = realloc(buffer, *length * sizeof(BYTE));
    if (buffer == NULL)
    {
        free(buffer);
        return false;
    }

    *content = buffer;
    return true;
}

and here is my indexes function:

char* indexes(const char* path)
{

    // create strings to append to path
    char* php = "/index.php";
    char* html = "/index.html";

    // create memory for indexed path
    char* path_index = malloc(sizeof(path) + sizeof(html) + 1);

    if (path_index == NULL)
    {
        free(path_index);
        return NULL;
    }

    // concatonate path string and php index string
    strcpy(path_index, path);
    strcat(path_index, php);

    // return path if /index.php exists
    if (access(path_index, F_OK) == 0)
    {
        return path_index;
    }

    else
    {

        // concatonate path string and html index string
        strcpy(path_index, path);
        strcat(path_index, html);

        // return path if /index.html exists
        if (access(path_index, F_OK) == 0)
        {
            return path_index;
        }

        // return NULL if none exist
        else
            return NULL;
    }
}

EDIT:

Finally was able to upload to check50, got this back:

:) server.c exists

:) server compiles

:) Requesting cat.jpg returns 200, image/jpeg, and correct image

:) Requesting cat.html returns 200, text/html, and correct file

:) Requesting cat2.HTML returns 200, text/html, and correct file

:) Requesting cat3.HtMl returns 200, text/html, and correct file

:) Requesting cat.gif returns 200, image/gif, and correct file

:) Requesting favicon.ico returns 200, image/x-icon, and correct file

:) Requesting test.css returns 200, text/css, and correct file

:) Requesting test.js returns 200, text/javascript, and correct file

:) Requesting hello.php returns 200, text/html, and correct output

:( Requesting hello.php? returns 200, text/html, and correct output \ expected output, not an exit code of 0

:( Requesting hello.php?name=Alice returns 200, text/html, and correct output \ expected output, not an exit code of 0

:) Requesting /test redirects to /test/

:( Requesting /test/ outputs /test/index.html \ expected an exit code of 0, not standard error of "======= Backtrace: =========\n======= M..."

:( Requesting directory containing index.php outputs index.php \ expected output, not standard error of "======= Backtrace: =========\n======= M..."

:) Requesting two files in a row (cat.html then cat.jpg) succeeds

Can anybody point me in the right direction as to where to look in my code to fix these errors?

0

1 Answer 1

0

Suggest you sit on it for a day or two and start working on pset7 if you're done with 6. It looks like the servers are getting the same result with everything, even mario. :-( Just have to wait for staff to reset the servers.

You can always test to see if the servers are back up by trying to run check50 with one of the early pset programs. When it doesn't time out, then try rerunning for pset6.

2
  • Hey @Cliff_B, I don't know how to pm so I am posting here, can you please check my error on pset6, I am getting error in access() function but that is written by default. Please help [cs50.stackexchange.com/questions/18756/…
    – Salil Jain
    Commented Jun 30, 2016 at 16:58
  • Thanks @Cliff_B , didn't even think of that. I'll check back on the servers. Could have spent a couple days going crazy finding a bug that might not even be there!
    – Jon Savas
    Commented Jun 30, 2016 at 20:55

You must log in to answer this question.

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