It looks like the load function in q16858 is a copy (except for the correction!) of the load function in q16598. I marked it as a "possible duplicate". I couldn't find any guidance or reporting mechanism here on stack or on reddit or in the courseware. Is there any formal procedure? I am perfectly willing to be wrong. And maybe it's innocent, but it is not coincidence. It quacks.
pset6 load() from 16858
bool load(FILE* file, BYTE** content, size_t* length)
{
// TODO
// allocate memory on the heap
char* file_content = malloc(sizeof(char)*1000);
if (file_content == NULL)
{
return false;
}
int i = 0;
for (int c = fgetc(file); c != EOF; c = fgetc(file))
{
if (i % 1000 == 0)
{
file_content = realloc(file_content, sizeof(char)*(1000 + i));
}
file_content[i] = c;
i++;
}
// add terminating string and increase the size by one
i++;
// stores the address of the first byte of file contant in heap
*content = file_content;
*length = i;
return true;
}
pset6 load() from 16598
bool load(FILE* file, BYTE** content, size_t* length)
{
// allocate memory on the heap
char* file_content = malloc(sizeof(char)*1000);
if (file_content == NULL)
{
return false;
}
int i = 0;
for (int c = fgetc(file); c != EOF; c = fgetc(file))
{
if (i % 1000 == 0)
{
file_content = realloc(file_content, sizeof(char)*(1000 + i));
}
file_content[i] = c;
i++;
}
// add terminating string and increase the size by one
file_content[i] = '\0';
i++;
// stores the address of the first byte of file contant in heap
*content = file_content;
*length = i;
return true;
}
The difference is here (from orginal)
// add terminating string and increase the size by one
file_content[i] = '\0';
i++;
That's where the bug was identified. Further, poster had posted load() earlier in q16845.