Skip to content

Commit d5ba790

Browse files
committed
Reduce stack usage in command.c
by using PATH_MAX_LENGTH to define the length of buffers that store paths.
1 parent 5adaaf7 commit d5ba790

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

command.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -743,13 +743,12 @@ bool command_show_osd_msg(command_t *cmd, const char* arg)
743743

744744
bool command_load_state_slot(command_t *cmd, const char *arg)
745745
{
746-
char state_path[16384];
746+
char state_path[PATH_MAX_LENGTH] = "";
747747
size_t _len = 0;
748748
char reply[128] = "";
749749
unsigned int slot = (unsigned int)strtoul(arg, NULL, 10);
750750
bool savestates_enabled = core_info_current_supports_savestate();
751751
bool ret = false;
752-
state_path[0] = '\0';
753752
_len = strlcpy(reply, "LOAD_STATE_SLOT ", sizeof(reply));
754753
_len += snprintf(reply + _len, sizeof(reply) - _len, "%d", slot);
755754
if (savestates_enabled)
@@ -1362,7 +1361,7 @@ void command_event_init_cheats(
13621361

13631362
bool command_event_load_entry_state(settings_t *settings)
13641363
{
1365-
char entry_state_path[PATH_MAX_LENGTH];
1364+
char entry_state_path[PATH_MAX_LENGTH] = "";
13661365
int entry_path_stats;
13671366
runloop_state_t *runloop_st = runloop_state_get_ptr();
13681367
bool ret = false;
@@ -1379,8 +1378,6 @@ bool command_event_load_entry_state(settings_t *settings)
13791378
return false;
13801379
#endif
13811380

1382-
entry_state_path[0] = '\0';
1383-
13841381
if (!runloop_get_entry_state_path(
13851382
entry_state_path, sizeof(entry_state_path),
13861383
runloop_st->entry_state_slot))
@@ -2112,15 +2109,13 @@ void command_event_remove_current_config(enum override_type type)
21122109

21132110
bool command_event_main_state(unsigned cmd)
21142111
{
2115-
char msg[128];
2116-
char state_path[16384]; /* TODO/FIXME - reduce this */
2112+
char msg[128] = "";
2113+
char state_path[PATH_MAX_LENGTH] = "";
21172114
size_t _len = 0;
21182115
settings_t *settings = config_get_ptr();
21192116
bool savestates_enabled = core_info_current_supports_savestate();
21202117
bool ret = false;
21212118

2122-
state_path[0] = msg[0] = '\0';
2123-
21242119
if (savestates_enabled)
21252120
{
21262121
size_t info_size;

0 commit comments

Comments
 (0)