libavformat/mxfenc.c:1746: error: Integer Overflow L2
  ([min(0, `s->priv_data->edit_units_count`), 1+max(0, `s->priv_data->edit_units_count`)] - 1):unsigned32 by call to `mxf_write_d10_audio_packet`.

libavformat/mxfenc.c:1676:1: Parameter `s->priv_data->edit_units_count`
1674. }
1675. 
1676. static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt)
      ^
1677. {
1678.     MXFContext *mxf = s->priv_data;

libavformat/mxfenc.c:1746:13: Call
1744.             mxf_write_d10_video_packet(s, st, pkt);
1745.         else
1746.             mxf_write_d10_audio_packet(s, st, pkt);
                  ^
1747.     } else {
1748.         klv_encode_ber4_length(pb, pkt->size); // write length

libavformat/mxfenc.c:1644:1: <LHS trace>
1642. }
1643. 
1644. static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt)
      ^
1645. {
1646.     MXFContext *mxf = s->priv_data;

libavformat/mxfenc.c:1644:1: Parameter `s->priv_data->edit_units_count`
  1642. }
  1643. 
  1644. static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt)
        ^
  1645. {
  1646.     MXFContext *mxf = s->priv_data;

libavformat/mxfenc.c:1655:18: Binary operation: ([min(0, s->priv_data->edit_units_count), 1+max(0, s->priv_data->edit_units_count)] - 1):unsigned32 by call to `mxf_write_d10_audio_packet` 
  1653.     klv_encode_ber4_length(pb, 4 + frame_size*4*8);
  1654. 
  1655.     avio_w8(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1));
                         ^
  1656.     avio_wl16(pb, frame_size);
  1657.     avio_w8(pb, (1<<st->codecpar->channels)-1);

static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt)
{
    MXFContext *mxf = s->priv_data;
    AVIOContext *pb = s->pb;
    int frame_size = pkt->size / st->codecpar->block_align;
    uint8_t *samples = pkt->data;
    uint8_t *end = pkt->data + pkt->size;
    int i;
    klv_encode_ber4_length(pb, 4 + frame_size*4*8);
    avio_w8(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1));
    avio_wl16(pb, frame_size);
    avio_w8(pb, (1<<st->codecpar->channels)-1);
    while (samples < end) {
        for (i = 0; i < st->codecpar->channels; i++) {
            uint32_t sample;
            if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S24LE) {
                sample = AV_RL24(samples)<< 4;
                samples += 3;
            } else {
                sample = AV_RL16(samples)<<12;
                samples += 2;
            }
            avio_wl32(pb, sample | i);
        }
        for (; i < 8; i++)
            avio_wl32(pb, i);
    }
}
['static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt)\n{\n    MXFContext *mxf = s->priv_data;\n    AVIOContext *pb = s->pb;\n    AVStream *st = s->streams[pkt->stream_index];\n    MXFStreamContext *sc = st->priv_data;\n    MXFIndexEntry ie = {0};\n    int err;\n    if (!mxf->edit_unit_byte_count && !(mxf->edit_units_count % EDIT_UNITS_PER_BODY)) {\n        if ((err = av_reallocp_array(&mxf->index_entries, mxf->edit_units_count\n                                     + EDIT_UNITS_PER_BODY, sizeof(*mxf->index_entries))) < 0) {\n            mxf->edit_units_count = 0;\n            av_log(s, AV_LOG_ERROR, "could not allocate index entries\\n");\n            return err;\n        }\n    }\n    if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) {\n        if (!mxf_parse_mpeg2_frame(s, st, pkt, &ie)) {\n            av_log(s, AV_LOG_ERROR, "could not get mpeg2 profile and level\\n");\n            return -1;\n        }\n    }\n    if (!mxf->header_written) {\n        if (mxf->edit_unit_byte_count) {\n            if ((err = mxf_write_partition(s, 1, 2, header_open_partition_key, 1)) < 0)\n                return err;\n            mxf_write_klv_fill(s);\n            mxf_write_index_table_segment(s);\n        } else {\n            if ((err = mxf_write_partition(s, 0, 0, header_open_partition_key, 1)) < 0)\n                return err;\n        }\n        mxf->header_written = 1;\n    }\n    if (st->index == 0) {\n        if (!mxf->edit_unit_byte_count &&\n            (!mxf->edit_units_count || mxf->edit_units_count > EDIT_UNITS_PER_BODY) &&\n            !(ie.flags & 0x33)) {\n            mxf_write_klv_fill(s);\n            if ((err = mxf_write_partition(s, 1, 2, body_partition_key, 0)) < 0)\n                return err;\n            mxf_write_klv_fill(s);\n            mxf_write_index_table_segment(s);\n        }\n        mxf_write_klv_fill(s);\n        mxf_write_system_item(s);\n        if (!mxf->edit_unit_byte_count) {\n            mxf->index_entries[mxf->edit_units_count].offset = mxf->body_offset;\n            mxf->index_entries[mxf->edit_units_count].flags = ie.flags;\n            mxf->index_entries[mxf->edit_units_count].temporal_ref = ie.temporal_ref;\n            mxf->body_offset += KAG_SIZE;\n        }\n        mxf->edit_units_count++;\n    } else if (!mxf->edit_unit_byte_count && st->index == 1) {\n        mxf->index_entries[mxf->edit_units_count-1].slice_offset =\n            mxf->body_offset - mxf->index_entries[mxf->edit_units_count-1].offset;\n    }\n    mxf_write_klv_fill(s);\n    avio_write(pb, sc->track_essence_element_key, 16);\n    if (s->oformat == &ff_mxf_d10_muxer) {\n        if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)\n            mxf_write_d10_video_packet(s, st, pkt);\n        else\n            mxf_write_d10_audio_packet(s, st, pkt);\n    } else {\n        klv_encode_ber4_length(pb, pkt->size);\n        avio_write(pb, pkt->data, pkt->size);\n        mxf->body_offset += 16+4+pkt->size + klv_fill_size(16+4+pkt->size);\n    }\n    avio_flush(pb);\n    return 0;\n}', 'static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt)\n{\n    MXFContext *mxf = s->priv_data;\n    AVIOContext *pb = s->pb;\n    int frame_size = pkt->size / st->codecpar->block_align;\n    uint8_t *samples = pkt->data;\n    uint8_t *end = pkt->data + pkt->size;\n    int i;\n    klv_encode_ber4_length(pb, 4 + frame_size*4*8);\n    avio_w8(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1));\n    avio_wl16(pb, frame_size);\n    avio_w8(pb, (1<<st->codecpar->channels)-1);\n    while (samples < end) {\n        for (i = 0; i < st->codecpar->channels; i++) {\n            uint32_t sample;\n            if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S24LE) {\n                sample = AV_RL24(samples)<< 4;\n                samples += 3;\n            } else {\n                sample = AV_RL16(samples)<<12;\n                samples += 2;\n            }\n            avio_wl32(pb, sample | i);\n        }\n        for (; i < 8; i++)\n            avio_wl32(pb, i);\n    }\n}']