avconv.c:1971: error: Buffer Overrun L3
  Offset: [-1, +oo] Size: [0, 2147483631] by call to `av_dict_set`.

avconv.c:1970:17: Call
1968.             }
1969.             if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0))
1970.                 av_dict_set(&ost->encoder_opts, "threads", "auto", 0);
                      ^
1971.             av_dict_set(&ost->encoder_opts, "side_data_only_packets", "1", 0);
1972. 

libavutil/dict.c:68:1: Parameter `*value`
  66. }
  67. 
  68. int av_dict_set(AVDictionary **pm, const char *key, const char *value,
      ^
  69.                 int flags)
  70. {

libavutil/dict.c:109:13: Assignment
  107.             m->elems[m->count].key = av_strdup(key);
  108.         if (flags & AV_DICT_DONT_STRDUP_VAL) {
  109.             m->elems[m->count].value = value;
                   ^
  110.         } else if (oldval && flags & AV_DICT_APPEND) {
  111.             int len = strlen(oldval) + strlen(value) + 1;

avconv.c:1971:13: Call
1969.             if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0))
1970.                 av_dict_set(&ost->encoder_opts, "threads", "auto", 0);
1971.             av_dict_set(&ost->encoder_opts, "side_data_only_packets", "1", 0);
                  ^
1972. 
1973.             if ((ret = avcodec_open2(ost->enc_ctx, codec, &ost->encoder_opts)) < 0) {

libavutil/dict.c:68:1: <Offset trace>
66. }
67. 
68. int av_dict_set(AVDictionary **pm, const char *key, const char *value,
    ^
69.                 int flags)
70. {

libavutil/dict.c:68:1: Parameter `(*pm)->count`
  66. }
  67. 
  68. int av_dict_set(AVDictionary **pm, const char *key, const char *value,
      ^
  69.                 int flags)
  70. {

libavutil/dict.c:72:30: Call
  70. {
  71.     AVDictionary *m = *pm;
  72.     AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);
                                   ^
  73.     char *oldval = NULL;
  74.     int allocated = !!m;

libavutil/dict.c:38:1: Parameter `m->count`
    36. }
    37. 
    38. AVDictionaryEntry *av_dict_get(const AVDictionary *m, const char *key,
        ^
    39.                                const AVDictionaryEntry *prev, int flags)
    40. {

libavutil/dict.c:68:1: <Length trace>
66. }
67. 
68. int av_dict_set(AVDictionary **pm, const char *key, const char *value,
    ^
69.                 int flags)
70. {

libavutil/dict.c:68:1: Parameter `*(*pm)->elems`
  66. }
  67. 
  68. int av_dict_set(AVDictionary **pm, const char *key, const char *value,
      ^
  69.                 int flags)
  70. {

libavutil/dict.c:105:13: Array access: Offset: [-1, +oo] Size: [0, 2147483631] by call to `av_dict_set` 
  103.     if (value) {
  104.         if (flags & AV_DICT_DONT_STRDUP_KEY)
  105.             m->elems[m->count].key = key;
                   ^
  106.         else
  107.             m->elems[m->count].key = av_strdup(key);

int av_dict_set(AVDictionary **pm, const char *key, const char *value,
                int flags)
{
    AVDictionary *m = *pm;
    AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);
    char *oldval = NULL;
    int allocated = !!m;
    if (!m)
        m = *pm = av_mallocz(sizeof(*m));
    if (!m)
        return AVERROR(ENOMEM);
    if (tag) {
        if (flags & AV_DICT_DONT_OVERWRITE) {
            if (flags & AV_DICT_DONT_STRDUP_KEY) av_free(key);
            if (flags & AV_DICT_DONT_STRDUP_VAL) av_free(value);
            return 0;
        }
        if (flags & AV_DICT_APPEND)
            oldval = tag->value;
        else
            av_free(tag->value);
        av_free(tag->key);
        *tag = m->elems[--m->count];
    } else {
        int ret = av_reallocp_array(&m->elems,
                                    m->count + 1, sizeof(*m->elems));
        if (ret < 0) {
            if (allocated)
                av_freep(pm);
            return ret;
        }
    }
    if (value) {
        if (flags & AV_DICT_DONT_STRDUP_KEY)
            m->elems[m->count].key = key;
        else
            m->elems[m->count].key = av_strdup(key);
        if (flags & AV_DICT_DONT_STRDUP_VAL) {
            m->elems[m->count].value = value;
        } else if (oldval && flags & AV_DICT_APPEND) {
            int len = strlen(oldval) + strlen(value) + 1;
            if (!(oldval = av_realloc(oldval, len)))
                return AVERROR(ENOMEM);
            av_strlcat(oldval, value, len);
            m->elems[m->count].value = oldval;
        } else
            m->elems[m->count].value = av_strdup(value);
        m->count++;
    }
    if (!m->count) {
        av_free(m->elems);
        av_freep(pm);
    }
    return 0;
}
['static int transcode_init(void)\n{\n    int ret = 0, i, j, k;\n    AVFormatContext *oc;\n    OutputStream *ost;\n    InputStream *ist;\n    char error[1024];\n    int want_sdp = 1;\n    for (i = 0; i < nb_input_files; i++) {\n        InputFile *ifile = input_files[i];\n        if (ifile->rate_emu)\n            for (j = 0; j < ifile->nb_streams; j++)\n                input_streams[j + ifile->ist_index]->start = av_gettime_relative();\n    }\n    for (i = 0; i < nb_output_files; i++) {\n        oc = output_files[i]->ctx;\n        if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {\n            av_dump_format(oc, i, oc->filename, 1);\n            av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\\n", i);\n            return AVERROR(EINVAL);\n        }\n    }\n    for (i = 0; i < nb_filtergraphs; i++)\n        if ((ret = avfilter_graph_config(filtergraphs[i]->graph, NULL)) < 0)\n            return ret;\n    for (i = 0; i < nb_output_streams; i++) {\n        AVCodecContext *enc_ctx;\n        AVCodecContext *dec_ctx = NULL;\n        ost = output_streams[i];\n        oc  = output_files[ost->file_index]->ctx;\n        ist = get_input_stream(ost);\n        if (ost->attachment_filename)\n            continue;\n        enc_ctx = ost->enc_ctx;\n        if (ist) {\n            dec_ctx = ist->dec_ctx;\n            ost->st->disposition          = ist->st->disposition;\n            enc_ctx->bits_per_raw_sample    = dec_ctx->bits_per_raw_sample;\n            enc_ctx->chroma_sample_location = dec_ctx->chroma_sample_location;\n        }\n        if (ost->stream_copy) {\n            AVRational sar;\n            uint64_t extra_size;\n            av_assert0(ist && !ost->filter);\n            extra_size = (uint64_t)dec_ctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE;\n            if (extra_size > INT_MAX) {\n                return AVERROR(EINVAL);\n            }\n            enc_ctx->codec_id   = dec_ctx->codec_id;\n            enc_ctx->codec_type = dec_ctx->codec_type;\n            if (!enc_ctx->codec_tag) {\n                if (!oc->oformat->codec_tag ||\n                     av_codec_get_id (oc->oformat->codec_tag, dec_ctx->codec_tag) == enc_ctx->codec_id ||\n                     av_codec_get_tag(oc->oformat->codec_tag, dec_ctx->codec_id) <= 0)\n                    enc_ctx->codec_tag = dec_ctx->codec_tag;\n            }\n            enc_ctx->bit_rate       = dec_ctx->bit_rate;\n            enc_ctx->rc_max_rate    = dec_ctx->rc_max_rate;\n            enc_ctx->rc_buffer_size = dec_ctx->rc_buffer_size;\n            enc_ctx->field_order    = dec_ctx->field_order;\n            enc_ctx->extradata      = av_mallocz(extra_size);\n            if (!enc_ctx->extradata) {\n                return AVERROR(ENOMEM);\n            }\n            memcpy(enc_ctx->extradata, dec_ctx->extradata, dec_ctx->extradata_size);\n            enc_ctx->extradata_size = dec_ctx->extradata_size;\n            if (!copy_tb) {\n                enc_ctx->time_base      = dec_ctx->time_base;\n                enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;\n                av_reduce(&enc_ctx->time_base.num, &enc_ctx->time_base.den,\n                          enc_ctx->time_base.num, enc_ctx->time_base.den, INT_MAX);\n            } else\n                enc_ctx->time_base = ist->st->time_base;\n            if (ist->st->nb_side_data) {\n                ost->st->side_data = av_realloc_array(NULL, ist->st->nb_side_data,\n                                                      sizeof(*ist->st->side_data));\n                if (!ost->st->side_data)\n                    return AVERROR(ENOMEM);\n                for (j = 0; j < ist->st->nb_side_data; j++) {\n                    const AVPacketSideData *sd_src = &ist->st->side_data[j];\n                    AVPacketSideData *sd_dst = &ost->st->side_data[j];\n                    sd_dst->data = av_malloc(sd_src->size);\n                    if (!sd_dst->data)\n                        return AVERROR(ENOMEM);\n                    memcpy(sd_dst->data, sd_src->data, sd_src->size);\n                    sd_dst->size = sd_src->size;\n                    sd_dst->type = sd_src->type;\n                    ost->st->nb_side_data++;\n                }\n            }\n            ost->parser = av_parser_init(enc_ctx->codec_id);\n            switch (enc_ctx->codec_type) {\n            case AVMEDIA_TYPE_AUDIO:\n                if (audio_volume != 256) {\n                    av_log(NULL, AV_LOG_FATAL, "-acodec copy and -vol are incompatible (frames are not decoded)\\n");\n                    exit_program(1);\n                }\n                enc_ctx->channel_layout     = dec_ctx->channel_layout;\n                enc_ctx->sample_rate        = dec_ctx->sample_rate;\n                enc_ctx->channels           = dec_ctx->channels;\n                enc_ctx->frame_size         = dec_ctx->frame_size;\n                enc_ctx->audio_service_type = dec_ctx->audio_service_type;\n                enc_ctx->block_align        = dec_ctx->block_align;\n                break;\n            case AVMEDIA_TYPE_VIDEO:\n                enc_ctx->pix_fmt            = dec_ctx->pix_fmt;\n                enc_ctx->width              = dec_ctx->width;\n                enc_ctx->height             = dec_ctx->height;\n                enc_ctx->has_b_frames       = dec_ctx->has_b_frames;\n                if (ost->frame_aspect_ratio)\n                    sar = av_d2q(ost->frame_aspect_ratio * enc_ctx->height / enc_ctx->width, 255);\n                else if (ist->st->sample_aspect_ratio.num)\n                    sar = ist->st->sample_aspect_ratio;\n                else\n                    sar = dec_ctx->sample_aspect_ratio;\n                ost->st->sample_aspect_ratio = enc_ctx->sample_aspect_ratio = sar;\n                break;\n            case AVMEDIA_TYPE_SUBTITLE:\n                enc_ctx->width  = dec_ctx->width;\n                enc_ctx->height = dec_ctx->height;\n                break;\n            case AVMEDIA_TYPE_DATA:\n            case AVMEDIA_TYPE_ATTACHMENT:\n                break;\n            default:\n                abort();\n            }\n        } else {\n            if (!ost->enc) {\n                snprintf(error, sizeof(error), "Automatic encoder selection "\n                         "failed for output stream #%d:%d. Default encoder for "\n                         "format %s is probably disabled. Please choose an "\n                         "encoder manually.\\n", ost->file_index, ost->index,\n                         oc->oformat->name);\n                ret = AVERROR(EINVAL);\n                goto dump_format;\n            }\n            if (ist)\n                ist->decoding_needed = 1;\n            ost->encoding_needed = 1;\n            set_encoder_id(output_files[ost->file_index], ost);\n            if (enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO &&\n                !ost->frame_rate.num && ist &&\n                (video_sync_method ==  VSYNC_CFR ||\n                 (video_sync_method ==  VSYNC_AUTO &&\n                  !(oc->oformat->flags & (AVFMT_NOTIMESTAMPS | AVFMT_VARIABLE_FPS))))) {\n                if (ist->framerate.num)\n                    ost->frame_rate = ist->framerate;\n                else if (ist->st->avg_frame_rate.num)\n                    ost->frame_rate = ist->st->avg_frame_rate;\n                else {\n                    av_log(NULL, AV_LOG_WARNING, "Constant framerate requested "\n                           "for the output stream #%d:%d, but no information "\n                           "about the input framerate is available. Falling "\n                           "back to a default value of 25fps. Use the -r option "\n                           "if you want a different framerate.\\n",\n                           ost->file_index, ost->index);\n                    ost->frame_rate = (AVRational){ 25, 1 };\n                }\n                if (ost->enc && ost->enc->supported_framerates && !ost->force_fps) {\n                    int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates);\n                    ost->frame_rate = ost->enc->supported_framerates[idx];\n                }\n            }\n            if (!ost->filter &&\n                (enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO ||\n                 enc_ctx->codec_type == AVMEDIA_TYPE_AUDIO)) {\n                    FilterGraph *fg;\n                    fg = init_simple_filtergraph(ist, ost);\n                    if (configure_filtergraph(fg)) {\n                        av_log(NULL, AV_LOG_FATAL, "Error opening filters!\\n");\n                        exit_program(1);\n                    }\n            }\n            switch (enc_ctx->codec_type) {\n            case AVMEDIA_TYPE_AUDIO:\n                enc_ctx->sample_fmt     = ost->filter->filter->inputs[0]->format;\n                enc_ctx->sample_rate    = ost->filter->filter->inputs[0]->sample_rate;\n                enc_ctx->channel_layout = ost->filter->filter->inputs[0]->channel_layout;\n                enc_ctx->channels       = av_get_channel_layout_nb_channels(enc_ctx->channel_layout);\n                enc_ctx->time_base      = (AVRational){ 1, enc_ctx->sample_rate };\n                break;\n            case AVMEDIA_TYPE_VIDEO:\n                enc_ctx->time_base = ost->filter->filter->inputs[0]->time_base;\n                enc_ctx->width  = ost->filter->filter->inputs[0]->w;\n                enc_ctx->height = ost->filter->filter->inputs[0]->h;\n                enc_ctx->sample_aspect_ratio = ost->st->sample_aspect_ratio =\n                    ost->frame_aspect_ratio ?\n                    av_d2q(ost->frame_aspect_ratio * enc_ctx->height/enc_ctx->width, 255) :\n                    ost->filter->filter->inputs[0]->sample_aspect_ratio;\n                enc_ctx->pix_fmt = ost->filter->filter->inputs[0]->format;\n                ost->st->avg_frame_rate = ost->frame_rate;\n                if (dec_ctx &&\n                    (enc_ctx->width   != dec_ctx->width  ||\n                     enc_ctx->height  != dec_ctx->height ||\n                     enc_ctx->pix_fmt != dec_ctx->pix_fmt)) {\n                    enc_ctx->bits_per_raw_sample = 0;\n                }\n                if (ost->forced_keyframes)\n                    parse_forced_key_frames(ost->forced_keyframes, ost,\n                                            ost->enc_ctx);\n                break;\n            case AVMEDIA_TYPE_SUBTITLE:\n                enc_ctx->time_base = (AVRational){1, 1000};\n                break;\n            default:\n                abort();\n                break;\n            }\n            if ((enc_ctx->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) {\n                char logfilename[1024];\n                FILE *f;\n                snprintf(logfilename, sizeof(logfilename), "%s-%d.log",\n                         ost->logfile_prefix ? ost->logfile_prefix :\n                                               DEFAULT_PASS_LOGFILENAME_PREFIX,\n                         i);\n                if (!strcmp(ost->enc->name, "libx264")) {\n                    av_dict_set(&ost->encoder_opts, "stats", logfilename, AV_DICT_DONT_OVERWRITE);\n                } else {\n                    if (enc_ctx->flags & CODEC_FLAG_PASS1) {\n                        f = fopen(logfilename, "wb");\n                        if (!f) {\n                            av_log(NULL, AV_LOG_FATAL, "Cannot write log file \'%s\' for pass-1 encoding: %s\\n",\n                                   logfilename, strerror(errno));\n                            exit_program(1);\n                        }\n                        ost->logfile = f;\n                    } else {\n                        char  *logbuffer;\n                        size_t logbuffer_size;\n                        if (cmdutils_read_file(logfilename, &logbuffer, &logbuffer_size) < 0) {\n                            av_log(NULL, AV_LOG_FATAL, "Error reading log file \'%s\' for pass-2 encoding\\n",\n                                   logfilename);\n                            exit_program(1);\n                        }\n                        enc_ctx->stats_in = logbuffer;\n                    }\n                }\n            }\n        }\n    }\n    for (i = 0; i < nb_output_streams; i++) {\n        ost = output_streams[i];\n        if (ost->encoding_needed) {\n            AVCodec      *codec = ost->enc;\n            AVCodecContext *dec = NULL;\n            if ((ist = get_input_stream(ost)))\n                dec = ist->dec_ctx;\n            if (dec && dec->subtitle_header) {\n                ost->enc_ctx->subtitle_header = av_malloc(dec->subtitle_header_size);\n                if (!ost->enc_ctx->subtitle_header) {\n                    ret = AVERROR(ENOMEM);\n                    goto dump_format;\n                }\n                memcpy(ost->enc_ctx->subtitle_header, dec->subtitle_header, dec->subtitle_header_size);\n                ost->enc_ctx->subtitle_header_size = dec->subtitle_header_size;\n            }\n            if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0))\n                av_dict_set(&ost->encoder_opts, "threads", "auto", 0);\n            av_dict_set(&ost->encoder_opts, "side_data_only_packets", "1", 0);\n            if ((ret = avcodec_open2(ost->enc_ctx, codec, &ost->encoder_opts)) < 0) {\n                if (ret == AVERROR_EXPERIMENTAL)\n                    abort_codec_experimental(codec, 1);\n                snprintf(error, sizeof(error), "Error while opening encoder for output stream #%d:%d - maybe incorrect parameters such as bit_rate, rate, width or height",\n                        ost->file_index, ost->index);\n                goto dump_format;\n            }\n            assert_avoptions(ost->encoder_opts);\n            if (ost->enc_ctx->bit_rate && ost->enc_ctx->bit_rate < 1000)\n                av_log(NULL, AV_LOG_WARNING, "The bitrate parameter is set too low."\n                                             "It takes bits/s as argument, not kbits/s\\n");\n        } else {\n            ret = av_opt_set_dict(ost->enc_ctx, &ost->encoder_opts);\n            if (ret < 0)\n                return ret;\n        }\n        ret = avcodec_copy_context(ost->st->codec, ost->enc_ctx);\n        if (ret < 0) {\n            av_log(NULL, AV_LOG_FATAL,\n                   "Error initializing the output stream codec context.\\n");\n            exit_program(1);\n        }\n        ost->st->time_base = ost->enc_ctx->time_base;\n    }\n    for (i = 0; i < nb_input_streams; i++)\n        if ((ret = init_input_stream(i, error, sizeof(error))) < 0)\n            goto dump_format;\n    for (i = 0; i < nb_input_files; i++) {\n        InputFile *ifile = input_files[i];\n        for (j = 0; j < ifile->ctx->nb_programs; j++) {\n            AVProgram *p = ifile->ctx->programs[j];\n            int discard  = AVDISCARD_ALL;\n            for (k = 0; k < p->nb_stream_indexes; k++)\n                if (!input_streams[ifile->ist_index + p->stream_index[k]]->discard) {\n                    discard = AVDISCARD_DEFAULT;\n                    break;\n                }\n            p->discard = discard;\n        }\n    }\n    for (i = 0; i < nb_output_files; i++) {\n        oc = output_files[i]->ctx;\n        oc->interrupt_callback = int_cb;\n        if ((ret = avformat_write_header(oc, &output_files[i]->opts)) < 0) {\n            char errbuf[128];\n            av_strerror(ret, errbuf, sizeof(errbuf));\n            snprintf(error, sizeof(error),\n                     "Could not write header for output file #%d "\n                     "(incorrect codec parameters ?): %s",\n                     i, errbuf);\n            ret = AVERROR(EINVAL);\n            goto dump_format;\n        }\n        assert_avoptions(output_files[i]->opts);\n        if (strcmp(oc->oformat->name, "rtp")) {\n            want_sdp = 0;\n        }\n    }\n dump_format:\n    for (i = 0; i < nb_output_files; i++) {\n        av_dump_format(output_files[i]->ctx, i, output_files[i]->ctx->filename, 1);\n    }\n    av_log(NULL, AV_LOG_INFO, "Stream mapping:\\n");\n    for (i = 0; i < nb_input_streams; i++) {\n        ist = input_streams[i];\n        for (j = 0; j < ist->nb_filters; j++) {\n            if (ist->filters[j]->graph->graph_desc) {\n                av_log(NULL, AV_LOG_INFO, "  Stream #%d:%d (%s) -> %s",\n                       ist->file_index, ist->st->index, ist->dec ? ist->dec->name : "?",\n                       ist->filters[j]->name);\n                if (nb_filtergraphs > 1)\n                    av_log(NULL, AV_LOG_INFO, " (graph %d)", ist->filters[j]->graph->index);\n                av_log(NULL, AV_LOG_INFO, "\\n");\n            }\n        }\n    }\n    for (i = 0; i < nb_output_streams; i++) {\n        ost = output_streams[i];\n        if (ost->attachment_filename) {\n            av_log(NULL, AV_LOG_INFO, "  File %s -> Stream #%d:%d\\n",\n                   ost->attachment_filename, ost->file_index, ost->index);\n            continue;\n        }\n        if (ost->filter && ost->filter->graph->graph_desc) {\n            av_log(NULL, AV_LOG_INFO, "  %s", ost->filter->name);\n            if (nb_filtergraphs > 1)\n                av_log(NULL, AV_LOG_INFO, " (graph %d)", ost->filter->graph->index);\n            av_log(NULL, AV_LOG_INFO, " -> Stream #%d:%d (%s)\\n", ost->file_index,\n                   ost->index, ost->enc ? ost->enc->name : "?");\n            continue;\n        }\n        av_log(NULL, AV_LOG_INFO, "  Stream #%d:%d -> #%d:%d",\n               input_streams[ost->source_index]->file_index,\n               input_streams[ost->source_index]->st->index,\n               ost->file_index,\n               ost->index);\n        if (ost->sync_ist != input_streams[ost->source_index])\n            av_log(NULL, AV_LOG_INFO, " [sync #%d:%d]",\n                   ost->sync_ist->file_index,\n                   ost->sync_ist->st->index);\n        if (ost->stream_copy)\n            av_log(NULL, AV_LOG_INFO, " (copy)");\n        else {\n            const AVCodec *in_codec    = input_streams[ost->source_index]->dec;\n            const AVCodec *out_codec   = ost->enc;\n            const char *decoder_name   = "?";\n            const char *in_codec_name  = "?";\n            const char *encoder_name   = "?";\n            const char *out_codec_name = "?";\n            if (in_codec) {\n                decoder_name  = in_codec->name;\n                in_codec_name = avcodec_descriptor_get(in_codec->id)->name;\n                if (!strcmp(decoder_name, in_codec_name))\n                    decoder_name = "native";\n            }\n            if (out_codec) {\n                encoder_name   = out_codec->name;\n                out_codec_name = avcodec_descriptor_get(out_codec->id)->name;\n                if (!strcmp(encoder_name, out_codec_name))\n                    encoder_name = "native";\n            }\n            av_log(NULL, AV_LOG_INFO, " (%s (%s) -> %s (%s))",\n                   in_codec_name, decoder_name,\n                   out_codec_name, encoder_name);\n        }\n        av_log(NULL, AV_LOG_INFO, "\\n");\n    }\n    if (ret) {\n        av_log(NULL, AV_LOG_ERROR, "%s\\n", error);\n        return ret;\n    }\n    if (want_sdp) {\n        print_sdp();\n    }\n    return 0;\n}', 'int av_dict_set(AVDictionary **pm, const char *key, const char *value,\n                int flags)\n{\n    AVDictionary *m = *pm;\n    AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);\n    char *oldval = NULL;\n    int allocated = !!m;\n    if (!m)\n        m = *pm = av_mallocz(sizeof(*m));\n    if (!m)\n        return AVERROR(ENOMEM);\n    if (tag) {\n        if (flags & AV_DICT_DONT_OVERWRITE) {\n            if (flags & AV_DICT_DONT_STRDUP_KEY) av_free(key);\n            if (flags & AV_DICT_DONT_STRDUP_VAL) av_free(value);\n            return 0;\n        }\n        if (flags & AV_DICT_APPEND)\n            oldval = tag->value;\n        else\n            av_free(tag->value);\n        av_free(tag->key);\n        *tag = m->elems[--m->count];\n    } else {\n        int ret = av_reallocp_array(&m->elems,\n                                    m->count + 1, sizeof(*m->elems));\n        if (ret < 0) {\n            if (allocated)\n                av_freep(pm);\n            return ret;\n        }\n    }\n    if (value) {\n        if (flags & AV_DICT_DONT_STRDUP_KEY)\n            m->elems[m->count].key = key;\n        else\n            m->elems[m->count].key = av_strdup(key);\n        if (flags & AV_DICT_DONT_STRDUP_VAL) {\n            m->elems[m->count].value = value;\n        } else if (oldval && flags & AV_DICT_APPEND) {\n            int len = strlen(oldval) + strlen(value) + 1;\n            if (!(oldval = av_realloc(oldval, len)))\n                return AVERROR(ENOMEM);\n            av_strlcat(oldval, value, len);\n            m->elems[m->count].value = oldval;\n        } else\n            m->elems[m->count].value = av_strdup(value);\n        m->count++;\n    }\n    if (!m->count) {\n        av_free(m->elems);\n        av_freep(pm);\n    }\n    return 0;\n}', 'AVDictionaryEntry *av_dict_get(const AVDictionary *m, const char *key,\n                               const AVDictionaryEntry *prev, int flags)\n{\n    unsigned int i, j;\n    if (!m)\n        return NULL;\n    if (prev)\n        i = prev - m->elems + 1;\n    else\n        i = 0;\n    for (; i < m->count; i++) {\n        const char *s = m->elems[i].key;\n        if (flags & AV_DICT_MATCH_CASE)\n            for (j = 0; s[j] == key[j] && key[j]; j++)\n                ;\n        else\n            for (j = 0; av_toupper(s[j]) == av_toupper(key[j]) && key[j]; j++)\n                ;\n        if (key[j])\n            continue;\n        if (s[j] && !(flags & AV_DICT_IGNORE_SUFFIX))\n            continue;\n        return &m->elems[i];\n    }\n    return NULL;\n}']