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

libavformat/mxfenc.c:1165:1: start of procedure mxf_write_partition()
1163. }
1164. 
1165. static void mxf_write_partition(AVFormatContext *s, int bodysid,
      ^
1166.                                 int indexsid,
1167.                                 const uint8_t *key, int write_metadata)

libavformat/mxfenc.c:1169:5: 
1167.                                 const uint8_t *key, int write_metadata)
1168. {
1169.     MXFContext *mxf = s->priv_data;
          ^
1170.     ByteIOContext *pb = s->pb;
1171.     int64_t header_byte_count_offset;

libavformat/mxfenc.c:1170:5: 
1168. {
1169.     MXFContext *mxf = s->priv_data;
1170.     ByteIOContext *pb = s->pb;
          ^
1171.     int64_t header_byte_count_offset;
1172.     unsigned index_byte_count = 0;

libavformat/mxfenc.c:1172:5: 
1170.     ByteIOContext *pb = s->pb;
1171.     int64_t header_byte_count_offset;
1172.     unsigned index_byte_count = 0;
          ^
1173.     uint64_t partition_offset = url_ftell(pb);
1174. 

libavformat/mxfenc.c:1173:5: 
1171.     int64_t header_byte_count_offset;
1172.     unsigned index_byte_count = 0;
1173.     uint64_t partition_offset = url_ftell(pb);
          ^
1174. 
1175.     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:1175:10: Taking true branch
1173.     uint64_t partition_offset = url_ftell(pb);
1174. 
1175.     if (!mxf->edit_unit_byte_count && mxf->edit_units_count)
               ^
1176.         index_byte_count = 85 + 12+(s->nb_streams+1)*6 +
1177.             12+mxf->edit_units_count*(11+mxf->slice_count*4);

libavformat/mxfenc.c:1175:39: Taking true branch
1173.     uint64_t partition_offset = url_ftell(pb);
1174. 
1175.     if (!mxf->edit_unit_byte_count && mxf->edit_units_count)
                                            ^
1176.         index_byte_count = 85 + 12+(s->nb_streams+1)*6 +
1177.             12+mxf->edit_units_count*(11+mxf->slice_count*4);

libavformat/mxfenc.c:1176:9: 
1174. 
1175.     if (!mxf->edit_unit_byte_count && mxf->edit_units_count)
1176.         index_byte_count = 85 + 12+(s->nb_streams+1)*6 +
              ^
1177.             12+mxf->edit_units_count*(11+mxf->slice_count*4);
1178.     else if (mxf->edit_unit_byte_count && indexsid)

libavformat/mxfenc.c:1181:9: Taking true branch
1179.         index_byte_count = 80;
1180. 
1181.     if (index_byte_count) {
              ^
1182.         // add encoded ber length
1183.         index_byte_count += 16 + klv_ber_length(index_byte_count);

libavformat/mxfenc.c:1183:9: 
1181.     if (index_byte_count) {
1182.         // add encoded ber length
1183.         index_byte_count += 16 + klv_ber_length(index_byte_count);
              ^
1184.         index_byte_count += klv_fill_size(index_byte_count);
1185.     }

libavformat/mxfenc.c:322:1: start of procedure klv_ber_length()
  320. }
  321. 
  322. static int klv_ber_length(uint64_t len)
       ^
  323. {
  324.     if (len < 128)

libavformat/mxfenc.c:324:9: Taking false branch
  322. static int klv_ber_length(uint64_t len)
  323. {
  324.     if (len < 128)
               ^
  325.         return 1;
  326.     else

libavformat/mxfenc.c:327:9: 
  325.         return 1;
  326.     else
  327.         return (av_log2(len) >> 3) + 2;
               ^
  328. }
  329. 

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

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

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

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

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

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

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

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

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

libavformat/mxfenc.c:328:1: return from a call to klv_ber_length
  326.     else
  327.         return (av_log2(len) >> 3) + 2;
  328. }
       ^
  329. 
  330. static int klv_encode_ber_length(ByteIOContext *pb, uint64_t len)

libavformat/mxfenc.c:1184:9: 
1182.         // add encoded ber length
1183.         index_byte_count += 16 + klv_ber_length(index_byte_count);
1184.         index_byte_count += klv_fill_size(index_byte_count);
              ^
1185.     }
1186. 

libavformat/mxfenc.c:1015:1: start of procedure klv_fill_size()
  1013. }
  1014. 
  1015. static unsigned klv_fill_size(uint64_t size)
        ^
  1016. {
  1017.     unsigned pad = KAG_SIZE - (size & (KAG_SIZE-1));

libavformat/mxfenc.c:1017:5: 
  1015. static unsigned klv_fill_size(uint64_t size)
  1016. {
  1017.     unsigned pad = KAG_SIZE - (size & (KAG_SIZE-1));
            ^
  1018.     if (pad < 20) // smallest fill item possible
  1019.         return pad + KAG_SIZE;

libavformat/mxfenc.c:1018:9: Taking false branch
  1016. {
  1017.     unsigned pad = KAG_SIZE - (size & (KAG_SIZE-1));
  1018.     if (pad < 20) // smallest fill item possible
                ^
  1019.         return pad + KAG_SIZE;
  1020.     else

libavformat/mxfenc.c:1021:9: 
  1019.         return pad + KAG_SIZE;
  1020.     else
  1021.         return pad & (KAG_SIZE-1);
                ^
  1022. }
  1023. 

libavformat/mxfenc.c:1022:1: return from a call to klv_fill_size
  1020.     else
  1021.         return pad & (KAG_SIZE-1);
  1022. }
        ^
  1023. 
  1024. static void mxf_write_index_table_segment(AVFormatContext *s)

libavformat/mxfenc.c:1187:10: Taking true branch
1185.     }
1186. 
1187.     if (!memcmp(key, body_partition_key, 16)) {
               ^
1188.         mxf->body_partition_offset =
1189.             av_realloc(mxf->body_partition_offset,

libavformat/mxfenc.c:1188:9: 
1186. 
1187.     if (!memcmp(key, body_partition_key, 16)) {
1188.         mxf->body_partition_offset =
              ^
1189.             av_realloc(mxf->body_partition_offset,
1190.                        (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 false branch
  107. 
  108.     /* let's disallow possible ambiguous cases */
  109.     if(size > (INT_MAX-16) )
              ^
  110.         return NULL;
  111. 

libavutil/mem.c:118:5: 
  116.     return (char*)realloc((char*)ptr - diff, size + diff) + diff;
  117. #else
  118.     return realloc(ptr, size);
           ^
  119. #endif
  120. }

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:1192:9: 
1190.                        (mxf->body_partitions_count+1)*
1191.                        sizeof(*mxf->body_partition_offset));
1192.         mxf->body_partition_offset[mxf->body_partitions_count++] = partition_offset;
              ^
1193.     }
1194. 

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}']