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

libavformat/mxfenc.c:1782:1: Parameter `s->priv_data->body_partitions_count`
1780. }
1781. 
1782. static int mxf_write_footer(AVFormatContext *s)
      ^
1783. {
1784.     MXFContext *mxf = s->priv_data;

libavformat/mxfenc.c:1793:20: Call
1791.     mxf->footer_partition_offset = avio_tell(pb);
1792.     if (mxf->edit_unit_byte_count) { // no need to repeat index
1793.         if ((err = mxf_write_partition(s, 0, 0, footer_partition_key, 0)) < 0)
                         ^
1794.             return err;
1795.     } else {

libavformat/mxfenc.c:1185:1: Parameter `s->priv_data->body_partitions_count`
  1183. }
  1184. 
  1185. static int mxf_write_partition(AVFormatContext *s, int bodysid,
        ^
  1186.                                 int indexsid,
  1187.                                 const uint8_t *key, int write_metadata)

libavformat/mxfenc.c:1803:5: Call
1801. 
1802.     mxf_write_klv_fill(s);
1803.     mxf_write_random_index_pack(s);
          ^
1804. 
1805.     if (s->pb->seekable) {

libavformat/mxfenc.c:1755:1: Parameter `s->priv_data->body_partitions_count`
  1753. }
  1754. 
  1755. static void mxf_write_random_index_pack(AVFormatContext *s)
        ^
  1756. {
  1757.     MXFContext *mxf = s->priv_data;

libavformat/mxfenc.c:1808:24: Call
1806.         avio_seek(pb, 0, SEEK_SET);
1807.         if (mxf->edit_unit_byte_count) {
1808.             if ((err = mxf_write_partition(s, 1, 2, header_closed_partition_key, 1)) < 0)
                             ^
1809.                 return err;
1810.             mxf_write_klv_fill(s);

libavformat/mxfenc.c:1185:1: <LHS trace>
1183. }
1184. 
1185. static int mxf_write_partition(AVFormatContext *s, int bodysid,
      ^
1186.                                 int indexsid,
1187.                                 const uint8_t *key, int write_metadata)

libavformat/mxfenc.c:1185:1: Parameter `s->priv_data->body_partitions_count`
  1183. }
  1184. 
  1185. static int mxf_write_partition(AVFormatContext *s, int bodysid,
        ^
  1186.                                 int indexsid,
  1187.                                 const uint8_t *key, int write_metadata)

libavformat/mxfenc.c:1231:23: Binary operation: ([min(0, s->priv_data->body_partitions_count), 2+max(-1, s->priv_data->body_partitions_count)] - 1):unsigned32 by call to `mxf_write_partition` 
  1229.         avio_wb64(pb, mxf->body_partition_offset[mxf->body_partitions_count-2]); // PreviousPartition
  1230.     else if (!memcmp(key, footer_partition_key, 16) && mxf->body_partitions_count)
  1231.         avio_wb64(pb, mxf->body_partition_offset[mxf->body_partitions_count-1]); // PreviousPartition
                              ^
  1232.     else
  1233.         avio_wb64(pb, 0);

static int mxf_write_partition(AVFormatContext *s, int bodysid,
                                int indexsid,
                                const uint8_t *key, int write_metadata)
{
    MXFContext *mxf = s->priv_data;
    AVIOContext *pb = s->pb;
    int64_t header_byte_count_offset;
    unsigned index_byte_count = 0;
    uint64_t partition_offset = avio_tell(pb);
    int err;
    if (!mxf->edit_unit_byte_count && mxf->edit_units_count)
        index_byte_count = 85 + 12+(s->nb_streams+1)*6 +
            12+mxf->edit_units_count*(11+mxf->slice_count*4);
    else if (mxf->edit_unit_byte_count && indexsid)
        index_byte_count = 80;
    if (index_byte_count) {
        index_byte_count += 16 + klv_ber_length(index_byte_count);
        index_byte_count += klv_fill_size(index_byte_count);
    }
    if (!memcmp(key, body_partition_key, 16)) {
        if ((err = av_reallocp_array(&mxf->body_partition_offset, mxf->body_partitions_count + 1,
                                     sizeof(*mxf->body_partition_offset))) < 0) {
            mxf->body_partitions_count = 0;
            return err;
        }
        mxf->body_partition_offset[mxf->body_partitions_count++] = partition_offset;
    }
    avio_write(pb, key, 16);
    klv_encode_ber_length(pb, 88 + 16 * mxf->essence_container_count);
    avio_wb16(pb, 1);
    avio_wb16(pb, 2);
    avio_wb32(pb, KAG_SIZE);
    avio_wb64(pb, partition_offset);
    if (!memcmp(key, body_partition_key, 16) && mxf->body_partitions_count > 1)
        avio_wb64(pb, mxf->body_partition_offset[mxf->body_partitions_count-2]);
    else if (!memcmp(key, footer_partition_key, 16) && mxf->body_partitions_count)
        avio_wb64(pb, mxf->body_partition_offset[mxf->body_partitions_count-1]);
    else
        avio_wb64(pb, 0);
    avio_wb64(pb, mxf->footer_partition_offset);
    header_byte_count_offset = avio_tell(pb);
    avio_wb64(pb, 0);
    avio_wb64(pb, index_byte_count);
    avio_wb32(pb, index_byte_count ? indexsid : 0);
    if (bodysid && mxf->edit_units_count && mxf->body_partitions_count) {
        avio_wb64(pb, mxf->body_offset);
    } else
        avio_wb64(pb, 0);
    avio_wb32(pb, bodysid);
    avio_write(pb, op1a_ul, 16);
    mxf_write_essence_container_refs(s);
    if (write_metadata) {
        int64_t pos, start;
        unsigned header_byte_count;
        mxf_write_klv_fill(s);
        start = avio_tell(s->pb);
        mxf_write_primer_pack(s);
        mxf_write_header_metadata_sets(s);
        pos = avio_tell(s->pb);
        header_byte_count = pos - start + klv_fill_size(pos);
        avio_seek(pb, header_byte_count_offset, SEEK_SET);
        avio_wb64(pb, header_byte_count);
        avio_seek(pb, pos, SEEK_SET);
    }
    avio_flush(pb);
    return 0;
}
['static int mxf_write_footer(AVFormatContext *s)\n{\n    MXFContext *mxf = s->priv_data;\n    AVIOContext *pb = s->pb;\n    int err;\n    mxf->duration = mxf->last_indexed_edit_unit + mxf->edit_units_count;\n    mxf_write_klv_fill(s);\n    mxf->footer_partition_offset = avio_tell(pb);\n    if (mxf->edit_unit_byte_count) {\n        if ((err = mxf_write_partition(s, 0, 0, footer_partition_key, 0)) < 0)\n            return err;\n    } else {\n        if ((err = mxf_write_partition(s, 0, 2, footer_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_random_index_pack(s);\n    if (s->pb->seekable) {\n        avio_seek(pb, 0, SEEK_SET);\n        if (mxf->edit_unit_byte_count) {\n            if ((err = mxf_write_partition(s, 1, 2, header_closed_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_closed_partition_key, 1)) < 0)\n                return err;\n        }\n    }\n    ff_audio_interleave_close(s);\n    av_freep(&mxf->index_entries);\n    av_freep(&mxf->body_partition_offset);\n    av_freep(&mxf->timecode_track->priv_data);\n    av_freep(&mxf->timecode_track);\n    mxf_free(s);\n    return 0;\n}', 'static int mxf_write_partition(AVFormatContext *s, int bodysid,\n                                int indexsid,\n                                const uint8_t *key, int write_metadata)\n{\n    MXFContext *mxf = s->priv_data;\n    AVIOContext *pb = s->pb;\n    int64_t header_byte_count_offset;\n    unsigned index_byte_count = 0;\n    uint64_t partition_offset = avio_tell(pb);\n    int err;\n    if (!mxf->edit_unit_byte_count && mxf->edit_units_count)\n        index_byte_count = 85 + 12+(s->nb_streams+1)*6 +\n            12+mxf->edit_units_count*(11+mxf->slice_count*4);\n    else if (mxf->edit_unit_byte_count && indexsid)\n        index_byte_count = 80;\n    if (index_byte_count) {\n        index_byte_count += 16 + klv_ber_length(index_byte_count);\n        index_byte_count += klv_fill_size(index_byte_count);\n    }\n    if (!memcmp(key, body_partition_key, 16)) {\n        if ((err = av_reallocp_array(&mxf->body_partition_offset, mxf->body_partitions_count + 1,\n                                     sizeof(*mxf->body_partition_offset))) < 0) {\n            mxf->body_partitions_count = 0;\n            return err;\n        }\n        mxf->body_partition_offset[mxf->body_partitions_count++] = partition_offset;\n    }\n    avio_write(pb, key, 16);\n    klv_encode_ber_length(pb, 88 + 16 * mxf->essence_container_count);\n    avio_wb16(pb, 1);\n    avio_wb16(pb, 2);\n    avio_wb32(pb, KAG_SIZE);\n    avio_wb64(pb, partition_offset);\n    if (!memcmp(key, body_partition_key, 16) && mxf->body_partitions_count > 1)\n        avio_wb64(pb, mxf->body_partition_offset[mxf->body_partitions_count-2]);\n    else if (!memcmp(key, footer_partition_key, 16) && mxf->body_partitions_count)\n        avio_wb64(pb, mxf->body_partition_offset[mxf->body_partitions_count-1]);\n    else\n        avio_wb64(pb, 0);\n    avio_wb64(pb, mxf->footer_partition_offset);\n    header_byte_count_offset = avio_tell(pb);\n    avio_wb64(pb, 0);\n    avio_wb64(pb, index_byte_count);\n    avio_wb32(pb, index_byte_count ? indexsid : 0);\n    if (bodysid && mxf->edit_units_count && mxf->body_partitions_count) {\n        avio_wb64(pb, mxf->body_offset);\n    } else\n        avio_wb64(pb, 0);\n    avio_wb32(pb, bodysid);\n    avio_write(pb, op1a_ul, 16);\n    mxf_write_essence_container_refs(s);\n    if (write_metadata) {\n        int64_t pos, start;\n        unsigned header_byte_count;\n        mxf_write_klv_fill(s);\n        start = avio_tell(s->pb);\n        mxf_write_primer_pack(s);\n        mxf_write_header_metadata_sets(s);\n        pos = avio_tell(s->pb);\n        header_byte_count = pos - start + klv_fill_size(pos);\n        avio_seek(pb, header_byte_count_offset, SEEK_SET);\n        avio_wb64(pb, header_byte_count);\n        avio_seek(pb, pos, SEEK_SET);\n    }\n    avio_flush(pb);\n    return 0;\n}', 'static void mxf_write_random_index_pack(AVFormatContext *s)\n{\n    MXFContext *mxf = s->priv_data;\n    AVIOContext *pb = s->pb;\n    uint64_t pos = avio_tell(pb);\n    int i;\n    avio_write(pb, random_index_pack_key, 16);\n    klv_encode_ber_length(pb, 28 + 12*mxf->body_partitions_count);\n    if (mxf->edit_unit_byte_count)\n        avio_wb32(pb, 1);\n    else\n        avio_wb32(pb, 0);\n    avio_wb64(pb, 0);\n    for (i = 0; i < mxf->body_partitions_count; i++) {\n        avio_wb32(pb, 1);\n        avio_wb64(pb, mxf->body_partition_offset[i]);\n    }\n    avio_wb32(pb, 0);\n    avio_wb64(pb, mxf->footer_partition_offset);\n    avio_wb32(pb, avio_tell(pb) - pos + 4);\n}']