mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 01:59:43 +01:00
Fix possible dangling pointers in FontContainer.map_name_idx
The hashmap would get populated with the name of each font, as each font was being added. Unfortunately, adding a font would also realloc the storage for fonts, in which the names are also stored... Possibly invalidating the pointers to the names. This is now fixed by populating the hashmap after all the fonts are added.
This commit is contained in:
parent
04743abe91
commit
faff8bba5f
1 changed files with 15 additions and 6 deletions
|
@ -286,12 +286,6 @@ static uint8_t load_font(FontContainer* container, const char* name)
|
||||||
f->fallback_key[0] = '\0';
|
f->fallback_key[0] = '\0';
|
||||||
f->fallback_idx_valid = false;
|
f->fallback_idx_valid = false;
|
||||||
|
|
||||||
if (container->map_name_idx == NULL)
|
|
||||||
{
|
|
||||||
container->map_name_idx = hashmap_create();
|
|
||||||
}
|
|
||||||
hashmap_set(container->map_name_idx, f->name, SDL_strlen(f->name), f_idx);
|
|
||||||
|
|
||||||
bool white_teeth = false;
|
bool white_teeth = false;
|
||||||
|
|
||||||
tinyxml2::XMLDocument doc;
|
tinyxml2::XMLDocument doc;
|
||||||
|
@ -555,6 +549,19 @@ void set_level_font_new(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void fill_map_name_idx(FontContainer* container)
|
||||||
|
{
|
||||||
|
/* Initialize the name->idx hashmap for the fonts in this container.
|
||||||
|
* This should only be done once, after all the fonts are added. */
|
||||||
|
container->map_name_idx = hashmap_create();
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < container->count; i++)
|
||||||
|
{
|
||||||
|
Font* f = &container->fonts[i];
|
||||||
|
hashmap_set(container->map_name_idx, f->name, SDL_strlen(f->name), i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void set_fallbacks(FontContainer* container)
|
static void set_fallbacks(FontContainer* container)
|
||||||
{
|
{
|
||||||
/* Initialize the value of fallback_idx for all fonts in this container.
|
/* Initialize the value of fallback_idx for all fonts in this container.
|
||||||
|
@ -609,6 +616,7 @@ void load_main(void)
|
||||||
FILESYSTEM_freeEnumerate(&handle);
|
FILESYSTEM_freeEnumerate(&handle);
|
||||||
font_idx_level = font_idx_8x8;
|
font_idx_level = font_idx_8x8;
|
||||||
|
|
||||||
|
fill_map_name_idx(&fonts_main);
|
||||||
set_fallbacks(&fonts_main);
|
set_fallbacks(&fonts_main);
|
||||||
|
|
||||||
// Initialize the font menu options, 8x8 font first
|
// Initialize the font menu options, 8x8 font first
|
||||||
|
@ -645,6 +653,7 @@ void load_custom(const char* name)
|
||||||
}
|
}
|
||||||
FILESYSTEM_freeEnumerate(&handle);
|
FILESYSTEM_freeEnumerate(&handle);
|
||||||
|
|
||||||
|
fill_map_name_idx(&fonts_custom);
|
||||||
set_fallbacks(&fonts_custom);
|
set_fallbacks(&fonts_custom);
|
||||||
|
|
||||||
set_level_font(name);
|
set_level_font(name);
|
||||||
|
|
Loading…
Reference in a new issue