Skip to content

Commit

Permalink
finalize: fix using pointers incorrectly, meaning only one title woul…
Browse files Browse the repository at this point in the history
…d work
  • Loading branch information
ihaveamac committed May 23, 2020
1 parent 167a80f commit a515ca7
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions finalize/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ int load_cifinish(char* path, struct finish_db_entry_final **entries)
struct finish_db_entry_v2 v2;
struct finish_db_entry_v3 v3;

struct finish_db_entry_final *tmp;

int i;
size_t read;

Expand Down Expand Up @@ -114,6 +116,12 @@ int load_cifinish(char* path, struct finish_db_entry_final **entries)
}

*entries = calloc(header.title_count, sizeof(struct finish_db_entry_final));
if (!*entries) {
printf("Couldn't allocate memory.\n");
printf("This should never happen.\n");
goto fail;
}
tmp = *entries;

if (header.version == 1)
{
Expand All @@ -133,9 +141,9 @@ int load_cifinish(char* path, struct finish_db_entry_final **entries)
printf(" Is the file corrupt?\n");
goto fail;
}
entries[i]->has_seed = v1.has_seed;
entries[i]->title_id = v1.title_id;
memcpy(entries[i]->seed, v1.seed, 16);
tmp[i].has_seed = v1.has_seed;
tmp[i].title_id = v1.title_id;
memcpy(tmp[i].seed, v1.seed, 16);
}
} else if (header.version == 2) {
for (i = 0; i < header.title_count; i++)
Expand All @@ -154,9 +162,9 @@ int load_cifinish(char* path, struct finish_db_entry_final **entries)
printf(" Is the file corrupt?\n");
goto fail;
}
entries[i]->has_seed = v2.has_seed;
entries[i]->title_id = v2.title_id;
memcpy(entries[i]->seed, v2.seed, 16);
tmp[i].has_seed = v2.has_seed;
tmp[i].title_id = v2.title_id;
memcpy(tmp[i].seed, v2.seed, 16);
}
} else if (header.version == 3) {
for (i = 0; i < header.title_count; i++)
Expand All @@ -175,9 +183,9 @@ int load_cifinish(char* path, struct finish_db_entry_final **entries)
printf(" Is the file corrupt?\n");
goto fail;
}
entries[i]->has_seed = v3.has_seed;
entries[i]->title_id = v3.title_id;
memcpy(entries[i]->seed, v3.seed, 16);
tmp[i].has_seed = v3.has_seed;
tmp[i].title_id = v3.title_id;
memcpy(tmp[i].seed, v3.seed, 16);
}
}

Expand Down Expand Up @@ -267,7 +275,7 @@ int main(int argc, char* argv[])
gfxInitDefault();
consoleInit(GFX_TOP, NULL);

printf("custom-install-finalize v1.3\n");
printf("custom-install-finalize v1.4\n");

finalize_install();
// print this at the end in case it gets pushed off the screen
Expand Down

0 comments on commit a515ca7

Please sign in to comment.