Commit c07ce2ac authored by Jamie A. Jennings's avatar Jamie A. Jennings

Invalid memory write in file.c fixed.

parent fd5aec13
......@@ -177,6 +177,7 @@ int file_save (const char *filename, Chunk *chunk) {
return FILE_OK;
}
/* TODO: fclose(in) before returning an error code */
int file_load (const char *filename, Chunk *chunk) {
FILE *in;
size_t len;
......@@ -215,11 +216,13 @@ int file_load (const char *filename, Chunk *chunk) {
kt->elements[1] = 0;
int next = 2;
for (size_t i = 0; i < kt->blocksize; i++)
for (size_t i = 0; i < kt->blocksize; i++) {
if (next > n) break;
if (kt->block[i] == '\0') {
kt->elements[next] = i + 1;
next++;
}
}
assert( (next - 1) == kt->next );
kt->blocknext = kt->blocksize;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment