Okay, I think I'm having trouble understanding realloc. It seems to me that I've done things right, though I'm sure I'm missing a very obvious mistake. Here's the relevant part of my load function:
BYTE* buffer = malloc(sizeof(BYTE));
int count = 0;
for (BYTE c = fgetc(file); c != EOF; c = fgetc(file))
{
buffer[count] = c;
buffer = realloc(buffer, (sizeof(buffer) + sizeof(BYTE)));
if (buffer == NULL)
{
return false;
}
count++;
}
I originally tried using a second pointer, rather than count, but, of course, it would lose its place whenever buffer was realloc'ed. That change kept me from getting a bus error, but now I get this response:
GET / HTTP/1.1
HTTP/1.1 200 OK
GET /favicon.ico HTTP/1.1
*** Error in `./server': realloc(): invalid next size: 0x0000000001949990 ***