ref: 5e064562c09ceb5b93a4ddafe734cdb6c7b081c6
parent: 6357ef2d6e960cd3cbed76405711e058df679dbf
author: Fabian Greffrath <[email protected]>
date: Tue Oct 28 02:27:33 EDT 2014
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.
--- a/src/setup/multiplayer.c
+++ b/src/setup/multiplayer.c
@@ -55,7 +55,7 @@
// 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,8 +559,14 @@
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