From 2d345c59d637ec12fbc39d97e1999c335dffcdd2 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 10 Jan 2018 01:20:58 +0100 Subject: input: make command argument list a dynamic array Replace the static array with dynamic memory allocation. This also requires some code to honor mp_cmd.nargs more strictly. Generally allocates more stuff. Fixes #5375 (although we could also just raise the static limit). --- player/command.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'player') diff --git a/player/command.c b/player/command.c index 006f557eb8..2496b396ff 100644 --- a/player/command.c +++ b/player/command.c @@ -4991,7 +4991,7 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re } case MP_CMD_CYCLE_VALUES: { - char *args[MP_CMD_MAX_ARGS + 1] = {0}; + char **args = talloc_zero_array(NULL, char *, cmd->nargs + 1); for (int n = 0; n < cmd->nargs; n++) args[n] = cmd->args[n].v.s; int first = 1, dir = 1; @@ -5015,14 +5015,17 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re } else if (r == M_PROPERTY_UNKNOWN) { set_osd_msg(mpctx, osdl, osd_duration, "Unknown property: '%s'", property); + talloc_free(args); return -1; } else if (r <= 0) { set_osd_msg(mpctx, osdl, osd_duration, "Failed to set property '%s' to '%s'", property, value); + talloc_free(args); return -1; } } + talloc_free(args); break; } @@ -5390,10 +5393,11 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re } case MP_CMD_RUN: { - char *args[MP_CMD_MAX_ARGS + 1] = {0}; + char **args = talloc_zero_array(NULL, char *, cmd->nargs + 1); for (int n = 0; n < cmd->nargs; n++) args[n] = cmd->args[n].v.s; mp_subprocess_detached(mpctx->log, args); + talloc_free(args); break; } @@ -5510,11 +5514,12 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re break; } case MP_CMD_SCRIPT_MESSAGE: { - const char *args[MP_CMD_MAX_ARGS]; + const char **args = talloc_array(NULL, const char *, cmd->nargs); mpv_event_client_message event = {.args = args}; for (int n = 0; n < cmd->nargs; n++) event.args[event.num_args++] = cmd->args[n].v.s; mp_client_broadcast_event(mpctx, MPV_EVENT_CLIENT_MESSAGE, &event); + talloc_free(args); break; } -- cgit v1.2.3