libavformat/matroskaenc.c:687: error: Null Dereference
  pointer `mkv->md5_ctx` last assigned on line 686 could be null and is dereferenced by call to `av_md5_init()` at line 687, column 5.

libavformat/matroskaenc.c:678:1: start of procedure mkv_write_header()
676. }
677. 
678. static int mkv_write_header(AVFormatContext *s)
     ^
679. {
680.     MatroskaMuxContext *mkv = s->priv_data;

libavformat/matroskaenc.c:680:5: 
678. static int mkv_write_header(AVFormatContext *s)
679. {
680.     MatroskaMuxContext *mkv = s->priv_data;
         ^
681.     ByteIOContext *pb = s->pb;
682.     ebml_master ebml_header, segment_info;

libavformat/matroskaenc.c:681:5: 
679. {
680.     MatroskaMuxContext *mkv = s->priv_data;
681.     ByteIOContext *pb = s->pb;
         ^
682.     ebml_master ebml_header, segment_info;
683.     AVMetadataTag *tag;

libavformat/matroskaenc.c:686:5: 
684.     int ret;
685. 
686.     mkv->md5_ctx = av_mallocz(av_md5_size);
         ^
687.     av_md5_init(mkv->md5_ctx);
688.     mkv->tracks = av_mallocz(s->nb_streams * sizeof(*mkv->tracks));

libavutil/mem.c:157:1: start of procedure av_mallocz()
  155. }
  156. 
  157. void *av_mallocz(unsigned int size)
       ^
  158. {
  159.     void *ptr = av_malloc(size);

libavutil/mem.c:159:5: 
  157. void *av_mallocz(unsigned int size)
  158. {
  159.     void *ptr = av_malloc(size);
           ^
  160.     if (ptr)
  161.         memset(ptr, 0, size);

libavutil/mem.c:64:1: start of procedure av_malloc()
    62.    linker will do it automatically. */
    63. 
    64. void *av_malloc(unsigned int size)
        ^
    65. {
    66.     void *ptr = NULL;

libavutil/mem.c:66:5: 
    64. void *av_malloc(unsigned int size)
    65. {
    66.     void *ptr = NULL;
            ^
    67. #if CONFIG_MEMALIGN_HACK
    68.     long diff;

libavutil/mem.c:72:8: Taking true branch
    70. 
    71.     /* let's disallow possible ambiguous cases */
    72.     if(size > (INT_MAX-16) )
               ^
    73.         return NULL;
    74. 

libavutil/mem.c:73:9: 
    71.     /* let's disallow possible ambiguous cases */
    72.     if(size > (INT_MAX-16) )
    73.         return NULL;
                ^
    74. 
    75. #if CONFIG_MEMALIGN_HACK

libavutil/mem.c:117:1: return from a call to av_malloc
    115. #endif
    116.     return ptr;
    117. }
         ^
    118. 
    119. void *av_realloc(void *ptr, unsigned int size)

libavutil/mem.c:160:9: Taking false branch
  158. {
  159.     void *ptr = av_malloc(size);
  160.     if (ptr)
               ^
  161.         memset(ptr, 0, size);
  162.     return ptr;

libavutil/mem.c:162:5: 
  160.     if (ptr)
  161.         memset(ptr, 0, size);
  162.     return ptr;
           ^
  163. }
  164. 

libavutil/mem.c:163:1: return from a call to av_mallocz
  161.         memset(ptr, 0, size);
  162.     return ptr;
  163. }
       ^
  164. 
  165. char *av_strdup(const char *s)

libavformat/matroskaenc.c:687:5: 
685. 
686.     mkv->md5_ctx = av_mallocz(av_md5_size);
687.     av_md5_init(mkv->md5_ctx);
         ^
688.     mkv->tracks = av_mallocz(s->nb_streams * sizeof(*mkv->tracks));
689. 

libavutil/md5.c:118:1: start of procedure av_md5_init()
  116. }
  117. 
  118. void av_md5_init(AVMD5 *ctx){
       ^
  119.     ctx->len    = 0;
  120. 

libavutil/md5.c:119:5: 
  117. 
  118. void av_md5_init(AVMD5 *ctx){
  119.     ctx->len    = 0;
           ^
  120. 
  121.     ctx->ABCD[0] = 0x10325476;

static int mkv_write_header(AVFormatContext *s)
{
    MatroskaMuxContext *mkv = s->priv_data;
    ByteIOContext *pb = s->pb;
    ebml_master ebml_header, segment_info;
    AVMetadataTag *tag;
    int ret;
    mkv->md5_ctx = av_mallocz(av_md5_size);
    av_md5_init(mkv->md5_ctx);
    mkv->tracks = av_mallocz(s->nb_streams * sizeof(*mkv->tracks));
    ebml_header = start_ebml_master(pb, EBML_ID_HEADER, 0);
    put_ebml_uint   (pb, EBML_ID_EBMLVERSION        ,           1);
    put_ebml_uint   (pb, EBML_ID_EBMLREADVERSION    ,           1);
    put_ebml_uint   (pb, EBML_ID_EBMLMAXIDLENGTH    ,           4);
    put_ebml_uint   (pb, EBML_ID_EBMLMAXSIZELENGTH  ,           8);
    put_ebml_string (pb, EBML_ID_DOCTYPE            ,  "matroska");
    put_ebml_uint   (pb, EBML_ID_DOCTYPEVERSION     ,           2);
    put_ebml_uint   (pb, EBML_ID_DOCTYPEREADVERSION ,           2);
    end_ebml_master(pb, ebml_header);
    mkv->segment = start_ebml_master(pb, MATROSKA_ID_SEGMENT, 0);
    mkv->segment_offset = url_ftell(pb);
    mkv->main_seekhead    = mkv_start_seekhead(pb, mkv->segment_offset, 10);
    mkv->cluster_seekhead = mkv_start_seekhead(pb, mkv->segment_offset, 0);
    if (mkv->main_seekhead == NULL || mkv->cluster_seekhead == NULL)
        return AVERROR(ENOMEM);
    ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_INFO, url_ftell(pb));
    if (ret < 0) return ret;
    segment_info = start_ebml_master(pb, MATROSKA_ID_INFO, 0);
    put_ebml_uint(pb, MATROSKA_ID_TIMECODESCALE, 1000000);
    if ((tag = av_metadata_get(s->metadata, "title", NULL, 0)))
        put_ebml_string(pb, MATROSKA_ID_TITLE, tag->value);
    if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) {
        put_ebml_string(pb, MATROSKA_ID_MUXINGAPP , LIBAVFORMAT_IDENT);
        put_ebml_string(pb, MATROSKA_ID_WRITINGAPP, LIBAVFORMAT_IDENT);
        mkv->segment_uid = url_ftell(pb);
        put_ebml_void(pb, 19);
    }
    mkv->duration = 0;
    mkv->duration_offset = url_ftell(pb);
    put_ebml_void(pb, 11);
    end_ebml_master(pb, segment_info);
    ret = mkv_write_tracks(s);
    if (ret < 0) return ret;
    ret = mkv_write_chapters(s);
    if (ret < 0) return ret;
    if (url_is_streamed(s->pb))
        mkv_write_seekhead(pb, mkv->main_seekhead);
    mkv->cues = mkv_start_cues(mkv->segment_offset);
    if (mkv->cues == NULL)
        return AVERROR(ENOMEM);
    put_flush_packet(pb);
    return 0;
}
['static int mkv_write_header(AVFormatContext *s)\n{\n    MatroskaMuxContext *mkv = s->priv_data;\n    ByteIOContext *pb = s->pb;\n    ebml_master ebml_header, segment_info;\n    AVMetadataTag *tag;\n    int ret;\n    mkv->md5_ctx = av_mallocz(av_md5_size);\n    av_md5_init(mkv->md5_ctx);\n    mkv->tracks = av_mallocz(s->nb_streams * sizeof(*mkv->tracks));\n    ebml_header = start_ebml_master(pb, EBML_ID_HEADER, 0);\n    put_ebml_uint   (pb, EBML_ID_EBMLVERSION        ,           1);\n    put_ebml_uint   (pb, EBML_ID_EBMLREADVERSION    ,           1);\n    put_ebml_uint   (pb, EBML_ID_EBMLMAXIDLENGTH    ,           4);\n    put_ebml_uint   (pb, EBML_ID_EBMLMAXSIZELENGTH  ,           8);\n    put_ebml_string (pb, EBML_ID_DOCTYPE            ,  "matroska");\n    put_ebml_uint   (pb, EBML_ID_DOCTYPEVERSION     ,           2);\n    put_ebml_uint   (pb, EBML_ID_DOCTYPEREADVERSION ,           2);\n    end_ebml_master(pb, ebml_header);\n    mkv->segment = start_ebml_master(pb, MATROSKA_ID_SEGMENT, 0);\n    mkv->segment_offset = url_ftell(pb);\n    mkv->main_seekhead    = mkv_start_seekhead(pb, mkv->segment_offset, 10);\n    mkv->cluster_seekhead = mkv_start_seekhead(pb, mkv->segment_offset, 0);\n    if (mkv->main_seekhead == NULL || mkv->cluster_seekhead == NULL)\n        return AVERROR(ENOMEM);\n    ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_INFO, url_ftell(pb));\n    if (ret < 0) return ret;\n    segment_info = start_ebml_master(pb, MATROSKA_ID_INFO, 0);\n    put_ebml_uint(pb, MATROSKA_ID_TIMECODESCALE, 1000000);\n    if ((tag = av_metadata_get(s->metadata, "title", NULL, 0)))\n        put_ebml_string(pb, MATROSKA_ID_TITLE, tag->value);\n    if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) {\n        put_ebml_string(pb, MATROSKA_ID_MUXINGAPP , LIBAVFORMAT_IDENT);\n        put_ebml_string(pb, MATROSKA_ID_WRITINGAPP, LIBAVFORMAT_IDENT);\n        mkv->segment_uid = url_ftell(pb);\n        put_ebml_void(pb, 19);\n    }\n    mkv->duration = 0;\n    mkv->duration_offset = url_ftell(pb);\n    put_ebml_void(pb, 11);\n    end_ebml_master(pb, segment_info);\n    ret = mkv_write_tracks(s);\n    if (ret < 0) return ret;\n    ret = mkv_write_chapters(s);\n    if (ret < 0) return ret;\n    if (url_is_streamed(s->pb))\n        mkv_write_seekhead(pb, mkv->main_seekhead);\n    mkv->cues = mkv_start_cues(mkv->segment_offset);\n    if (mkv->cues == NULL)\n        return AVERROR(ENOMEM);\n    put_flush_packet(pb);\n    return 0;\n}', 'void *av_mallocz(unsigned int size)\n{\n    void *ptr = av_malloc(size);\n    if (ptr)\n        memset(ptr, 0, size);\n    return ptr;\n}', 'void *av_malloc(unsigned int size)\n{\n    void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n    long diff;\n#endif\n    if(size > (INT_MAX-16) )\n        return NULL;\n#if CONFIG_MEMALIGN_HACK\n    ptr = malloc(size+16);\n    if(!ptr)\n        return ptr;\n    diff= ((-(long)ptr - 1)&15) + 1;\n    ptr = (char*)ptr + diff;\n    ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n    if (posix_memalign(&ptr,16,size))\n        ptr = NULL;\n#elif HAVE_MEMALIGN\n    ptr = memalign(16,size);\n#else\n    ptr = malloc(size);\n#endif\n    return ptr;\n}', 'void av_md5_init(AVMD5 *ctx){\n    ctx->len    = 0;\n    ctx->ABCD[0] = 0x10325476;\n    ctx->ABCD[1] = 0x98badcfe;\n    ctx->ABCD[2] = 0xefcdab89;\n    ctx->ABCD[3] = 0x67452301;\n}']