summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-01-10 01:20:58 +0100
committerKevin Mitchell <kevmitch@gmail.com>2018-01-10 20:36:27 -0800
commit2d345c59d637ec12fbc39d97e1999c335dffcdd2 (patch)
treeec8281b2e0ccec14739827e28153f73b22fd26ed /player
parente3bee23fe4e0dc15ea2564b684572572f2393a15 (diff)
downloadmpv-2d345c59d637ec12fbc39d97e1999c335dffcdd2.tar.bz2
mpv-2d345c59d637ec12fbc39d97e1999c335dffcdd2.tar.xz
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).
Diffstat (limited to 'player')
-rw-r--r--player/command.c11
1 files changed, 8 insertions, 3 deletions
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;
}