libavformat/mxfenc.c:1213: error: Null Dereference
  pointer `mxf->body_partition_offset` last assigned on line 1209 could be null and is dereferenced at line 1213, column 9.

libavformat/mxfenc.c:1186:1: start of procedure mxf_write_partition()
1184. }
1185. 
1186. static void mxf_write_partition(AVFormatContext *s, int bodysid,
      ^
1187.                                 int indexsid,
1188.                                 const uint8_t *key, int write_metadata)

libavformat/mxfenc.c:1190:5: 
1188.                                 const uint8_t *key, int write_metadata)
1189. {
1190.     MXFContext *mxf = s->priv_data;
          ^
1191.     AVIOContext *pb = s->pb;
1192.     int64_t header_byte_count_offset;

libavformat/mxfenc.c:1191:5: 
1189. {
1190.     MXFContext *mxf = s->priv_data;
1191.     AVIOContext *pb = s->pb;
          ^
1192.     int64_t header_byte_count_offset;
1193.     unsigned index_byte_count = 0;

libavformat/mxfenc.c:1193:5: 
1191.     AVIOContext *pb = s->pb;
1192.     int64_t header_byte_count_offset;
1193.     unsigned index_byte_count = 0;
          ^
1194.     uint64_t partition_offset = avio_tell(pb);
1195. 

libavformat/mxfenc.c:1194:5: 
1192.     int64_t header_byte_count_offset;
1193.     unsigned index_byte_count = 0;
1194.     uint64_t partition_offset = avio_tell(pb);
          ^
1195. 
1196.     if (!mxf->edit_unit_byte_count && mxf->edit_units_count)

libavformat/avio.h:450:1: start of procedure avio_tell()
  448.  * @return position or AVERROR.
  449.  */
  450. static av_always_inline int64_t avio_tell(AVIOContext *s)
       ^
  451. {
  452.     return avio_seek(s, 0, SEEK_CUR);

libavformat/avio.h:452:5: Skipping avio_seek(): empty list of specs
  450. static av_always_inline int64_t avio_tell(AVIOContext *s)
  451. {
  452.     return avio_seek(s, 0, SEEK_CUR);
           ^
  453. }
  454. 

libavformat/avio.h:453:1: return from a call to avio_tell
  451. {
  452.     return avio_seek(s, 0, SEEK_CUR);
  453. }
       ^
  454. 
  455. /**

libavformat/mxfenc.c:1196:10: Taking true branch
1194.     uint64_t partition_offset = avio_tell(pb);
1195. 
1196.     if (!mxf->edit_unit_byte_count && mxf->edit_units_count)
               ^
1197.         index_byte_count = 85 + 12+(s->nb_streams+1)*6 +
1198.             12+mxf->edit_units_count*(11+mxf->slice_count*4);

libavformat/mxfenc.c:1196:39: Taking true branch
1194.     uint64_t partition_offset = avio_tell(pb);
1195. 
1196.     if (!mxf->edit_unit_byte_count && mxf->edit_units_count)
                                            ^
1197.         index_byte_count = 85 + 12+(s->nb_streams+1)*6 +
1198.             12+mxf->edit_units_count*(11+mxf->slice_count*4);

libavformat/mxfenc.c:1197:9: 
1195. 
1196.     if (!mxf->edit_unit_byte_count && mxf->edit_units_count)
1197.         index_byte_count = 85 + 12+(s->nb_streams+1)*6 +
              ^
1198.             12+mxf->edit_units_count*(11+mxf->slice_count*4);
1199.     else if (mxf->edit_unit_byte_count && indexsid)

libavformat/mxfenc.c:1202:9: Taking true branch
1200.         index_byte_count = 80;
1201. 
1202.     if (index_byte_count) {
              ^
1203.         // add encoded ber length
1204.         index_byte_count += 16 + klv_ber_length(index_byte_count);

libavformat/mxfenc.c:1204:9: 
1202.     if (index_byte_count) {
1203.         // add encoded ber length
1204.         index_byte_count += 16 + klv_ber_length(index_byte_count);
              ^
1205.         index_byte_count += klv_fill_size(index_byte_count);
1206.     }

libavformat/mxfenc.c:331:1: start of procedure klv_ber_length()
  329. }
  330. 
  331. static int klv_ber_length(uint64_t len)
       ^
  332. {
  333.     if (len < 128)

libavformat/mxfenc.c:333:9: Taking false branch
  331. static int klv_ber_length(uint64_t len)
  332. {
  333.     if (len < 128)
               ^
  334.         return 1;
  335.     else

libavformat/mxfenc.c:336:9: 
  334.         return 1;
  335.     else
  336.         return (av_log2(len) >> 3) + 2;
               ^
  337. }
  338. 

libavutil/common.h:67:1: start of procedure av_log2_c()
    65. extern const uint8_t av_reverse[256];
    66. 
    67. static av_always_inline av_const int av_log2_c(unsigned int v)
        ^
    68. {
    69.     int n = 0;

libavutil/common.h:69:5: 
    67. static av_always_inline av_const int av_log2_c(unsigned int v)
    68. {
    69.     int n = 0;
            ^
    70.     if (v & 0xffff0000) {
    71.         v >>= 16;

libavutil/common.h:70:9: Taking false branch
    68. {
    69.     int n = 0;
    70.     if (v & 0xffff0000) {
                ^
    71.         v >>= 16;
    72.         n += 16;

libavutil/common.h:74:9: Taking false branch
    72.         n += 16;
    73.     }
    74.     if (v & 0xff00) {
                ^
    75.         v >>= 8;
    76.         n += 8;

libavutil/common.h:78:5: 
    76.         n += 8;
    77.     }
    78.     n += ff_log2_tab[v];
            ^
    79. 
    80.     return n;

libavutil/common.h:80:5: 
    78.     n += ff_log2_tab[v];
    79. 
    80.     return n;
            ^
    81. }
    82. 

libavutil/common.h:81:1: return from a call to av_log2_c
    79. 
    80.     return n;
    81. }
        ^
    82. 
    83. static av_always_inline av_const int av_log2_16bit_c(unsigned int v)

libavformat/mxfenc.c:337:1: return from a call to klv_ber_length
  335.     else
  336.         return (av_log2(len) >> 3) + 2;
  337. }
       ^
  338. 
  339. static int klv_encode_ber_length(AVIOContext *pb, uint64_t len)

libavformat/mxfenc.c:1205:9: 
1203.         // add encoded ber length
1204.         index_byte_count += 16 + klv_ber_length(index_byte_count);
1205.         index_byte_count += klv_fill_size(index_byte_count);
              ^
1206.     }
1207. 

libavformat/mxfenc.c:1031:1: start of procedure klv_fill_size()
  1029. }
  1030. 
  1031. static unsigned klv_fill_size(uint64_t size)
        ^
  1032. {
  1033.     unsigned pad = KAG_SIZE - (size & (KAG_SIZE-1));

libavformat/mxfenc.c:1033:5: 
  1031. static unsigned klv_fill_size(uint64_t size)
  1032. {
  1033.     unsigned pad = KAG_SIZE - (size & (KAG_SIZE-1));
            ^
  1034.     if (pad < 20) // smallest fill item possible
  1035.         return pad + KAG_SIZE;

libavformat/mxfenc.c:1034:9: Taking false branch
  1032. {
  1033.     unsigned pad = KAG_SIZE - (size & (KAG_SIZE-1));
  1034.     if (pad < 20) // smallest fill item possible
                ^
  1035.         return pad + KAG_SIZE;
  1036.     else

libavformat/mxfenc.c:1037:9: 
  1035.         return pad + KAG_SIZE;
  1036.     else
  1037.         return pad & (KAG_SIZE-1);
                ^
  1038. }
  1039. 

libavformat/mxfenc.c:1038:1: return from a call to klv_fill_size
  1036.     else
  1037.         return pad & (KAG_SIZE-1);
  1038. }
        ^
  1039. 
  1040. static void mxf_write_index_table_segment(AVFormatContext *s)

libavformat/mxfenc.c:1208:10: Taking true branch
1206.     }
1207. 
1208.     if (!memcmp(key, body_partition_key, 16)) {
               ^
1209.         mxf->body_partition_offset =
1210.             av_realloc(mxf->body_partition_offset,

libavformat/mxfenc.c:1209:9: 
1207. 
1208.     if (!memcmp(key, body_partition_key, 16)) {
1209.         mxf->body_partition_offset =
              ^
1210.             av_realloc(mxf->body_partition_offset,
1211.                        (mxf->body_partitions_count+1)*

libavutil/mem.c:117:1: start of procedure av_realloc()
  115. }
  116. 
  117. void *av_realloc(void *ptr, size_t size)
       ^
  118. {
  119. #if CONFIG_MEMALIGN_HACK

libavutil/mem.c:124:8: Taking false branch
  122. 
  123.     /* let's disallow possible ambiguous cases */
  124.     if(size > (INT_MAX-16) )
              ^
  125.         return NULL;
  126. 

libavutil/mem.c:133:5: 
  131.     return (char*)realloc((char*)ptr - diff, size + diff) + diff;
  132. #else
  133.     return realloc(ptr, size);
           ^
  134. #endif
  135. }

libavutil/mem.c:135:1: return from a call to av_realloc
  133.     return realloc(ptr, size);
  134. #endif
  135. }
       ^
  136. 
  137. void av_free(void *ptr)

libavformat/mxfenc.c:1213:9: 
1211.                        (mxf->body_partitions_count+1)*
1212.                        sizeof(*mxf->body_partition_offset));
1213.         mxf->body_partition_offset[mxf->body_partitions_count++] = partition_offset;
              ^
1214.     }
1215. 

static void 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);
    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)) {
        mxf->body_partition_offset =
            av_realloc(mxf->body_partition_offset,
                       (mxf->body_partitions_count+1)*
                       sizeof(*mxf->body_partition_offset));
        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);
}
['static void 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    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        mxf->body_partition_offset =\n            av_realloc(mxf->body_partition_offset,\n                       (mxf->body_partitions_count+1)*\n                       sizeof(*mxf->body_partition_offset));\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}', 'static av_always_inline int64_t avio_tell(AVIOContext *s)\n{\n    return avio_seek(s, 0, SEEK_CUR);\n}', 'static int klv_ber_length(uint64_t len)\n{\n    if (len < 128)\n        return 1;\n    else\n        return (av_log2(len) >> 3) + 2;\n}', 'static av_always_inline av_const int av_log2_c(unsigned int v)\n{\n    int n = 0;\n    if (v & 0xffff0000) {\n        v >>= 16;\n        n += 16;\n    }\n    if (v & 0xff00) {\n        v >>= 8;\n        n += 8;\n    }\n    n += ff_log2_tab[v];\n    return n;\n}', 'static unsigned klv_fill_size(uint64_t size)\n{\n    unsigned pad = KAG_SIZE - (size & (KAG_SIZE-1));\n    if (pad < 20)\n        return pad + KAG_SIZE;\n    else\n        return pad & (KAG_SIZE-1);\n}', 'void *av_realloc(void *ptr, size_t size)\n{\n#if CONFIG_MEMALIGN_HACK\n    int diff;\n#endif\n    if(size > (INT_MAX-16) )\n        return NULL;\n#if CONFIG_MEMALIGN_HACK\n    if(!ptr) return av_malloc(size);\n    diff= ((char*)ptr)[-1];\n    return (char*)realloc((char*)ptr - diff, size + diff) + diff;\n#else\n    return realloc(ptr, size);\n#endif\n}']