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

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

libavformat/movenc.c:2979:5: 
2977. static void mov_create_chapter_track(AVFormatContext *s, int tracknum)
2978. {
2979.     MOVMuxContext *mov = s->priv_data;
          ^
2980.     MOVTrack *track = &mov->tracks[tracknum];
2981.     AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY };

libavformat/movenc.c:2980:5: 
2978. {
2979.     MOVMuxContext *mov = s->priv_data;
2980.     MOVTrack *track = &mov->tracks[tracknum];
          ^
2981.     AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY };
2982.     int i, len;

libavformat/movenc.c:2981:5: 
2979.     MOVMuxContext *mov = s->priv_data;
2980.     MOVTrack *track = &mov->tracks[tracknum];
2981.     AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY };
          ^
2982.     int i, len;
2983. 

libavformat/movenc.c:2984:5: 
2982.     int i, len;
2983. 
2984.     track->mode = mov->mode;
          ^
2985.     track->tag = MKTAG('t','e','x','t');
2986.     track->timescale = MOV_TIMESCALE;

libavformat/movenc.c:2985:5: 
2983. 
2984.     track->mode = mov->mode;
2985.     track->tag = MKTAG('t','e','x','t');
          ^
2986.     track->timescale = MOV_TIMESCALE;
2987.     track->enc = avcodec_alloc_context3(NULL);

libavformat/movenc.c:2986:5: 
2984.     track->mode = mov->mode;
2985.     track->tag = MKTAG('t','e','x','t');
2986.     track->timescale = MOV_TIMESCALE;
          ^
2987.     track->enc = avcodec_alloc_context3(NULL);
2988.     track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;

libavformat/movenc.c:2987:5: 
2985.     track->tag = MKTAG('t','e','x','t');
2986.     track->timescale = MOV_TIMESCALE;
2987.     track->enc = avcodec_alloc_context3(NULL);
          ^
2988.     track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
2989. 

libavcodec/options.c:123:1: start of procedure avcodec_alloc_context3()
  121. }
  122. 
  123. AVCodecContext *avcodec_alloc_context3(AVCodec *codec){
       ^
  124.     AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
  125. 

libavcodec/options.c:124:5: 
  122. 
  123. AVCodecContext *avcodec_alloc_context3(AVCodec *codec){
  124.     AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
           ^
  125. 
  126.     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:71:5: 
    69. #endif
    70. 
    71.     assert(size);
            ^
    72. 
    73.     /* let's disallow possible ambiguous cases */

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

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

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

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

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, size_t size)

libavcodec/options.c:126:8: Taking false branch
  124.     AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
  125. 
  126.     if(avctx==NULL) return NULL;
              ^
  127. 
  128.     if(avcodec_get_context_defaults3(avctx, codec) < 0){

libavcodec/options.c:128:8: Taking false branch
  126.     if(avctx==NULL) return NULL;
  127. 
  128.     if(avcodec_get_context_defaults3(avctx, codec) < 0){
              ^
  129.         av_free(avctx);
  130.         return NULL;

libavcodec/options.c:133:5: 
  131.     }
  132. 
  133.     return avctx;
           ^
  134. }
  135. 

libavcodec/options.c:134:1: return from a call to avcodec_alloc_context3
  132. 
  133.     return avctx;
  134. }
       ^
  135. 
  136. int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)

libavformat/movenc.c:2988:5: 
2986.     track->timescale = MOV_TIMESCALE;
2987.     track->enc = avcodec_alloc_context3(NULL);
2988.     track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
          ^
2989. 
2990.     for (i = 0; i < s->nb_chapters; i++) {

libavformat/movenc.c:2990:10: 
2988.     track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
2989. 
2990.     for (i = 0; i < s->nb_chapters; i++) {
               ^
2991.         AVChapter *c = s->chapters[i];
2992.         AVDictionaryEntry *t;

libavformat/movenc.c:2990:17: Loop condition is true. Entering loop body
2988.     track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
2989. 
2990.     for (i = 0; i < s->nb_chapters; i++) {
                      ^
2991.         AVChapter *c = s->chapters[i];
2992.         AVDictionaryEntry *t;

libavformat/movenc.c:2991:9: 
2989. 
2990.     for (i = 0; i < s->nb_chapters; i++) {
2991.         AVChapter *c = s->chapters[i];
              ^
2992.         AVDictionaryEntry *t;
2993. 

libavformat/movenc.c:2994:9: 
2992.         AVDictionaryEntry *t;
2993. 
2994.         int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE});
              ^
2995.         pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE});
2996.         pkt.duration = end - pkt.dts;

libavutil/mathematics.c:141:1: start of procedure av_rescale_q()
  139. }
  140. 
  141. int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
       ^
  142. {
  143.     return av_rescale_q_rnd(a, bq, cq, AV_ROUND_NEAR_INF);

libavutil/mathematics.c:143:5: 
  141. int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
  142. {
  143.     return av_rescale_q_rnd(a, bq, cq, AV_ROUND_NEAR_INF);
           ^
  144. }
  145. 

libavutil/mathematics.c:133:1: start of procedure av_rescale_q_rnd()
    131. }
    132. 
    133. int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq,
         ^
    134.                          enum AVRounding rnd)
    135. {

libavutil/mathematics.c:136:5: 
    134.                          enum AVRounding rnd)
    135. {
    136.     int64_t b= bq.num * (int64_t)cq.den;
             ^
    137.     int64_t c= cq.num * (int64_t)bq.den;
    138.     return av_rescale_rnd(a, b, c, rnd);

libavutil/mathematics.c:137:5: 
    135. {
    136.     int64_t b= bq.num * (int64_t)cq.den;
    137.     int64_t c= cq.num * (int64_t)bq.den;
             ^
    138.     return av_rescale_rnd(a, b, c, rnd);
    139. }

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

libavutil/mathematics.c:139:1: return from a call to av_rescale_q_rnd
    137.     int64_t c= cq.num * (int64_t)bq.den;
    138.     return av_rescale_rnd(a, b, c, rnd);
    139. }
         ^
    140. 
    141. int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)

libavutil/mathematics.c:144:1: return from a call to av_rescale_q
  142. {
  143.     return av_rescale_q_rnd(a, bq, cq, AV_ROUND_NEAR_INF);
  144. }
       ^
  145. 
  146. int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){

libavformat/movenc.c:2995:9: 
2993. 
2994.         int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE});
2995.         pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE});
              ^
2996.         pkt.duration = end - pkt.dts;
2997. 

libavutil/mathematics.c:141:1: start of procedure av_rescale_q()
  139. }
  140. 
  141. int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
       ^
  142. {
  143.     return av_rescale_q_rnd(a, bq, cq, AV_ROUND_NEAR_INF);

libavutil/mathematics.c:143:5: 
  141. int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
  142. {
  143.     return av_rescale_q_rnd(a, bq, cq, AV_ROUND_NEAR_INF);
           ^
  144. }
  145. 

libavutil/mathematics.c:133:1: start of procedure av_rescale_q_rnd()
    131. }
    132. 
    133. int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq,
         ^
    134.                          enum AVRounding rnd)
    135. {

libavutil/mathematics.c:136:5: 
    134.                          enum AVRounding rnd)
    135. {
    136.     int64_t b= bq.num * (int64_t)cq.den;
             ^
    137.     int64_t c= cq.num * (int64_t)bq.den;
    138.     return av_rescale_rnd(a, b, c, rnd);

libavutil/mathematics.c:137:5: 
    135. {
    136.     int64_t b= bq.num * (int64_t)cq.den;
    137.     int64_t c= cq.num * (int64_t)bq.den;
             ^
    138.     return av_rescale_rnd(a, b, c, rnd);
    139. }

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

libavutil/mathematics.c:139:1: return from a call to av_rescale_q_rnd
    137.     int64_t c= cq.num * (int64_t)bq.den;
    138.     return av_rescale_rnd(a, b, c, rnd);
    139. }
         ^
    140. 
    141. int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)

libavutil/mathematics.c:144:1: return from a call to av_rescale_q
  142. {
  143.     return av_rescale_q_rnd(a, bq, cq, AV_ROUND_NEAR_INF);
  144. }
       ^
  145. 
  146. int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){

libavformat/movenc.c:2996:9: 
2994.         int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE});
2995.         pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE});
2996.         pkt.duration = end - pkt.dts;
              ^
2997. 
2998.         if ((t = av_dict_get(c->metadata, "title", NULL, 0))) {

libavformat/movenc.c:2998:14: Taking true branch
2996.         pkt.duration = end - pkt.dts;
2997. 
2998.         if ((t = av_dict_get(c->metadata, "title", NULL, 0))) {
                   ^
2999.             len = strlen(t->value);
3000.             pkt.size = len+2;

libavformat/movenc.c:2999:13: 
2997. 
2998.         if ((t = av_dict_get(c->metadata, "title", NULL, 0))) {
2999.             len = strlen(t->value);
                  ^
3000.             pkt.size = len+2;
3001.             pkt.data = av_malloc(pkt.size);

libavformat/movenc.c:3000:13: 
2998.         if ((t = av_dict_get(c->metadata, "title", NULL, 0))) {
2999.             len = strlen(t->value);
3000.             pkt.size = len+2;
                  ^
3001.             pkt.data = av_malloc(pkt.size);
3002.             AV_WB16(pkt.data, len);

libavformat/movenc.c:3001:13: 
2999.             len = strlen(t->value);
3000.             pkt.size = len+2;
3001.             pkt.data = av_malloc(pkt.size);
                  ^
3002.             AV_WB16(pkt.data, len);
3003.             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:71:5: 
  69. #endif
  70. 
  71.     assert(size);
          ^
  72. 
  73.     /* let's disallow possible ambiguous cases */

libavutil/mem.c:74:9: Taking true branch
  72. 
  73.     /* let's disallow possible ambiguous cases */
  74.     if (size > (INT_MAX-32) || !size)
              ^
  75.         return NULL;
  76. 

libavutil/mem.c:75:9: 
  73.     /* let's disallow possible ambiguous cases */
  74.     if (size > (INT_MAX-32) || !size)
  75.         return NULL;
              ^
  76. 
  77. #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, size_t size)

libavformat/movenc.c:3002:13: 
3000.             pkt.size = len+2;
3001.             pkt.data = av_malloc(pkt.size);
3002.             AV_WB16(pkt.data, len);
                  ^
3003.             memcpy(pkt.data+2, t->value, len);
3004.             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_context3(NULL);
    track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
    for (i = 0; i < s->nb_chapters; i++) {
        AVChapter *c = s->chapters[i];
        AVDictionaryEntry *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_dict_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_context3(NULL);\n    track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;\n    for (i = 0; i < s->nb_chapters; i++) {\n        AVChapter *c = s->chapters[i];\n        AVDictionaryEntry *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_dict_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_context3(AVCodec *codec){\n    AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));\n    if(avctx==NULL) return NULL;\n    if(avcodec_get_context_defaults3(avctx, codec) < 0){\n        av_free(avctx);\n        return NULL;\n    }\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    assert(size);\n    if (size > (INT_MAX-32) || !size)\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{\n    return av_rescale_q_rnd(a, bq, cq, AV_ROUND_NEAR_INF);\n}', 'int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq,\n                         enum AVRounding rnd)\n{\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, rnd);\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}']