libavformat/rtpdec_h264.c:184: error: Null Dereference
  pointer `pkt->data` last assigned on line 183 could be null and is dereferenced by call to `memcpy()` at line 184, column 9.

libavformat/rtpdec_h264.c:153:1: start of procedure h264_handle_packet()
151. 
152. // return 0 on packet, no more left, 1 on packet, 1 on partial packet...
153. static int h264_handle_packet(AVFormatContext *ctx,
     ^
154.                               PayloadContext *data,
155.                               AVStream *st,

libavformat/rtpdec_h264.c:163:5: 
161.     uint8_t nal;
162.     uint8_t type;
163.     int result= 0;
         ^
164.     uint8_t start_sequence[] = { 0, 0, 0, 1 };
165. 

libavformat/rtpdec_h264.c:164:5: 
162.     uint8_t type;
163.     int result= 0;
164.     uint8_t start_sequence[] = { 0, 0, 0, 1 };
         ^
165. 
166.     if (!len) {

libavformat/rtpdec_h264.c:166:10: Taking false branch
164.     uint8_t start_sequence[] = { 0, 0, 0, 1 };
165. 
166.     if (!len) {
              ^
167.         av_log(ctx, AV_LOG_ERROR, "Empty H264 RTP packet\n");
168.         return AVERROR_INVALIDDATA;

libavformat/rtpdec_h264.c:170:5: 
168.         return AVERROR_INVALIDDATA;
169.     }
170.     nal  = buf[0];
         ^
171.     type = nal & 0x1f;
172. 

libavformat/rtpdec_h264.c:171:5: 
169.     }
170.     nal  = buf[0];
171.     type = nal & 0x1f;
         ^
172. 
173. #ifdef DEBUG

libavformat/rtpdec_h264.c:176:5: 
174.     assert(data);
175. #endif
176.     assert(buf);
         ^
177. 
178.     if (type >= 1 && type <= 23)

libavformat/rtpdec_h264.c:178:9: Taking true branch
176.     assert(buf);
177. 
178.     if (type >= 1 && type <= 23)
             ^
179.         type = 1;              // simplify the case. (these are all the nal types used internally by the h264 codec)
180.     switch (type) {

libavformat/rtpdec_h264.c:178:22: Taking true branch
176.     assert(buf);
177. 
178.     if (type >= 1 && type <= 23)
                          ^
179.         type = 1;              // simplify the case. (these are all the nal types used internally by the h264 codec)
180.     switch (type) {

libavformat/rtpdec_h264.c:179:9: 
177. 
178.     if (type >= 1 && type <= 23)
179.         type = 1;              // simplify the case. (these are all the nal types used internally by the h264 codec)
             ^
180.     switch (type) {
181.     case 0:                    // undefined, but pass them through

libavformat/rtpdec_h264.c:180:5: 
178.     if (type >= 1 && type <= 23)
179.         type = 1;              // simplify the case. (these are all the nal types used internally by the h264 codec)
180.     switch (type) {
         ^
181.     case 0:                    // undefined, but pass them through
182.     case 1:

libavformat/rtpdec_h264.c:181:5: Switch condition is false. Skipping switch case
179.         type = 1;              // simplify the case. (these are all the nal types used internally by the h264 codec)
180.     switch (type) {
181.     case 0:                    // undefined, but pass them through
         ^
182.     case 1:
183.         av_new_packet(pkt, len+sizeof(start_sequence));

libavformat/rtpdec_h264.c:182:5: Switch condition is true. Entering switch case
180.     switch (type) {
181.     case 0:                    // undefined, but pass them through
182.     case 1:
         ^
183.         av_new_packet(pkt, len+sizeof(start_sequence));
184.         memcpy(pkt->data, start_sequence, sizeof(start_sequence));

libavformat/rtpdec_h264.c:183:9: 
181.     case 0:                    // undefined, but pass them through
182.     case 1:
183.         av_new_packet(pkt, len+sizeof(start_sequence));
             ^
184.         memcpy(pkt->data, start_sequence, sizeof(start_sequence));
185.         memcpy(pkt->data+sizeof(start_sequence), buf, len);

libavcodec/avpacket.c:61:1: start of procedure av_new_packet()
  59. }
  60. 
  61. int av_new_packet(AVPacket *pkt, int size)
      ^
  62. {
  63.     uint8_t *data = NULL;

libavcodec/avpacket.c:63:5: 
  61. int av_new_packet(AVPacket *pkt, int size)
  62. {
  63.     uint8_t *data = NULL;
          ^
  64.     if ((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)
  65.         data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);

libavcodec/avpacket.c:64:9: Taking true branch
  62. {
  63.     uint8_t *data = NULL;
  64.     if ((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)
              ^
  65.         data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
  66.     if (data) {

libavcodec/avpacket.c:65:9: 
  63.     uint8_t *data = NULL;
  64.     if ((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)
  65.         data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
              ^
  66.     if (data) {
  67.         memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);

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)

libavcodec/avpacket.c:66:9: Taking false branch
  64.     if ((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)
  65.         data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
  66.     if (data) {
              ^
  67.         memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
  68.     } else

libavcodec/avpacket.c:69:9: 
  67.         memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
  68.     } else
  69.         size = 0;
              ^
  70. 
  71.     av_init_packet(pkt);

libavcodec/avpacket.c:71:5: 
  69.         size = 0;
  70. 
  71.     av_init_packet(pkt);
          ^
  72.     pkt->data     = data;
  73.     pkt->size     = size;

libavcodec/avpacket.c:47:1: start of procedure av_init_packet()
    45. }
    46. 
    47. void av_init_packet(AVPacket *pkt)
        ^
    48. {
    49.     pkt->pts                  = AV_NOPTS_VALUE;

libavcodec/avpacket.c:49:5: 
    47. void av_init_packet(AVPacket *pkt)
    48. {
    49.     pkt->pts                  = AV_NOPTS_VALUE;
            ^
    50.     pkt->dts                  = AV_NOPTS_VALUE;
    51.     pkt->pos                  = -1;

libavcodec/avpacket.c:50:5: 
    48. {
    49.     pkt->pts                  = AV_NOPTS_VALUE;
    50.     pkt->dts                  = AV_NOPTS_VALUE;
            ^
    51.     pkt->pos                  = -1;
    52.     pkt->duration             = 0;

libavcodec/avpacket.c:51:5: 
    49.     pkt->pts                  = AV_NOPTS_VALUE;
    50.     pkt->dts                  = AV_NOPTS_VALUE;
    51.     pkt->pos                  = -1;
            ^
    52.     pkt->duration             = 0;
    53.     pkt->convergence_duration = 0;

libavcodec/avpacket.c:52:5: 
    50.     pkt->dts                  = AV_NOPTS_VALUE;
    51.     pkt->pos                  = -1;
    52.     pkt->duration             = 0;
            ^
    53.     pkt->convergence_duration = 0;
    54.     pkt->flags                = 0;

libavcodec/avpacket.c:53:5: 
    51.     pkt->pos                  = -1;
    52.     pkt->duration             = 0;
    53.     pkt->convergence_duration = 0;
            ^
    54.     pkt->flags                = 0;
    55.     pkt->stream_index         = 0;

libavcodec/avpacket.c:54:5: 
    52.     pkt->duration             = 0;
    53.     pkt->convergence_duration = 0;
    54.     pkt->flags                = 0;
            ^
    55.     pkt->stream_index         = 0;
    56.     pkt->destruct             = NULL;

libavcodec/avpacket.c:55:5: 
    53.     pkt->convergence_duration = 0;
    54.     pkt->flags                = 0;
    55.     pkt->stream_index         = 0;
            ^
    56.     pkt->destruct             = NULL;
    57.     pkt->side_data            = NULL;

libavcodec/avpacket.c:56:5: 
    54.     pkt->flags                = 0;
    55.     pkt->stream_index         = 0;
    56.     pkt->destruct             = NULL;
            ^
    57.     pkt->side_data            = NULL;
    58.     pkt->side_data_elems      = 0;

libavcodec/avpacket.c:57:5: 
    55.     pkt->stream_index         = 0;
    56.     pkt->destruct             = NULL;
    57.     pkt->side_data            = NULL;
            ^
    58.     pkt->side_data_elems      = 0;
    59. }

libavcodec/avpacket.c:58:5: 
    56.     pkt->destruct             = NULL;
    57.     pkt->side_data            = NULL;
    58.     pkt->side_data_elems      = 0;
            ^
    59. }
    60. 

libavcodec/avpacket.c:59:1: return from a call to av_init_packet
    57.     pkt->side_data            = NULL;
    58.     pkt->side_data_elems      = 0;
    59. }
        ^
    60. 
    61. int av_new_packet(AVPacket *pkt, int size)

libavcodec/avpacket.c:72:5: 
  70. 
  71.     av_init_packet(pkt);
  72.     pkt->data     = data;
          ^
  73.     pkt->size     = size;
  74.     pkt->destruct = av_destruct_packet;

libavcodec/avpacket.c:73:5: 
  71.     av_init_packet(pkt);
  72.     pkt->data     = data;
  73.     pkt->size     = size;
          ^
  74.     pkt->destruct = av_destruct_packet;
  75.     if (!data)

libavcodec/avpacket.c:74:5: 
  72.     pkt->data     = data;
  73.     pkt->size     = size;
  74.     pkt->destruct = av_destruct_packet;
          ^
  75.     if (!data)
  76.         return AVERROR(ENOMEM);

libavcodec/avpacket.c:75:10: Taking true branch
  73.     pkt->size     = size;
  74.     pkt->destruct = av_destruct_packet;
  75.     if (!data)
               ^
  76.         return AVERROR(ENOMEM);
  77.     return 0;

libavcodec/avpacket.c:76:9: 
  74.     pkt->destruct = av_destruct_packet;
  75.     if (!data)
  76.         return AVERROR(ENOMEM);
              ^
  77.     return 0;
  78. }

libavcodec/avpacket.c:78:1: return from a call to av_new_packet
  76.         return AVERROR(ENOMEM);
  77.     return 0;
  78. }
      ^
  79. 
  80. void av_shrink_packet(AVPacket *pkt, int size)

libavformat/rtpdec_h264.c:184:9: 
182.     case 1:
183.         av_new_packet(pkt, len+sizeof(start_sequence));
184.         memcpy(pkt->data, start_sequence, sizeof(start_sequence));
             ^
185.         memcpy(pkt->data+sizeof(start_sequence), buf, len);
186. #ifdef DEBUG

static int h264_handle_packet(AVFormatContext *ctx,
                              PayloadContext *data,
                              AVStream *st,
                              AVPacket * pkt,
                              uint32_t * timestamp,
                              const uint8_t * buf,
                              int len, int flags)
{
    uint8_t nal;
    uint8_t type;
    int result= 0;
    uint8_t start_sequence[] = { 0, 0, 0, 1 };
    if (!len) {
        av_log(ctx, AV_LOG_ERROR, "Empty H264 RTP packet\n");
        return AVERROR_INVALIDDATA;
    }
    nal  = buf[0];
    type = nal & 0x1f;
#ifdef DEBUG
    assert(data);
#endif
    assert(buf);
    if (type >= 1 && type <= 23)
        type = 1;
    switch (type) {
    case 0:
    case 1:
        av_new_packet(pkt, len+sizeof(start_sequence));
        memcpy(pkt->data, start_sequence, sizeof(start_sequence));
        memcpy(pkt->data+sizeof(start_sequence), buf, len);
#ifdef DEBUG
        data->packet_types_received[nal & 0x1f]++;
#endif
        break;
    case 24:
        buf++;
        len--;
        {
            int pass= 0;
            int total_length= 0;
            uint8_t *dst= NULL;
            for(pass= 0; pass<2; pass++) {
                const uint8_t *src= buf;
                int src_len= len;
                while (src_len > 2) {
                    uint16_t nal_size = AV_RB16(src);
                    src += 2;
                    src_len -= 2;
                    if (nal_size <= src_len) {
                        if(pass==0) {
                            total_length+= sizeof(start_sequence)+nal_size;
                        } else {
                            assert(dst);
                            memcpy(dst, start_sequence, sizeof(start_sequence));
                            dst+= sizeof(start_sequence);
                            memcpy(dst, src, nal_size);
#ifdef DEBUG
                            data->packet_types_received[*src & 0x1f]++;
#endif
                            dst+= nal_size;
                        }
                    } else {
                        av_log(ctx, AV_LOG_ERROR,
                               "nal size exceeds length: %d %d\n", nal_size, src_len);
                    }
                    src += nal_size;
                    src_len -= nal_size;
                    if (src_len < 0)
                        av_log(ctx, AV_LOG_ERROR,
                               "Consumed more bytes than we got! (%d)\n", src_len);
                }
                if(pass==0) {
                    av_new_packet(pkt, total_length);
                    dst= pkt->data;
                } else {
                    assert(dst-pkt->data==total_length);
                }
            }
        }
        break;
    case 25:
    case 26:
    case 27:
    case 29:
        av_log(ctx, AV_LOG_ERROR,
               "Unhandled type (%d) (See RFC for implementation details\n",
               type);
        result = AVERROR(ENOSYS);
        break;
    case 28:
        buf++;
        len--;
        if (len > 1) {
            uint8_t fu_indicator = nal;
            uint8_t fu_header = *buf;
            uint8_t start_bit = fu_header >> 7;
            uint8_t nal_type = (fu_header & 0x1f);
            uint8_t reconstructed_nal;
            reconstructed_nal = fu_indicator & (0xe0);
            reconstructed_nal |= nal_type;
            buf++;
            len--;
#ifdef DEBUG
            if (start_bit)
                data->packet_types_received[nal_type]++;
#endif
            if(start_bit) {
                av_new_packet(pkt, sizeof(start_sequence)+sizeof(nal)+len);
                memcpy(pkt->data, start_sequence, sizeof(start_sequence));
                pkt->data[sizeof(start_sequence)]= reconstructed_nal;
                memcpy(pkt->data+sizeof(start_sequence)+sizeof(nal), buf, len);
            } else {
                av_new_packet(pkt, len);
                memcpy(pkt->data, buf, len);
            }
        } else {
            av_log(ctx, AV_LOG_ERROR, "Too short data for FU-A H264 RTP packet\n");
            result = AVERROR_INVALIDDATA;
        }
        break;
    case 30:
    case 31:
    default:
        av_log(ctx, AV_LOG_ERROR, "Undefined type (%d)", type);
        result = AVERROR_INVALIDDATA;
        break;
    }
    pkt->stream_index = st->index;
    return result;
}
['static int h264_handle_packet(AVFormatContext *ctx,\n                              PayloadContext *data,\n                              AVStream *st,\n                              AVPacket * pkt,\n                              uint32_t * timestamp,\n                              const uint8_t * buf,\n                              int len, int flags)\n{\n    uint8_t nal;\n    uint8_t type;\n    int result= 0;\n    uint8_t start_sequence[] = { 0, 0, 0, 1 };\n    if (!len) {\n        av_log(ctx, AV_LOG_ERROR, "Empty H264 RTP packet\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    nal  = buf[0];\n    type = nal & 0x1f;\n#ifdef DEBUG\n    assert(data);\n#endif\n    assert(buf);\n    if (type >= 1 && type <= 23)\n        type = 1;\n    switch (type) {\n    case 0:\n    case 1:\n        av_new_packet(pkt, len+sizeof(start_sequence));\n        memcpy(pkt->data, start_sequence, sizeof(start_sequence));\n        memcpy(pkt->data+sizeof(start_sequence), buf, len);\n#ifdef DEBUG\n        data->packet_types_received[nal & 0x1f]++;\n#endif\n        break;\n    case 24:\n        buf++;\n        len--;\n        {\n            int pass= 0;\n            int total_length= 0;\n            uint8_t *dst= NULL;\n            for(pass= 0; pass<2; pass++) {\n                const uint8_t *src= buf;\n                int src_len= len;\n                while (src_len > 2) {\n                    uint16_t nal_size = AV_RB16(src);\n                    src += 2;\n                    src_len -= 2;\n                    if (nal_size <= src_len) {\n                        if(pass==0) {\n                            total_length+= sizeof(start_sequence)+nal_size;\n                        } else {\n                            assert(dst);\n                            memcpy(dst, start_sequence, sizeof(start_sequence));\n                            dst+= sizeof(start_sequence);\n                            memcpy(dst, src, nal_size);\n#ifdef DEBUG\n                            data->packet_types_received[*src & 0x1f]++;\n#endif\n                            dst+= nal_size;\n                        }\n                    } else {\n                        av_log(ctx, AV_LOG_ERROR,\n                               "nal size exceeds length: %d %d\\n", nal_size, src_len);\n                    }\n                    src += nal_size;\n                    src_len -= nal_size;\n                    if (src_len < 0)\n                        av_log(ctx, AV_LOG_ERROR,\n                               "Consumed more bytes than we got! (%d)\\n", src_len);\n                }\n                if(pass==0) {\n                    av_new_packet(pkt, total_length);\n                    dst= pkt->data;\n                } else {\n                    assert(dst-pkt->data==total_length);\n                }\n            }\n        }\n        break;\n    case 25:\n    case 26:\n    case 27:\n    case 29:\n        av_log(ctx, AV_LOG_ERROR,\n               "Unhandled type (%d) (See RFC for implementation details\\n",\n               type);\n        result = AVERROR(ENOSYS);\n        break;\n    case 28:\n        buf++;\n        len--;\n        if (len > 1) {\n            uint8_t fu_indicator = nal;\n            uint8_t fu_header = *buf;\n            uint8_t start_bit = fu_header >> 7;\n            uint8_t nal_type = (fu_header & 0x1f);\n            uint8_t reconstructed_nal;\n            reconstructed_nal = fu_indicator & (0xe0);\n            reconstructed_nal |= nal_type;\n            buf++;\n            len--;\n#ifdef DEBUG\n            if (start_bit)\n                data->packet_types_received[nal_type]++;\n#endif\n            if(start_bit) {\n                av_new_packet(pkt, sizeof(start_sequence)+sizeof(nal)+len);\n                memcpy(pkt->data, start_sequence, sizeof(start_sequence));\n                pkt->data[sizeof(start_sequence)]= reconstructed_nal;\n                memcpy(pkt->data+sizeof(start_sequence)+sizeof(nal), buf, len);\n            } else {\n                av_new_packet(pkt, len);\n                memcpy(pkt->data, buf, len);\n            }\n        } else {\n            av_log(ctx, AV_LOG_ERROR, "Too short data for FU-A H264 RTP packet\\n");\n            result = AVERROR_INVALIDDATA;\n        }\n        break;\n    case 30:\n    case 31:\n    default:\n        av_log(ctx, AV_LOG_ERROR, "Undefined type (%d)", type);\n        result = AVERROR_INVALIDDATA;\n        break;\n    }\n    pkt->stream_index = st->index;\n    return result;\n}', 'int av_new_packet(AVPacket *pkt, int size)\n{\n    uint8_t *data = NULL;\n    if ((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)\n        data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);\n    if (data) {\n        memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);\n    } else\n        size = 0;\n    av_init_packet(pkt);\n    pkt->data     = data;\n    pkt->size     = size;\n    pkt->destruct = av_destruct_packet;\n    if (!data)\n        return AVERROR(ENOMEM);\n    return 0;\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}', 'void av_init_packet(AVPacket *pkt)\n{\n    pkt->pts                  = AV_NOPTS_VALUE;\n    pkt->dts                  = AV_NOPTS_VALUE;\n    pkt->pos                  = -1;\n    pkt->duration             = 0;\n    pkt->convergence_duration = 0;\n    pkt->flags                = 0;\n    pkt->stream_index         = 0;\n    pkt->destruct             = NULL;\n    pkt->side_data            = NULL;\n    pkt->side_data_elems      = 0;\n}']