I need help with load() in server.c. This is a follow-up to the other question, except now I'll post the updated code and make it a bit more specific.
When I tested the server after implemented lookup and parse (with abs_path and query), and had had done some stuff on load as well, I got this output:
Using /home/ubuntu/workspace/pset6/public for server's root
Listening on port 8080
GET / HTTP/1.1
HTTP/1.1 200 OK
GET /cat.html HTTP/1.1
server: malloc.c:2842: mremap_chunk: Assertion `((size + offset) & (_rtld_global_ro._dl_pagesize - 1)) == 0' failed.
Aborted
I tried to make some changes to my realloc call in load after that, and right now the function looks like this:
bool load(FILE* file, BYTE** content, size_t* length)
{
int c;
*length = 0;
while ((c = fgetc(file)) != EOF)
{
*content = realloc(*content, *length + 1);
if (*content == NULL)
{
exit(1);
}
*length++;
}
free(*content);
return true;
}
This also doesn't compile because the value of length
after length++
is unused (the main culprit being the -Werror compilation flag sent to Clang by make).
Any help would be appreciated, short of just giving me the answer of course.
By the way, how many bytes should I read with realloc? Is *length + 1
correct?