libavformat/movenc.c:2072: error: Null Dereference
  pointer `pkt.data` last assigned on line 2071 could be null and is dereferenced at line 2072, column 13.

libavformat/movenc.c:2047:1: start of procedure mov_create_chapter_track()
2045. // QuickTime chapters involve an additional text track with the chapter names
2046. // as samples, and a tref pointing from the other tracks to the chapter one.
2047. static void mov_create_chapter_track(AVFormatContext *s, int tracknum)
      ^
2048. {
2049.     MOVMuxContext *mov = s->priv_data;

libavformat/movenc.c:2049:5: 
2047. static void mov_create_chapter_track(AVFormatContext *s, int tracknum)
2048. {
2049.     MOVMuxContext *mov = s->priv_data;
          ^
2050.     MOVTrack *track = &mov->tracks[tracknum];
2051.     AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY };

libavformat/movenc.c:2050:5: 
2048. {
2049.     MOVMuxContext *mov = s->priv_data;
2050.     MOVTrack *track = &mov->tracks[tracknum];
          ^
2051.     AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY };
2052.     int i, len;

libavformat/movenc.c:2051:5: 
2049.     MOVMuxContext *mov = s->priv_data;
2050.     MOVTrack *track = &mov->tracks[tracknum];
2051.     AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY };
          ^
2052.     int i, len;
2053. 

libavformat/movenc.c:2054:5: 
2052.     int i, len;
2053. 
2054.     track->mode = mov->mode;
          ^
2055.     track->tag = MKTAG('t','e','x','t');
2056.     track->timescale = MOV_TIMESCALE;

libavformat/movenc.c:2055:5: 
2053. 
2054.     track->mode = mov->mode;
2055.     track->tag = MKTAG('t','e','x','t');
          ^
2056.     track->timescale = MOV_TIMESCALE;
2057.     track->enc = avcodec_alloc_context();

libavformat/movenc.c:2056:5: 
2054.     track->mode = mov->mode;
2055.     track->tag = MKTAG('t','e','x','t');
2056.     track->timescale = MOV_TIMESCALE;
          ^
2057.     track->enc = avcodec_alloc_context();
2058.     track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;

libavformat/movenc.c:2057:5: 
2055.     track->tag = MKTAG('t','e','x','t');
2056.     track->timescale = MOV_TIMESCALE;
2057.     track->enc = avcodec_alloc_context();
          ^
2058.     track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
2059. 

libavcodec/options.c:530:1: start of procedure avcodec_alloc_context()
  528. }
  529. 
  530. AVCodecContext *avcodec_alloc_context(void){
       ^
  531.     return avcodec_alloc_context2(AVMEDIA_TYPE_UNKNOWN);
  532. }

libavcodec/options.c:531:5: 
  529. 
  530. AVCodecContext *avcodec_alloc_context(void){
  531.     return avcodec_alloc_context2(AVMEDIA_TYPE_UNKNOWN);
           ^
  532. }
  533. 

libavcodec/options.c:516:1: start of procedure avcodec_alloc_context2()
    514. }
    515. 
    516. AVCodecContext *avcodec_alloc_context2(enum AVMediaType codec_type){
         ^
    517.     AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
    518. 

libavcodec/options.c:517:5: 
    515. 
    516. AVCodecContext *avcodec_alloc_context2(enum AVMediaType codec_type){
    517.     AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
             ^
    518. 
    519.     if(avctx==NULL) return NULL;

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

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

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

libavutil/mem.c:83:9: Taking false branch
      81.     ((char*)ptr)[-1]= diff;
      82. #elif HAVE_POSIX_MEMALIGN
      83.     if (posix_memalign(&ptr,32,size))
                  ^
      84.         ptr = NULL;
      85. #elif HAVE_MEMALIGN

libavutil/mem.c:114:5: 
      112.     ptr = malloc(size);
      113. #endif
      114.     return ptr;
               ^
      115. }
      116. 

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

libavcodec/options.c:519:8: Taking false branch
    517.     AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
    518. 
    519.     if(avctx==NULL) return NULL;
                ^
    520. 
    521.     avcodec_get_context_defaults2(avctx, codec_type);

libavcodec/options.c:521:5: Skipping avcodec_get_context_defaults2(): empty list of specs
    519.     if(avctx==NULL) return NULL;
    520. 
    521.     avcodec_get_context_defaults2(avctx, codec_type);
             ^
    522. 
    523.     return avctx;

libavcodec/options.c:523:5: 
    521.     avcodec_get_context_defaults2(avctx, codec_type);
    522. 
    523.     return avctx;
             ^
    524. }
    525. 

libavcodec/options.c:524:1: return from a call to avcodec_alloc_context2
    522. 
    523.     return avctx;
    524. }
         ^
    525. 
    526. void avcodec_get_context_defaults(AVCodecContext *s){

libavcodec/options.c:532:1: return from a call to avcodec_alloc_context
  530. AVCodecContext *avcodec_alloc_context(void){
  531.     return avcodec_alloc_context2(AVMEDIA_TYPE_UNKNOWN);
  532. }
       ^
  533. 
  534. int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)

libavformat/movenc.c:2058:5: 
2056.     track->timescale = MOV_TIMESCALE;
2057.     track->enc = avcodec_alloc_context();
2058.     track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
          ^
2059. 
2060.     for (i = 0; i < s->nb_chapters; i++) {

libavformat/movenc.c:2060:10: 
2058.     track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
2059. 
2060.     for (i = 0; i < s->nb_chapters; i++) {
               ^
2061.         AVChapter *c = s->chapters[i];
2062.         AVMetadataTag *t;

libavformat/movenc.c:2060:17: Loop condition is true. Entering loop body
2058.     track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
2059. 
2060.     for (i = 0; i < s->nb_chapters; i++) {
                      ^
2061.         AVChapter *c = s->chapters[i];
2062.         AVMetadataTag *t;

libavformat/movenc.c:2061:9: 
2059. 
2060.     for (i = 0; i < s->nb_chapters; i++) {
2061.         AVChapter *c = s->chapters[i];
              ^
2062.         AVMetadataTag *t;
2063. 

libavformat/movenc.c:2064:9: 
2062.         AVMetadataTag *t;
2063. 
2064.         int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE});
              ^
2065.         pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE});
2066.         pkt.duration = end - pkt.dts;

libavutil/mathematics.c:133:1: start of procedure av_rescale_q()
  131. }
  132. 
  133. int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
       ^
  134.     int64_t b= bq.num * (int64_t)cq.den;
  135.     int64_t c= cq.num * (int64_t)bq.den;

libavutil/mathematics.c:134:5: 
  132. 
  133. int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
  134.     int64_t b= bq.num * (int64_t)cq.den;
           ^
  135.     int64_t c= cq.num * (int64_t)bq.den;
  136.     return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);

libavutil/mathematics.c:135:5: 
  133. int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
  134.     int64_t b= bq.num * (int64_t)cq.den;
  135.     int64_t c= cq.num * (int64_t)bq.den;
           ^
  136.     return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
  137. }

libavutil/mathematics.c:136:5: Skipping av_rescale_rnd(): empty list of specs
  134.     int64_t b= bq.num * (int64_t)cq.den;
  135.     int64_t c= cq.num * (int64_t)bq.den;
  136.     return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
           ^
  137. }
  138. 

libavutil/mathematics.c:137:1: return from a call to av_rescale_q
  135.     int64_t c= cq.num * (int64_t)bq.den;
  136.     return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
  137. }
       ^
  138. 
  139. int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){

libavformat/movenc.c:2065:9: 
2063. 
2064.         int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE});
2065.         pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE});
              ^
2066.         pkt.duration = end - pkt.dts;
2067. 

libavutil/mathematics.c:133:1: start of procedure av_rescale_q()
  131. }
  132. 
  133. int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
       ^
  134.     int64_t b= bq.num * (int64_t)cq.den;
  135.     int64_t c= cq.num * (int64_t)bq.den;

libavutil/mathematics.c:134:5: 
  132. 
  133. int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
  134.     int64_t b= bq.num * (int64_t)cq.den;
           ^
  135.     int64_t c= cq.num * (int64_t)bq.den;
  136.     return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);

libavutil/mathematics.c:135:5: 
  133. int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
  134.     int64_t b= bq.num * (int64_t)cq.den;
  135.     int64_t c= cq.num * (int64_t)bq.den;
           ^
  136.     return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
  137. }

libavutil/mathematics.c:136:5: Skipping av_rescale_rnd(): empty list of specs
  134.     int64_t b= bq.num * (int64_t)cq.den;
  135.     int64_t c= cq.num * (int64_t)bq.den;
  136.     return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
           ^
  137. }
  138. 

libavutil/mathematics.c:137:1: return from a call to av_rescale_q
  135.     int64_t c= cq.num * (int64_t)bq.den;
  136.     return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
  137. }
       ^
  138. 
  139. int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){

libavformat/movenc.c:2066:9: 
2064.         int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE});
2065.         pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE});
2066.         pkt.duration = end - pkt.dts;
              ^
2067. 
2068.         if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) {

libavformat/movenc.c:2068:14: Taking true branch
2066.         pkt.duration = end - pkt.dts;
2067. 
2068.         if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) {
                   ^
2069.             len = strlen(t->value);
2070.             pkt.size = len+2;

libavformat/movenc.c:2069:13: 
2067. 
2068.         if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) {
2069.             len = strlen(t->value);
                  ^
2070.             pkt.size = len+2;
2071.             pkt.data = av_malloc(pkt.size);

libavformat/movenc.c:2070:13: 
2068.         if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) {
2069.             len = strlen(t->value);
2070.             pkt.size = len+2;
                  ^
2071.             pkt.data = av_malloc(pkt.size);
2072.             AV_WB16(pkt.data, len);

libavformat/movenc.c:2071:13: 
2069.             len = strlen(t->value);
2070.             pkt.size = len+2;
2071.             pkt.data = av_malloc(pkt.size);
                  ^
2072.             AV_WB16(pkt.data, len);
2073.             memcpy(pkt.data+2, t->value, len);

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

libavutil/mem.c:66:5: 
  64. void *av_malloc(size_t 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-32) )
             ^
  73.         return NULL;
  74. 

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

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

libavformat/movenc.c:2072:13: 
2070.             pkt.size = len+2;
2071.             pkt.data = av_malloc(pkt.size);
2072.             AV_WB16(pkt.data, len);
                  ^
2073.             memcpy(pkt.data+2, t->value, len);
2074.             ff_mov_write_packet(s, &pkt);

libavutil/bswap.h:58:1: start of procedure av_bswap16()
  56. 
  57. #ifndef av_bswap16
  58. static av_always_inline av_const uint16_t av_bswap16(uint16_t x)
      ^
  59. {
  60.     x= (x>>8) | (x<<8);

libavutil/bswap.h:60:5: 
  58. static av_always_inline av_const uint16_t av_bswap16(uint16_t x)
  59. {
  60.     x= (x>>8) | (x<<8);
          ^
  61.     return x;
  62. }

libavutil/bswap.h:61:5: 
  59. {
  60.     x= (x>>8) | (x<<8);
  61.     return x;
          ^
  62. }
  63. #endif

libavutil/bswap.h:62:1: return from a call to av_bswap16
  60.     x= (x>>8) | (x<<8);
  61.     return x;
  62. }
      ^
  63. #endif
  64. 

static void mov_create_chapter_track(AVFormatContext *s, int tracknum)
{
    MOVMuxContext *mov = s->priv_data;
    MOVTrack *track = &mov->tracks[tracknum];
    AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY };
    int i, len;
    track->mode = mov->mode;
    track->tag = MKTAG('t','e','x','t');
    track->timescale = MOV_TIMESCALE;
    track->enc = avcodec_alloc_context();
    track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
    for (i = 0; i < s->nb_chapters; i++) {
        AVChapter *c = s->chapters[i];
        AVMetadataTag *t;
        int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE});
        pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE});
        pkt.duration = end - pkt.dts;
        if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) {
            len = strlen(t->value);
            pkt.size = len+2;
            pkt.data = av_malloc(pkt.size);
            AV_WB16(pkt.data, len);
            memcpy(pkt.data+2, t->value, len);
            ff_mov_write_packet(s, &pkt);
            av_freep(&pkt.data);
        }
    }
}
['static void mov_create_chapter_track(AVFormatContext *s, int tracknum)\n{\n    MOVMuxContext *mov = s->priv_data;\n    MOVTrack *track = &mov->tracks[tracknum];\n    AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY };\n    int i, len;\n    track->mode = mov->mode;\n    track->tag = MKTAG(\'t\',\'e\',\'x\',\'t\');\n    track->timescale = MOV_TIMESCALE;\n    track->enc = avcodec_alloc_context();\n    track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;\n    for (i = 0; i < s->nb_chapters; i++) {\n        AVChapter *c = s->chapters[i];\n        AVMetadataTag *t;\n        int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE});\n        pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE});\n        pkt.duration = end - pkt.dts;\n        if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) {\n            len = strlen(t->value);\n            pkt.size = len+2;\n            pkt.data = av_malloc(pkt.size);\n            AV_WB16(pkt.data, len);\n            memcpy(pkt.data+2, t->value, len);\n            ff_mov_write_packet(s, &pkt);\n            av_freep(&pkt.data);\n        }\n    }\n}', 'AVCodecContext *avcodec_alloc_context(void){\n    return avcodec_alloc_context2(AVMEDIA_TYPE_UNKNOWN);\n}', 'AVCodecContext *avcodec_alloc_context2(enum AVMediaType codec_type){\n    AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));\n    if(avctx==NULL) return NULL;\n    avcodec_get_context_defaults2(avctx, codec_type);\n    return avctx;\n}', 'void *av_malloc(size_t size)\n{\n    void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n    long diff;\n#endif\n    if(size > (INT_MAX-32) )\n        return NULL;\n#if CONFIG_MEMALIGN_HACK\n    ptr = malloc(size+32);\n    if(!ptr)\n        return ptr;\n    diff= ((-(long)ptr - 1)&31) + 1;\n    ptr = (char*)ptr + diff;\n    ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n    if (posix_memalign(&ptr,32,size))\n        ptr = NULL;\n#elif HAVE_MEMALIGN\n    ptr = memalign(32,size);\n#else\n    ptr = malloc(size);\n#endif\n    return ptr;\n}', 'int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){\n    int64_t b= bq.num * (int64_t)cq.den;\n    int64_t c= cq.num * (int64_t)bq.den;\n    return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);\n}', 'static av_always_inline av_const uint16_t av_bswap16(uint16_t x)\n{\n    x= (x>>8) | (x<<8);\n    return x;\n}']