avconv.c:2837: error: Buffer Overrun L1
  Offset: 1 Size: 1 by call to `check_stream_specifier`.

avconv.c:2799:5: Call
2797.     int idx_in = 0, idx_out = 0;
2798. 
2799.     parse_meta_type(inspec,  &type_in,  &idx_in,  &istream_spec);
          ^
2800.     parse_meta_type(outspec, &type_out, &idx_out, &ostream_spec);
2801. 

avconv.c:2763:1: Parameter `**stream_spec`
  2761.  * @param stream_spec for type s, the stream specifier is written here
  2762.  */
  2763. static void parse_meta_type(char *arg, char *type, int *index, const char **stream_spec)
        ^
  2764. {
  2765.     if (*arg) {

avconv.c:2837:24: Call
2835.     if (type_in == 's') {
2836.         for (i = 0; i < ic->nb_streams; i++) {
2837.             if ((ret = check_stream_specifier(ic, ic->streams[i], istream_spec)) > 0) {
                             ^
2838.                 meta_in = &ic->streams[i]->metadata;
2839.                 break;

cmdutils.c:882:1: <Length trace>
880. }
881. 
882. int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
     ^
883. {
884.     if (*spec <= '9' && *spec >= '0')                                        /* opt:index */

cmdutils.c:882:1: Parameter `*spec`
  880. }
  881. 
  882. int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
       ^
  883. {
  884.     if (*spec <= '9' && *spec >= '0')                                        /* opt:index */

cmdutils.c:889:18: Assignment
  887.         enum AVMediaType type;
  888. 
  889.         switch (*spec++) {
                        ^
  890.         case 'v': type = AVMEDIA_TYPE_VIDEO;    break;
  891.         case 'a': type = AVMEDIA_TYPE_AUDIO;    break;

cmdutils.c:898:13: Array access: Offset: 1 Size: 1 by call to `check_stream_specifier` 
  896.         if (type != st->codec->codec_type)
  897.             return 0;
  898.         if (*spec++ == ':') {                                   /* possibly followed by :index */
                   ^
  899.             int i, index = strtol(spec, NULL, 0);
  900.             for (i = 0; i < s->nb_streams; i++)

int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
{
    if (*spec <= '9' && *spec >= '0')
        return strtol(spec, NULL, 0) == st->index;
    else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' || *spec == 't') {
        enum AVMediaType type;
        switch (*spec++) {
        case 'v': type = AVMEDIA_TYPE_VIDEO;    break;
        case 'a': type = AVMEDIA_TYPE_AUDIO;    break;
        case 's': type = AVMEDIA_TYPE_SUBTITLE; break;
        case 'd': type = AVMEDIA_TYPE_DATA;     break;
        case 't': type = AVMEDIA_TYPE_ATTACHMENT; break;
        }
        if (type != st->codec->codec_type)
            return 0;
        if (*spec++ == ':') {
            int i, index = strtol(spec, NULL, 0);
            for (i = 0; i < s->nb_streams; i++)
                if (s->streams[i]->codec->codec_type == type && index-- == 0)
                   return i == st->index;
            return 0;
        }
        return 1;
    } else if (*spec == 'p' && *(spec + 1) == ':') {
        int prog_id, i, j;
        char *endptr;
        spec += 2;
        prog_id = strtol(spec, &endptr, 0);
        for (i = 0; i < s->nb_programs; i++) {
            if (s->programs[i]->id != prog_id)
                continue;
            if (*endptr++ == ':') {
                int stream_idx = strtol(endptr, NULL, 0);
                return (stream_idx >= 0 && stream_idx < s->programs[i]->nb_stream_indexes &&
                        st->index == s->programs[i]->stream_index[stream_idx]);
            }
            for (j = 0; j < s->programs[i]->nb_stream_indexes; j++)
                if (st->index == s->programs[i]->stream_index[j])
                    return 1;
        }
        return 0;
    } else if (!*spec)
        return 1;
    av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
    return AVERROR(EINVAL);
}
['static int copy_metadata(char *outspec, char *inspec, AVFormatContext *oc, AVFormatContext *ic, OptionsContext *o)\n{\n    AVDictionary **meta_in = NULL;\n    AVDictionary **meta_out;\n    int i, ret = 0;\n    char type_in, type_out;\n    const char *istream_spec = NULL, *ostream_spec = NULL;\n    int idx_in = 0, idx_out = 0;\n    parse_meta_type(inspec,  &type_in,  &idx_in,  &istream_spec);\n    parse_meta_type(outspec, &type_out, &idx_out, &ostream_spec);\n    if (type_in == \'g\' || type_out == \'g\')\n        o->metadata_global_manual = 1;\n    if (type_in == \'s\' || type_out == \'s\')\n        o->metadata_streams_manual = 1;\n    if (type_in == \'c\' || type_out == \'c\')\n        o->metadata_chapters_manual = 1;\n#define METADATA_CHECK_INDEX(index, nb_elems, desc)\\\n    if ((index) < 0 || (index) >= (nb_elems)) {\\\n        av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps.\\n",\\\n                (desc), (index));\\\n        exit_program(1);\\\n    }\n#define SET_DICT(type, meta, context, index)\\\n        switch (type) {\\\n        case \'g\':\\\n            meta = &context->metadata;\\\n            break;\\\n        case \'c\':\\\n            METADATA_CHECK_INDEX(index, context->nb_chapters, "chapter")\\\n            meta = &context->chapters[index]->metadata;\\\n            break;\\\n        case \'p\':\\\n            METADATA_CHECK_INDEX(index, context->nb_programs, "program")\\\n            meta = &context->programs[index]->metadata;\\\n            break;\\\n        }\\\n    SET_DICT(type_in, meta_in, ic, idx_in);\n    SET_DICT(type_out, meta_out, oc, idx_out);\n    if (type_in == \'s\') {\n        for (i = 0; i < ic->nb_streams; i++) {\n            if ((ret = check_stream_specifier(ic, ic->streams[i], istream_spec)) > 0) {\n                meta_in = &ic->streams[i]->metadata;\n                break;\n            } else if (ret < 0)\n                exit_program(1);\n        }\n        if (!meta_in) {\n            av_log(NULL, AV_LOG_FATAL, "Stream specifier %s does not match  any streams.\\n", istream_spec);\n            exit_program(1);\n        }\n    }\n    if (type_out == \'s\') {\n        for (i = 0; i < oc->nb_streams; i++) {\n            if ((ret = check_stream_specifier(oc, oc->streams[i], ostream_spec)) > 0) {\n                meta_out = &oc->streams[i]->metadata;\n                av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);\n            } else if (ret < 0)\n                exit_program(1);\n        }\n    } else\n        av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);\n    return 0;\n}', 'static void parse_meta_type(char *arg, char *type, int *index, const char **stream_spec)\n{\n    if (*arg) {\n        *type = *arg;\n        switch (*arg) {\n        case \'g\':\n            break;\n        case \'s\':\n            if (*(++arg) && *arg != \':\') {\n                av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\\n", arg);\n                exit_program(1);\n            }\n            *stream_spec = *arg == \':\' ? arg + 1 : "";\n            break;\n        case \'c\':\n        case \'p\':\n            if (*(++arg) == \':\')\n                *index = strtol(++arg, NULL, 0);\n            break;\n        default:\n            av_log(NULL, AV_LOG_FATAL, "Invalid metadata type %c.\\n", *arg);\n            exit_program(1);\n        }\n    } else\n        *type = \'g\';\n}', 'int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)\n{\n    if (*spec <= \'9\' && *spec >= \'0\')\n        return strtol(spec, NULL, 0) == st->index;\n    else if (*spec == \'v\' || *spec == \'a\' || *spec == \'s\' || *spec == \'d\' || *spec == \'t\') {\n        enum AVMediaType type;\n        switch (*spec++) {\n        case \'v\': type = AVMEDIA_TYPE_VIDEO;    break;\n        case \'a\': type = AVMEDIA_TYPE_AUDIO;    break;\n        case \'s\': type = AVMEDIA_TYPE_SUBTITLE; break;\n        case \'d\': type = AVMEDIA_TYPE_DATA;     break;\n        case \'t\': type = AVMEDIA_TYPE_ATTACHMENT; break;\n        }\n        if (type != st->codec->codec_type)\n            return 0;\n        if (*spec++ == \':\') {\n            int i, index = strtol(spec, NULL, 0);\n            for (i = 0; i < s->nb_streams; i++)\n                if (s->streams[i]->codec->codec_type == type && index-- == 0)\n                   return i == st->index;\n            return 0;\n        }\n        return 1;\n    } else if (*spec == \'p\' && *(spec + 1) == \':\') {\n        int prog_id, i, j;\n        char *endptr;\n        spec += 2;\n        prog_id = strtol(spec, &endptr, 0);\n        for (i = 0; i < s->nb_programs; i++) {\n            if (s->programs[i]->id != prog_id)\n                continue;\n            if (*endptr++ == \':\') {\n                int stream_idx = strtol(endptr, NULL, 0);\n                return (stream_idx >= 0 && stream_idx < s->programs[i]->nb_stream_indexes &&\n                        st->index == s->programs[i]->stream_index[stream_idx]);\n            }\n            for (j = 0; j < s->programs[i]->nb_stream_indexes; j++)\n                if (st->index == s->programs[i]->stream_index[j])\n                    return 1;\n        }\n        return 0;\n    } else if (!*spec)\n        return 1;\n    av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\\n", spec);\n    return AVERROR(EINVAL);\n}']