libavformat/mxfenc.c:1668: 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:1634:1: Parameter `s->priv_data->edit_units_count`
1632. }
1633. 
1634. static int mxf_write_d10_packet(AVFormatContext *s, AVPacket *pkt)
      ^
1635. {
1636.     MXFContext *mxf = s->priv_data;

libavformat/mxfenc.c:1668:9: Call
1666.         mxf_write_d10_video_packet(s, st, pkt);
1667.     else
1668.         mxf_write_d10_audio_packet(s, st, pkt);
              ^
1669. 
1670.     put_flush_packet(pb);

libavformat/mxfenc.c:1601:1: <LHS trace>
1599. }
1600. 
1601. static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt)
      ^
1602. {
1603.     MXFContext *mxf = s->priv_data;

libavformat/mxfenc.c:1601:1: Parameter `s->priv_data->edit_units_count`
  1599. }
  1600. 
  1601. static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt)
        ^
  1602. {
  1603.     MXFContext *mxf = s->priv_data;

libavformat/mxfenc.c:1613:19: 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` 
  1611.     klv_encode_ber4_length(pb, 4 + frame_size*4*8);
  1612. 
  1613.     put_byte(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1));
                          ^
  1614.     put_le16(pb, frame_size);
  1615.     put_byte(pb, (1<<st->codec->channels)-1);

static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt)
{
    MXFContext *mxf = s->priv_data;
    ByteIOContext *pb = s->pb;
    int frame_size = (pkt->size<<3) /
        (st->codec->channels*av_get_bits_per_sample(st->codec->codec_id));
    uint8_t *samples = pkt->data;
    uint8_t *end = pkt->data + pkt->size;
    int i;
    klv_encode_ber4_length(pb, 4 + frame_size*4*8);
    put_byte(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1));
    put_le16(pb, frame_size);
    put_byte(pb, (1<<st->codec->channels)-1);
    while (samples < end) {
        for (i = 0; i < st->codec->channels; i++) {
            uint32_t sample;
            if (st->codec->codec_id == CODEC_ID_PCM_S24LE) {
                sample = (AV_RL24(samples)<< 4)|((samples==pkt->data)<<3) | i;
                samples += 3;
            } else {
                sample = (AV_RL16(samples)<<12)|((samples==pkt->data)<<3) | i;
                samples += 2;
            }
            put_le32(pb, sample);
        }
        for (; i < 8; i++)
            put_le32(pb, 0);
    }
}
['static int mxf_write_d10_packet(AVFormatContext *s, AVPacket *pkt)\n{\n    MXFContext *mxf = s->priv_data;\n    ByteIOContext *pb = s->pb;\n    AVStream *st = s->streams[pkt->stream_index];\n    MXFStreamContext *sc = st->priv_data;\n    int flags = 0;\n    if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO) {\n        if (!mxf_parse_mpeg2_frame(s, st, pkt, &flags)) {\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        mxf_write_partition(s, 1, 2, header_open_partition_key, 1);\n        mxf->header_written = 1;\n        mxf_write_klv_fill(s);\n        mxf_write_index_table_segment(s);\n    }\n    if (st->index == 0) {\n        mxf_write_klv_fill(s);\n        mxf_write_system_item(s);\n        mxf->edit_units_count++;\n    }\n    mxf_write_klv_fill(s);\n    put_buffer(pb, sc->track_essence_element_key, 16);\n    if (st->codec->codec_type == CODEC_TYPE_VIDEO)\n        mxf_write_d10_video_packet(s, st, pkt);\n    else\n        mxf_write_d10_audio_packet(s, st, pkt);\n    put_flush_packet(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    ByteIOContext *pb = s->pb;\n    int frame_size = (pkt->size<<3) /\n        (st->codec->channels*av_get_bits_per_sample(st->codec->codec_id));\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    put_byte(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1));\n    put_le16(pb, frame_size);\n    put_byte(pb, (1<<st->codec->channels)-1);\n    while (samples < end) {\n        for (i = 0; i < st->codec->channels; i++) {\n            uint32_t sample;\n            if (st->codec->codec_id == CODEC_ID_PCM_S24LE) {\n                sample = (AV_RL24(samples)<< 4)|((samples==pkt->data)<<3) | i;\n                samples += 3;\n            } else {\n                sample = (AV_RL16(samples)<<12)|((samples==pkt->data)<<3) | i;\n                samples += 2;\n            }\n            put_le32(pb, sample);\n        }\n        for (; i < 8; i++)\n            put_le32(pb, 0);\n    }\n}']