diff --git a/input/input_driver.c b/input/input_driver.c index 8a2f5944fd..cf86f54d7f 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -2318,7 +2318,10 @@ void input_config_parse_joy_button(void *data, const char *prefix, if (config_get_string(conf, key_label, &tmp_a)) { - strlcpy(bind->joykey_label, tmp_a, sizeof(bind->joykey_label)); + if (!string_is_empty(bind->joykey_label)) + free(bind->joykey_label); + + bind->joykey_label = strdup(tmp_a); free(tmp_a); } } @@ -2375,7 +2378,8 @@ static void input_config_get_bind_string_joykey( if (GET_HAT_DIR(bind->joykey)) { - if (!string_is_empty(bind->joykey_label) && label_show) + if (bind->joykey_label && + !string_is_empty(bind->joykey_label) && label_show) snprintf(buf, size, "%s %s ", prefix, bind->joykey_label); else { @@ -2405,7 +2409,8 @@ static void input_config_get_bind_string_joykey( } else { - if (!string_is_empty(bind->joykey_label) && label_show) + if (bind->joykey_label && + !string_is_empty(bind->joykey_label) && label_show) snprintf(buf, size, "%s%s (btn) ", prefix, bind->joykey_label); else snprintf(buf, size, "%s%u (%s) ", prefix, (unsigned)bind->joykey, diff --git a/input/input_driver.h b/input/input_driver.h index 111613ae02..0f99da1940 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -114,7 +114,7 @@ struct retro_keybind /* Used by input_{push,pop}_analog_dpad(). */ uint32_t orig_joyaxis; - char joykey_label[64]; + char *joykey_label; char joyaxis_label[64]; }; diff --git a/tasks/task_autodetect.c b/tasks/task_autodetect.c index d7c820c133..46c64e46a7 100644 --- a/tasks/task_autodetect.c +++ b/tasks/task_autodetect.c @@ -475,7 +475,10 @@ bool input_autoconfigure_connect( { input_autoconf_binds[state->idx][i].joykey = NO_BTN; input_autoconf_binds[state->idx][i].joyaxis = AXIS_NONE; - input_autoconf_binds[state->idx][i].joykey_label[0] = '\0'; + if (input_autoconf_binds[state->idx][i].joykey_label + && !string_is_empty(input_autoconf_binds[state->idx][i].joykey_label)) + free(input_autoconf_binds[state->idx][i].joykey_label); + input_autoconf_binds[state->idx][i].joykey_label = NULL; input_autoconf_binds[state->idx][i].joyaxis_label[0] = '\0'; }