diff options
author | Fabian Greffrath | 2014-10-28 06:27:33 +0100 |
---|---|---|
committer | Fabian Greffrath | 2014-10-28 06:36:20 +0100 |
commit | 5e064562c09ceb5b93a4ddafe734cdb6c7b081c6 (patch) | |
tree | 227879415232558cccfb7363d8d8bfb9c0940473 | |
parent | 6357ef2d6e960cd3cbed76405711e058df679dbf (diff) | |
download | chocolate-doom-5e064562c09ceb5b93a4ddafe734cdb6c7b081c6.tar.gz chocolate-doom-5e064562c09ceb5b93a4ddafe734cdb6c7b081c6.tar.bz2 chocolate-doom-5e064562c09ceb5b93a4ddafe734cdb6c7b081c6.zip |
setup: dynamically set size of iwad_labels array
With the addition of the Freedoom IWADs, the number of IWADs supported
by chocolate-doom has been raised to 10. However, the iwad_labels[]
array only holds place for up to 8 pointers. Incidently, I have all 10
IWADs installed and trying to warp into a game from
chocolate-doom-setup leads to an out-of-bounds access of this array
and so the application crashes with a segmentation fault.
Instead of increasing the array size to 10, which will bite us next
time, I decided to set its size dynamically as soon as the number of
IWADs of known.
-rw-r--r-- | src/setup/multiplayer.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/setup/multiplayer.c b/src/setup/multiplayer.c index f116ffb2..8c8fe0c5 100644 --- a/src/setup/multiplayer.c +++ b/src/setup/multiplayer.c @@ -55,7 +55,7 @@ static const iwad_t fallback_iwads[] = { // Array of IWADs found to be installed static const iwad_t **found_iwads; -static char *iwad_labels[8]; +static char **iwad_labels; // Index of the currently selected IWAD @@ -559,10 +559,16 @@ static txt_widget_t *IWADSelector(void) for (i=0; found_iwads[i] != NULL; ++i) { - iwad_labels[i] = found_iwads[i]->description; ++num_iwads; } + iwad_labels = malloc(sizeof(*iwad_labels) * num_iwads); + + for (i=0; i < num_iwads; ++i) + { + iwad_labels[i] = found_iwads[i]->description; + } + // If no IWADs are found, provide Doom 2 as an option, but // we're probably screwed. |