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

libavformat/mxfenc.c:1173:1: start of procedure mxf_write_partition()
1171. }
1172. 
1173. static void mxf_write_partition(AVFormatContext *s, int bodysid,
      ^
1174.                                 int indexsid,
1175.                                 const uint8_t *key, int write_metadata)

libavformat/mxfenc.c:1177:5: 
1175.                                 const uint8_t *key, int write_metadata)
1176. {
1177.     MXFContext *mxf = s->priv_data;
          ^
1178.     ByteIOContext *pb = s->pb;
1179.     int64_t header_byte_count_offset;

libavformat/mxfenc.c:1178:5: 
1176. {
1177.     MXFContext *mxf = s->priv_data;
1178.     ByteIOContext *pb = s->pb;
          ^
1179.     int64_t header_byte_count_offset;
1180.     unsigned index_byte_count = 0;

libavformat/mxfenc.c:1180:5: 
1178.     ByteIOContext *pb = s->pb;
1179.     int64_t header_byte_count_offset;
1180.     unsigned index_byte_count = 0;
          ^
1181.     uint64_t partition_offset = url_ftell(pb);
1182. 

libavformat/mxfenc.c:1181:5: 
1179.     int64_t header_byte_count_offset;
1180.     unsigned index_byte_count = 0;
1181.     uint64_t partition_offset = url_ftell(pb);
          ^
1182. 
1183.     if (!mxf->edit_unit_byte_count && mxf->edit_units_count)

libavformat/aviobuf.c:186:1: start of procedure url_ftell()
  184. }
  185. 
  186. int64_t url_ftell(ByteIOContext *s)
       ^
  187. {
  188.     return url_fseek(s, 0, SEEK_CUR);

libavformat/aviobuf.c:188:5: Skipping url_fseek(): empty list of specs
  186. int64_t url_ftell(ByteIOContext *s)
  187. {
  188.     return url_fseek(s, 0, SEEK_CUR);
           ^
  189. }
  190. 

libavformat/aviobuf.c:189:1: return from a call to url_ftell
  187. {
  188.     return url_fseek(s, 0, SEEK_CUR);
  189. }
       ^
  190. 
  191. int64_t url_fsize(ByteIOContext *s)

libavformat/mxfenc.c:1183:10: Taking true branch
1181.     uint64_t partition_offset = url_ftell(pb);
1182. 
1183.     if (!mxf->edit_unit_byte_count && mxf->edit_units_count)
               ^
1184.         index_byte_count = 85 + 12+(s->nb_streams+1)*6 +
1185.             12+mxf->edit_units_count*(11+mxf->slice_count*4);

libavformat/mxfenc.c:1183:39: Taking true branch
1181.     uint64_t partition_offset = url_ftell(pb);
1182. 
1183.     if (!mxf->edit_unit_byte_count && mxf->edit_units_count)
                                            ^
1184.         index_byte_count = 85 + 12+(s->nb_streams+1)*6 +
1185.             12+mxf->edit_units_count*(11+mxf->slice_count*4);

libavformat/mxfenc.c:1184:9: 
1182. 
1183.     if (!mxf->edit_unit_byte_count && mxf->edit_units_count)
1184.         index_byte_count = 85 + 12+(s->nb_streams+1)*6 +
              ^
1185.             12+mxf->edit_units_count*(11+mxf->slice_count*4);
1186.     else if (mxf->edit_unit_byte_count && indexsid)

libavformat/mxfenc.c:1189:9: Taking true branch
1187.         index_byte_count = 80;
1188. 
1189.     if (index_byte_count) {
              ^
1190.         // add encoded ber length
1191.         index_byte_count += 16 + klv_ber_length(index_byte_count);

libavformat/mxfenc.c:1191:9: 
1189.     if (index_byte_count) {
1190.         // add encoded ber length
1191.         index_byte_count += 16 + klv_ber_length(index_byte_count);
              ^
1192.         index_byte_count += klv_fill_size(index_byte_count);
1193.     }

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

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

libavformat/mxfenc.c:333:9: 
  331.         return 1;
  332.     else
  333.         return (av_log2(len) >> 3) + 2;
               ^
  334. }
  335. 

libavutil/common.h:135:1: start of procedure av_log2()
    133. extern const uint8_t ff_log2_tab[256];
    134. 
    135. static inline av_const int av_log2(unsigned int v)
         ^
    136. {
    137.     int n = 0;

libavutil/common.h:137:5: 
    135. static inline av_const int av_log2(unsigned int v)
    136. {
    137.     int n = 0;
             ^
    138.     if (v & 0xffff0000) {
    139.         v >>= 16;

libavutil/common.h:138:9: Taking true branch
    136. {
    137.     int n = 0;
    138.     if (v & 0xffff0000) {
                 ^
    139.         v >>= 16;
    140.         n += 16;

libavutil/common.h:139:9: 
    137.     int n = 0;
    138.     if (v & 0xffff0000) {
    139.         v >>= 16;
                 ^
    140.         n += 16;
    141.     }

libavutil/common.h:140:9: 
    138.     if (v & 0xffff0000) {
    139.         v >>= 16;
    140.         n += 16;
                 ^
    141.     }
    142.     if (v & 0xff00) {

libavutil/common.h:142:9: Taking false branch
    140.         n += 16;
    141.     }
    142.     if (v & 0xff00) {
                 ^
    143.         v >>= 8;
    144.         n += 8;

libavutil/common.h:146:5: 
    144.         n += 8;
    145.     }
    146.     n += ff_log2_tab[v];
             ^
    147. 
    148.     return n;

libavutil/common.h:148:5: 
    146.     n += ff_log2_tab[v];
    147. 
    148.     return n;
             ^
    149. }
    150. 

libavutil/common.h:149:1: return from a call to av_log2
    147. 
    148.     return n;
    149. }
         ^
    150. 
    151. static inline av_const int av_log2_16bit(unsigned int v)

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

libavformat/mxfenc.c:1192:9: 
1190.         // add encoded ber length
1191.         index_byte_count += 16 + klv_ber_length(index_byte_count);
1192.         index_byte_count += klv_fill_size(index_byte_count);
              ^
1193.     }
1194. 

libavformat/mxfenc.c:1021:1: start of procedure klv_fill_size()
  1019. }
  1020. 
  1021. static unsigned klv_fill_size(uint64_t size)
        ^
  1022. {
  1023.     unsigned pad = KAG_SIZE - (size & (KAG_SIZE-1));

libavformat/mxfenc.c:1023:5: 
  1021. static unsigned klv_fill_size(uint64_t size)
  1022. {
  1023.     unsigned pad = KAG_SIZE - (size & (KAG_SIZE-1));
            ^
  1024.     if (pad < 20) // smallest fill item possible
  1025.         return pad + KAG_SIZE;

libavformat/mxfenc.c:1024:9: Taking false branch
  1022. {
  1023.     unsigned pad = KAG_SIZE - (size & (KAG_SIZE-1));
  1024.     if (pad < 20) // smallest fill item possible
                ^
  1025.         return pad + KAG_SIZE;
  1026.     else

libavformat/mxfenc.c:1027:9: 
  1025.         return pad + KAG_SIZE;
  1026.     else
  1027.         return pad & (KAG_SIZE-1);
                ^
  1028. }
  1029. 

libavformat/mxfenc.c:1028:1: return from a call to klv_fill_size
  1026.     else
  1027.         return pad & (KAG_SIZE-1);
  1028. }
        ^
  1029. 
  1030. static void mxf_write_index_table_segment(AVFormatContext *s)

libavformat/mxfenc.c:1195:10: Taking true branch
1193.     }
1194. 
1195.     if (!memcmp(key, body_partition_key, 16)) {
               ^
1196.         mxf->body_partition_offset =
1197.             av_realloc(mxf->body_partition_offset,

libavformat/mxfenc.c:1196:9: 
1194. 
1195.     if (!memcmp(key, body_partition_key, 16)) {
1196.         mxf->body_partition_offset =
              ^
1197.             av_realloc(mxf->body_partition_offset,
1198.                        (mxf->body_partitions_count+1)*

libavutil/mem.c:102:1: start of procedure av_realloc()
  100. }
  101. 
  102. void *av_realloc(void *ptr, unsigned int size)
       ^
  103. {
  104. #if CONFIG_MEMALIGN_HACK

libavutil/mem.c:109:8: Taking true branch
  107. 
  108.     /* let's disallow possible ambiguous cases */
  109.     if(size > (INT_MAX-16) )
              ^
  110.         return NULL;
  111. 

libavutil/mem.c:110:9: 
  108.     /* let's disallow possible ambiguous cases */
  109.     if(size > (INT_MAX-16) )
  110.         return NULL;
               ^
  111. 
  112. #if CONFIG_MEMALIGN_HACK

libavutil/mem.c:120:1: return from a call to av_realloc
  118.     return realloc(ptr, size);
  119. #endif
  120. }
       ^
  121. 
  122. void av_free(void *ptr)

libavformat/mxfenc.c:1200:9: 
1198.                        (mxf->body_partitions_count+1)*
1199.                        sizeof(*mxf->body_partition_offset));
1200.         mxf->body_partition_offset[mxf->body_partitions_count++] = partition_offset;
              ^
1201.     }
1202. 

static void mxf_write_partition(AVFormatContext *s, int bodysid,
                                int indexsid,
                                const uint8_t *key, int write_metadata)
{
    MXFContext *mxf = s->priv_data;
    ByteIOContext *pb = s->pb;
    int64_t header_byte_count_offset;
    unsigned index_byte_count = 0;
    uint64_t partition_offset = url_ftell(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;
    }
    put_buffer(pb, key, 16);
    klv_encode_ber_length(pb, 88 + 16 * mxf->essence_container_count);
    put_be16(pb, 1);
    put_be16(pb, 2);
    put_be32(pb, KAG_SIZE);
    put_be64(pb, partition_offset);
    if (!memcmp(key, body_partition_key, 16) && mxf->body_partitions_count > 1)
        put_be64(pb, mxf->body_partition_offset[mxf->body_partitions_count-2]);
    else if (!memcmp(key, footer_partition_key, 16) && mxf->body_partitions_count)
        put_be64(pb, mxf->body_partition_offset[mxf->body_partitions_count-1]);
    else
        put_be64(pb, 0);
    put_be64(pb, mxf->footer_partition_offset);
    header_byte_count_offset = url_ftell(pb);
    put_be64(pb, 0);
    put_be64(pb, index_byte_count);
    put_be32(pb, index_byte_count ? indexsid : 0);
    if (bodysid && mxf->edit_units_count && mxf->body_partitions_count) {
        put_be64(pb, mxf->body_offset);
    } else
        put_be64(pb, 0);
    put_be32(pb, bodysid);
    put_buffer(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 = url_ftell(s->pb);
        mxf_write_primer_pack(s);
        mxf_write_header_metadata_sets(s);
        pos = url_ftell(s->pb);
        header_byte_count = pos - start + klv_fill_size(pos);
        url_fseek(pb, header_byte_count_offset, SEEK_SET);
        put_be64(pb, header_byte_count);
        url_fseek(pb, pos, SEEK_SET);
    }
    put_flush_packet(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    ByteIOContext *pb = s->pb;\n    int64_t header_byte_count_offset;\n    unsigned index_byte_count = 0;\n    uint64_t partition_offset = url_ftell(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    put_buffer(pb, key, 16);\n    klv_encode_ber_length(pb, 88 + 16 * mxf->essence_container_count);\n    put_be16(pb, 1);\n    put_be16(pb, 2);\n    put_be32(pb, KAG_SIZE);\n    put_be64(pb, partition_offset);\n    if (!memcmp(key, body_partition_key, 16) && mxf->body_partitions_count > 1)\n        put_be64(pb, mxf->body_partition_offset[mxf->body_partitions_count-2]);\n    else if (!memcmp(key, footer_partition_key, 16) && mxf->body_partitions_count)\n        put_be64(pb, mxf->body_partition_offset[mxf->body_partitions_count-1]);\n    else\n        put_be64(pb, 0);\n    put_be64(pb, mxf->footer_partition_offset);\n    header_byte_count_offset = url_ftell(pb);\n    put_be64(pb, 0);\n    put_be64(pb, index_byte_count);\n    put_be32(pb, index_byte_count ? indexsid : 0);\n    if (bodysid && mxf->edit_units_count && mxf->body_partitions_count) {\n        put_be64(pb, mxf->body_offset);\n    } else\n        put_be64(pb, 0);\n    put_be32(pb, bodysid);\n    put_buffer(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 = url_ftell(s->pb);\n        mxf_write_primer_pack(s);\n        mxf_write_header_metadata_sets(s);\n        pos = url_ftell(s->pb);\n        header_byte_count = pos - start + klv_fill_size(pos);\n        url_fseek(pb, header_byte_count_offset, SEEK_SET);\n        put_be64(pb, header_byte_count);\n        url_fseek(pb, pos, SEEK_SET);\n    }\n    put_flush_packet(pb);\n}', 'int64_t url_ftell(ByteIOContext *s)\n{\n    return url_fseek(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 inline av_const int av_log2(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, unsigned int 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}']