You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
fftools/cmdutils: add error handling to GROW_ARRAY()
This commit is contained in:
@@ -609,13 +609,17 @@ static int match_group_separator(const OptionGroupDef *groups, int nb_groups,
|
|||||||
* @param group_idx which group definition should this group belong to
|
* @param group_idx which group definition should this group belong to
|
||||||
* @param arg argument of the group delimiting option
|
* @param arg argument of the group delimiting option
|
||||||
*/
|
*/
|
||||||
static void finish_group(OptionParseContext *octx, int group_idx,
|
static int finish_group(OptionParseContext *octx, int group_idx,
|
||||||
const char *arg)
|
const char *arg)
|
||||||
{
|
{
|
||||||
OptionGroupList *l = &octx->groups[group_idx];
|
OptionGroupList *l = &octx->groups[group_idx];
|
||||||
OptionGroup *g;
|
OptionGroup *g;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = GROW_ARRAY(l->groups, l->nb_groups);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
GROW_ARRAY(l->groups, l->nb_groups);
|
|
||||||
g = &l->groups[l->nb_groups - 1];
|
g = &l->groups[l->nb_groups - 1];
|
||||||
|
|
||||||
*g = octx->cur_group;
|
*g = octx->cur_group;
|
||||||
@@ -632,21 +636,29 @@ static void finish_group(OptionParseContext *octx, int group_idx,
|
|||||||
swr_opts = NULL;
|
swr_opts = NULL;
|
||||||
|
|
||||||
memset(&octx->cur_group, 0, sizeof(octx->cur_group));
|
memset(&octx->cur_group, 0, sizeof(octx->cur_group));
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add an option instance to currently parsed group.
|
* Add an option instance to currently parsed group.
|
||||||
*/
|
*/
|
||||||
static void add_opt(OptionParseContext *octx, const OptionDef *opt,
|
static int add_opt(OptionParseContext *octx, const OptionDef *opt,
|
||||||
const char *key, const char *val)
|
const char *key, const char *val)
|
||||||
{
|
{
|
||||||
int global = !(opt->flags & (OPT_PERFILE | OPT_SPEC | OPT_OFFSET));
|
int global = !(opt->flags & (OPT_PERFILE | OPT_SPEC | OPT_OFFSET));
|
||||||
OptionGroup *g = global ? &octx->global_opts : &octx->cur_group;
|
OptionGroup *g = global ? &octx->global_opts : &octx->cur_group;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = GROW_ARRAY(g->opts, g->nb_opts);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
GROW_ARRAY(g->opts, g->nb_opts);
|
|
||||||
g->opts[g->nb_opts - 1].opt = opt;
|
g->opts[g->nb_opts - 1].opt = opt;
|
||||||
g->opts[g->nb_opts - 1].key = key;
|
g->opts[g->nb_opts - 1].key = key;
|
||||||
g->opts[g->nb_opts - 1].val = val;
|
g->opts[g->nb_opts - 1].val = val;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int init_parse_context(OptionParseContext *octx,
|
static int init_parse_context(OptionParseContext *octx,
|
||||||
@@ -726,7 +738,10 @@ int split_commandline(OptionParseContext *octx, int argc, char *argv[],
|
|||||||
}
|
}
|
||||||
/* unnamed group separators, e.g. output filename */
|
/* unnamed group separators, e.g. output filename */
|
||||||
if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) {
|
if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) {
|
||||||
finish_group(octx, 0, opt);
|
ret = finish_group(octx, 0, opt);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
av_log(NULL, AV_LOG_DEBUG, " matched as %s.\n", groups[0].name);
|
av_log(NULL, AV_LOG_DEBUG, " matched as %s.\n", groups[0].name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -744,7 +759,10 @@ do { \
|
|||||||
/* named group separators, e.g. -i */
|
/* named group separators, e.g. -i */
|
||||||
if ((ret = match_group_separator(groups, nb_groups, opt)) >= 0) {
|
if ((ret = match_group_separator(groups, nb_groups, opt)) >= 0) {
|
||||||
GET_ARG(arg);
|
GET_ARG(arg);
|
||||||
finish_group(octx, ret, arg);
|
ret = finish_group(octx, ret, arg);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
av_log(NULL, AV_LOG_DEBUG, " matched as %s with argument '%s'.\n",
|
av_log(NULL, AV_LOG_DEBUG, " matched as %s with argument '%s'.\n",
|
||||||
groups[ret].name, arg);
|
groups[ret].name, arg);
|
||||||
continue;
|
continue;
|
||||||
@@ -762,7 +780,10 @@ do { \
|
|||||||
arg = "1";
|
arg = "1";
|
||||||
}
|
}
|
||||||
|
|
||||||
add_opt(octx, po, opt, arg);
|
ret = add_opt(octx, po, opt, arg);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
|
av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
|
||||||
"argument '%s'.\n", po->name, po->help, arg);
|
"argument '%s'.\n", po->name, po->help, arg);
|
||||||
continue;
|
continue;
|
||||||
@@ -787,7 +808,10 @@ do { \
|
|||||||
if (opt[0] == 'n' && opt[1] == 'o' &&
|
if (opt[0] == 'n' && opt[1] == 'o' &&
|
||||||
(po = find_option(options, opt + 2)) &&
|
(po = find_option(options, opt + 2)) &&
|
||||||
po->name && po->flags & OPT_BOOL) {
|
po->name && po->flags & OPT_BOOL) {
|
||||||
add_opt(octx, po, opt, "0");
|
ret = add_opt(octx, po, opt, "0");
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
|
av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
|
||||||
"argument 0.\n", po->name, po->help);
|
"argument 0.\n", po->name, po->help);
|
||||||
continue;
|
continue;
|
||||||
|
@@ -440,11 +440,7 @@ int grow_array(void **array, int elem_size, int *size, int new_size);
|
|||||||
void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems);
|
void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems);
|
||||||
|
|
||||||
#define GROW_ARRAY(array, nb_elems)\
|
#define GROW_ARRAY(array, nb_elems)\
|
||||||
do { \
|
grow_array((void**)&array, sizeof(*array), &nb_elems, nb_elems + 1)
|
||||||
int _ret = grow_array((void**)&array, sizeof(*array), &nb_elems, nb_elems + 1); \
|
|
||||||
if (_ret < 0) \
|
|
||||||
report_and_exit(_ret); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define GET_PIX_FMT_NAME(pix_fmt)\
|
#define GET_PIX_FMT_NAME(pix_fmt)\
|
||||||
const char *name = av_get_pix_fmt_name(pix_fmt);
|
const char *name = av_get_pix_fmt_name(pix_fmt);
|
||||||
|
@@ -880,7 +880,10 @@ int ist_output_add(InputStream *ist, OutputStream *ost)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
GROW_ARRAY(ist->outputs, ist->nb_outputs);
|
ret = GROW_ARRAY(ist->outputs, ist->nb_outputs);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
ist->outputs[ist->nb_outputs - 1] = ost;
|
ist->outputs[ist->nb_outputs - 1] = ost;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -894,7 +897,10 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
GROW_ARRAY(ist->filters, ist->nb_filters);
|
ret = GROW_ARRAY(ist->filters, ist->nb_filters);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
ist->filters[ist->nb_filters - 1] = ifilter;
|
ist->filters[ist->nb_filters - 1] = ifilter;
|
||||||
|
|
||||||
// initialize fallback parameters for filtering
|
// initialize fallback parameters for filtering
|
||||||
|
@@ -208,7 +208,9 @@ static int enc_stats_get_file(AVIOContext **io, const char *path)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GROW_ARRAY(enc_stats_files, nb_enc_stats_files);
|
ret = GROW_ARRAY(enc_stats_files, nb_enc_stats_files);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
esf = &enc_stats_files[nb_enc_stats_files - 1];
|
esf = &enc_stats_files[nb_enc_stats_files - 1];
|
||||||
|
|
||||||
@@ -320,7 +322,11 @@ static int enc_stats_init(OutputStream *ost, EncStats *es, int pre,
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (val) {
|
if (val) {
|
||||||
GROW_ARRAY(es->components, es->nb_components);
|
ret = GROW_ARRAY(es->components, es->nb_components);
|
||||||
|
if (ret < 0) {
|
||||||
|
av_freep(&val);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
c = &es->components[es->nb_components - 1];
|
c = &es->components[es->nb_components - 1];
|
||||||
c->type = ENC_STATS_LITERAL;
|
c->type = ENC_STATS_LITERAL;
|
||||||
@@ -351,7 +357,10 @@ static int enc_stats_init(OutputStream *ost, EncStats *es, int pre,
|
|||||||
}
|
}
|
||||||
next++;
|
next++;
|
||||||
|
|
||||||
GROW_ARRAY(es->components, es->nb_components);
|
ret = GROW_ARRAY(es->components, es->nb_components);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
c = &es->components[es->nb_components - 1];
|
c = &es->components[es->nb_components - 1];
|
||||||
|
|
||||||
for (size_t i = 0; i < FF_ARRAY_ELEMS(fmt_specs); i++) {
|
for (size_t i = 0; i < FF_ARRAY_ELEMS(fmt_specs); i++) {
|
||||||
|
@@ -361,6 +361,7 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
|
|||||||
OptionsContext *o = optctx;
|
OptionsContext *o = optctx;
|
||||||
StreamMap *m = NULL;
|
StreamMap *m = NULL;
|
||||||
int i, negative = 0, file_idx, disabled = 0;
|
int i, negative = 0, file_idx, disabled = 0;
|
||||||
|
int ret;
|
||||||
#if FFMPEG_OPT_MAP_SYNC
|
#if FFMPEG_OPT_MAP_SYNC
|
||||||
char *sync;
|
char *sync;
|
||||||
#endif
|
#endif
|
||||||
@@ -387,7 +388,11 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
|
|||||||
if (map[0] == '[') {
|
if (map[0] == '[') {
|
||||||
/* this mapping refers to lavfi output */
|
/* this mapping refers to lavfi output */
|
||||||
const char *c = map + 1;
|
const char *c = map + 1;
|
||||||
GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
|
|
||||||
|
ret = GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
m = &o->stream_maps[o->nb_stream_maps - 1];
|
m = &o->stream_maps[o->nb_stream_maps - 1];
|
||||||
m->linklabel = av_get_token(&c, "]");
|
m->linklabel = av_get_token(&c, "]");
|
||||||
if (!m->linklabel) {
|
if (!m->linklabel) {
|
||||||
@@ -421,7 +426,10 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
|
|||||||
disabled = 1;
|
disabled = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
|
ret = GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
m = &o->stream_maps[o->nb_stream_maps - 1];
|
m = &o->stream_maps[o->nb_stream_maps - 1];
|
||||||
|
|
||||||
m->file_index = file_idx;
|
m->file_index = file_idx;
|
||||||
@@ -450,7 +458,10 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
|
|||||||
static int opt_attach(void *optctx, const char *opt, const char *arg)
|
static int opt_attach(void *optctx, const char *opt, const char *arg)
|
||||||
{
|
{
|
||||||
OptionsContext *o = optctx;
|
OptionsContext *o = optctx;
|
||||||
GROW_ARRAY(o->attachments, o->nb_attachments);
|
int ret = GROW_ARRAY(o->attachments, o->nb_attachments);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
o->attachments[o->nb_attachments - 1] = arg;
|
o->attachments[o->nb_attachments - 1] = arg;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -459,7 +470,7 @@ static int opt_attach(void *optctx, const char *opt, const char *arg)
|
|||||||
static int opt_map_channel(void *optctx, const char *opt, const char *arg)
|
static int opt_map_channel(void *optctx, const char *opt, const char *arg)
|
||||||
{
|
{
|
||||||
OptionsContext *o = optctx;
|
OptionsContext *o = optctx;
|
||||||
int n;
|
int n, ret;
|
||||||
AVStream *st;
|
AVStream *st;
|
||||||
AudioChannelMap *m;
|
AudioChannelMap *m;
|
||||||
char *allow_unused;
|
char *allow_unused;
|
||||||
@@ -474,7 +485,10 @@ static int opt_map_channel(void *optctx, const char *opt, const char *arg)
|
|||||||
if (!mapchan)
|
if (!mapchan)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
GROW_ARRAY(o->audio_channel_maps, o->nb_audio_channel_maps);
|
ret = GROW_ARRAY(o->audio_channel_maps, o->nb_audio_channel_maps);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
m = &o->audio_channel_maps[o->nb_audio_channel_maps - 1];
|
m = &o->audio_channel_maps[o->nb_audio_channel_maps - 1];
|
||||||
|
|
||||||
/* muted channel syntax */
|
/* muted channel syntax */
|
||||||
|
@@ -388,7 +388,10 @@ static const struct TextureFormatEntry {
|
|||||||
|
|
||||||
static int opt_add_vfilter(void *optctx, const char *opt, const char *arg)
|
static int opt_add_vfilter(void *optctx, const char *opt, const char *arg)
|
||||||
{
|
{
|
||||||
GROW_ARRAY(vfilters_list, nb_vfilters);
|
int ret = GROW_ARRAY(vfilters_list, nb_vfilters);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
vfilters_list[nb_vfilters - 1] = arg;
|
vfilters_list[nb_vfilters - 1] = arg;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user