diff options
author | Anton Khirnov <anton@khirnov.net> | 2023-07-14 17:19:28 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2023-07-20 20:47:46 +0200 |
commit | 87f0333af1810047fcd592f680c8d0a596bca7f6 (patch) | |
tree | de392224528d1e5c522dcb0c3fb88fe11c5decbf /fftools/cmdutils.c | |
parent | 6b8cf2505ab613fd365c276ed374caccb559f507 (diff) | |
download | ffmpeg-87f0333af1810047fcd592f680c8d0a596bca7f6.tar.gz |
fftools/cmdutils: add error handling to filter_codec_opts()
Diffstat (limited to 'fftools/cmdutils.c')
-rw-r--r-- | fftools/cmdutils.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index fa2797ebba..c2a783a983 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -943,8 +943,9 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec) return ret; } -AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id, - AVFormatContext *s, AVStream *st, const AVCodec *codec) +int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id, + AVFormatContext *s, AVStream *st, const AVCodec *codec, + AVDictionary **dst) { AVDictionary *ret = NULL; const AVDictionaryEntry *t = NULL; @@ -977,12 +978,16 @@ AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_i char *p = strchr(t->key, ':'); /* check stream specification in opt name */ - if (p) - switch (check_stream_specifier(s, st, p + 1)) { - case 1: *p = 0; break; - case 0: continue; - default: exit_program(1); - } + if (p) { + int err = check_stream_specifier(s, st, p + 1); + if (err < 0) { + av_dict_free(&ret); + return err; + } else if (!err) + continue; + + *p = 0; + } if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) || !codec || @@ -998,14 +1003,16 @@ AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_i if (p) *p = ':'; } - return ret; + + *dst = ret; + return 0; } int setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts, AVDictionary ***dst) { - int i; + int ret; AVDictionary **opts; *dst = NULL; @@ -1017,11 +1024,19 @@ int setup_find_stream_info_opts(AVFormatContext *s, if (!opts) return AVERROR(ENOMEM); - for (i = 0; i < s->nb_streams; i++) - opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id, - s, s->streams[i], NULL); + for (int i = 0; i < s->nb_streams; i++) { + ret = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id, + s, s->streams[i], NULL, &opts[i]); + if (ret < 0) + goto fail; + } *dst = opts; return 0; +fail: + for (int i = 0; i < s->nb_streams; i++) + av_dict_free(&opts[i]); + av_freep(&opts); + return ret; } int grow_array(void **array, int elem_size, int *size, int new_size) |