@@ -834,7 +834,10 @@ intptr_t rg_gui_dialog(const char *title, const rg_gui_option_t *options_const,
834834
835835 // We create a copy of options because the callbacks might modify it (ie option->value)
836836 rg_gui_option_t options [options_count + 1 ];
837- char * text_buffer = calloc (options_count , 32 );
837+ // The text_buffer is used for mutable option->values. Because values tend to be small, we can make
838+ // some assumptions. This is a terrible system that is prone to corruption. But we're stuck with it.
839+ size_t text_buffer_size = RG_MAX (options_count * 32 , 1024 );
840+ char * text_buffer = malloc (text_buffer_size );
838841 char * text_buffer_ptr = text_buffer ;
839842
840843 memcpy (options , options_const , sizeof (options ));
@@ -844,11 +847,11 @@ intptr_t rg_gui_dialog(const char *title, const rg_gui_option_t *options_const,
844847 rg_gui_option_t * option = & options [i ];
845848 if (!option -> label )
846849 option -> label = "" ;
847- if (option -> value && text_buffer )
850+ if (option -> value && text_buffer_ptr )
848851 option -> value = strcpy (text_buffer_ptr , option -> value );
849852 if (option -> update_cb )
850853 option -> update_cb (option , RG_DIALOG_INIT );
851- if (option -> value && text_buffer )
854+ if (option -> value && text_buffer_ptr )
852855 text_buffer_ptr += RG_MAX (strlen (option -> value ), 31 ) + 1 ;
853856 }
854857
@@ -1896,7 +1899,7 @@ static rg_gui_event_t app_options_cb(rg_gui_option_t *option, rg_gui_event_t eve
18961899
18971900void rg_gui_options_menu (void )
18981901{
1899- rg_gui_option_t options [16 ] = {
1902+ rg_gui_option_t options [20 ] = {
19001903 #if RG_SCREEN_BACKLIGHT
19011904 {0 , _ ("Brightness" ), "-" , RG_DIALOG_FLAG_NORMAL , & brightness_update_cb },
19021905 #endif
0 commit comments