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

libavformat/rtp_h264.c:162:1: start of procedure h264_handle_packet()
160. 
161. // return 0 on packet, no more left, 1 on packet, 1 on partial packet...
162. static int h264_handle_packet(AVFormatContext *ctx,
     ^
163.                               PayloadContext *data,
164.                               AVStream *st,

libavformat/rtp_h264.c:170:5: 
168.                               int len, int flags)
169. {
170.     uint8_t nal = buf[0];
         ^
171.     uint8_t type = (nal & 0x1f);
172.     int result= 0;

libavformat/rtp_h264.c:171:5: 
169. {
170.     uint8_t nal = buf[0];
171.     uint8_t type = (nal & 0x1f);
         ^
172.     int result= 0;
173.     uint8_t start_sequence[]= {0, 0, 1};

libavformat/rtp_h264.c:172:5: 
170.     uint8_t nal = buf[0];
171.     uint8_t type = (nal & 0x1f);
172.     int result= 0;
         ^
173.     uint8_t start_sequence[]= {0, 0, 1};
174. 

libavformat/rtp_h264.c:173:5: 
171.     uint8_t type = (nal & 0x1f);
172.     int result= 0;
173.     uint8_t start_sequence[]= {0, 0, 1};
         ^
174. 
175. #ifdef DEBUG

libavformat/rtp_h264.c:179:5: 
177.     assert(data->cookie == MAGIC_COOKIE);
178. #endif
179.     assert(buf);
         ^
180. 
181.     if (type >= 1 && type <= 23)

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

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

libavformat/rtp_h264.c:182:9: 
180. 
181.     if (type >= 1 && type <= 23)
182.         type = 1;              // simplify the case. (these are all the nal types used internally by the h264 codec)
             ^
183.     switch (type) {
184.     case 0:                    // undefined;

libavformat/rtp_h264.c:183:5: 
181.     if (type >= 1 && type <= 23)
182.         type = 1;              // simplify the case. (these are all the nal types used internally by the h264 codec)
183.     switch (type) {
         ^
184.     case 0:                    // undefined;
185.         result= -1;

libavformat/rtp_h264.c:184:5: Switch condition is false. Skipping switch case
182.         type = 1;              // simplify the case. (these are all the nal types used internally by the h264 codec)
183.     switch (type) {
184.     case 0:                    // undefined;
         ^
185.         result= -1;
186.         break;

libavformat/rtp_h264.c:188:5: Switch condition is true. Entering switch case
186.         break;
187. 
188.     case 1:
         ^
189.         av_new_packet(pkt, len+sizeof(start_sequence));
190.         memcpy(pkt->data, start_sequence, sizeof(start_sequence));

libavformat/rtp_h264.c:189:9: 
187. 
188.     case 1:
189.         av_new_packet(pkt, len+sizeof(start_sequence));
             ^
190.         memcpy(pkt->data, start_sequence, sizeof(start_sequence));
191.         memcpy(pkt->data+sizeof(start_sequence), buf, len);

libavcodec/avpacket.c:48:1: start of procedure av_new_packet()
  46. }
  47. 
  48. int av_new_packet(AVPacket *pkt, int size)
      ^
  49. {
  50.     uint8_t *data= NULL;

libavcodec/avpacket.c:50:5: 
  48. int av_new_packet(AVPacket *pkt, int size)
  49. {
  50.     uint8_t *data= NULL;
          ^
  51.     if((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)
  52.         data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);

libavcodec/avpacket.c:51:8: Taking true branch
  49. {
  50.     uint8_t *data= NULL;
  51.     if((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)
             ^
  52.         data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
  53.     if (data){

libavcodec/avpacket.c:52:9: 
  50.     uint8_t *data= NULL;
  51.     if((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)
  52.         data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
              ^
  53.     if (data){
  54.         memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);

libavutil/mem.c:47:1: start of procedure av_malloc()
    45.    linker will do it automatically. */
    46. 
    47. void *av_malloc(unsigned int size)
        ^
    48. {
    49.     void *ptr = NULL;

libavutil/mem.c:49:5: 
    47. void *av_malloc(unsigned int size)
    48. {
    49.     void *ptr = NULL;
            ^
    50. #if CONFIG_MEMALIGN_HACK
    51.     long diff;

libavutil/mem.c:55:8: Taking true branch
    53. 
    54.     /* let's disallow possible ambiguous cases */
    55.     if(size > (INT_MAX-16) )
               ^
    56.         return NULL;
    57. 

libavutil/mem.c:56:9: 
    54.     /* let's disallow possible ambiguous cases */
    55.     if(size > (INT_MAX-16) )
    56.         return NULL;
                ^
    57. 
    58. #if CONFIG_MEMALIGN_HACK

libavutil/mem.c:100:1: return from a call to av_malloc
     98. #endif
     99.     return ptr;
    100. }
         ^
    101. 
    102. void *av_realloc(void *ptr, unsigned int size)

libavcodec/avpacket.c:53:9: Taking false branch
  51.     if((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)
  52.         data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
  53.     if (data){
              ^
  54.         memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
  55.     }else

libavcodec/avpacket.c:56:9: 
  54.         memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
  55.     }else
  56.         size=0;
              ^
  57. 
  58.     av_init_packet(pkt);

libavcodec/avpacket.c:58:5: 
  56.         size=0;
  57. 
  58.     av_init_packet(pkt);
          ^
  59.     pkt->data = data;
  60.     pkt->size = size;

libavcodec/avpacket.c:36:1: start of procedure av_init_packet()
    34. }
    35. 
    36. void av_init_packet(AVPacket *pkt)
        ^
    37. {
    38.     pkt->pts   = AV_NOPTS_VALUE;

libavcodec/avpacket.c:38:5: 
    36. void av_init_packet(AVPacket *pkt)
    37. {
    38.     pkt->pts   = AV_NOPTS_VALUE;
            ^
    39.     pkt->dts   = AV_NOPTS_VALUE;
    40.     pkt->pos   = -1;

libavcodec/avpacket.c:39:5: 
    37. {
    38.     pkt->pts   = AV_NOPTS_VALUE;
    39.     pkt->dts   = AV_NOPTS_VALUE;
            ^
    40.     pkt->pos   = -1;
    41.     pkt->duration = 0;

libavcodec/avpacket.c:40:5: 
    38.     pkt->pts   = AV_NOPTS_VALUE;
    39.     pkt->dts   = AV_NOPTS_VALUE;
    40.     pkt->pos   = -1;
            ^
    41.     pkt->duration = 0;
    42.     pkt->convergence_duration = 0;

libavcodec/avpacket.c:41:5: 
    39.     pkt->dts   = AV_NOPTS_VALUE;
    40.     pkt->pos   = -1;
    41.     pkt->duration = 0;
            ^
    42.     pkt->convergence_duration = 0;
    43.     pkt->flags = 0;

libavcodec/avpacket.c:42:5: 
    40.     pkt->pos   = -1;
    41.     pkt->duration = 0;
    42.     pkt->convergence_duration = 0;
            ^
    43.     pkt->flags = 0;
    44.     pkt->stream_index = 0;

libavcodec/avpacket.c:43:5: 
    41.     pkt->duration = 0;
    42.     pkt->convergence_duration = 0;
    43.     pkt->flags = 0;
            ^
    44.     pkt->stream_index = 0;
    45.     pkt->destruct= NULL;

libavcodec/avpacket.c:44:5: 
    42.     pkt->convergence_duration = 0;
    43.     pkt->flags = 0;
    44.     pkt->stream_index = 0;
            ^
    45.     pkt->destruct= NULL;
    46. }

libavcodec/avpacket.c:45:5: 
    43.     pkt->flags = 0;
    44.     pkt->stream_index = 0;
    45.     pkt->destruct= NULL;
            ^
    46. }
    47. 

libavcodec/avpacket.c:46:1: return from a call to av_init_packet
    44.     pkt->stream_index = 0;
    45.     pkt->destruct= NULL;
    46. }
        ^
    47. 
    48. int av_new_packet(AVPacket *pkt, int size)

libavcodec/avpacket.c:59:5: 
  57. 
  58.     av_init_packet(pkt);
  59.     pkt->data = data;
          ^
  60.     pkt->size = size;
  61.     pkt->destruct = av_destruct_packet;

libavcodec/avpacket.c:60:5: 
  58.     av_init_packet(pkt);
  59.     pkt->data = data;
  60.     pkt->size = size;
          ^
  61.     pkt->destruct = av_destruct_packet;
  62.     if(!data)

libavcodec/avpacket.c:61:5: 
  59.     pkt->data = data;
  60.     pkt->size = size;
  61.     pkt->destruct = av_destruct_packet;
          ^
  62.     if(!data)
  63.         return AVERROR(ENOMEM);

libavcodec/avpacket.c:62:9: Taking true branch
  60.     pkt->size = size;
  61.     pkt->destruct = av_destruct_packet;
  62.     if(!data)
              ^
  63.         return AVERROR(ENOMEM);
  64.     return 0;

libavcodec/avpacket.c:63:9: 
  61.     pkt->destruct = av_destruct_packet;
  62.     if(!data)
  63.         return AVERROR(ENOMEM);
              ^
  64.     return 0;
  65. }

libavcodec/avpacket.c:65:1: return from a call to av_new_packet
  63.         return AVERROR(ENOMEM);
  64.     return 0;
  65. }
      ^
  66. 
  67. void av_shrink_packet(AVPacket *pkt, int size)

libavformat/rtp_h264.c:190:9: 
188.     case 1:
189.         av_new_packet(pkt, len+sizeof(start_sequence));
190.         memcpy(pkt->data, start_sequence, sizeof(start_sequence));
             ^
191.         memcpy(pkt->data+sizeof(start_sequence), buf, len);
192. #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 = buf[0];
    uint8_t type = (nal & 0x1f);
    int result= 0;
    uint8_t start_sequence[]= {0, 0, 1};
#ifdef DEBUG
    assert(data);
    assert(data->cookie == MAGIC_COOKIE);
#endif
    assert(buf);
    if (type >= 1 && type <= 23)
        type = 1;
    switch (type) {
    case 0:
        result= -1;
        break;
    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;
                do {
                    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);
                } while (src_len > 2);
                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= -1;
        break;
    case 28:
        buf++;
        len--;
        {
            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);
            }
        }
        break;
    case 30:
    case 31:
    default:
        av_log(ctx, AV_LOG_ERROR, "Undefined type (%d)", type);
        result= -1;
        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 = buf[0];\n    uint8_t type = (nal & 0x1f);\n    int result= 0;\n    uint8_t start_sequence[]= {0, 0, 1};\n#ifdef DEBUG\n    assert(data);\n    assert(data->cookie == MAGIC_COOKIE);\n#endif\n    assert(buf);\n    if (type >= 1 && type <= 23)\n        type = 1;\n    switch (type) {\n    case 0:\n        result= -1;\n        break;\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                do {\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                } while (src_len > 2);\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= -1;\n        break;\n    case 28:\n        buf++;\n        len--;\n        {\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        }\n        break;\n    case 30:\n    case 31:\n    default:\n        av_log(ctx, AV_LOG_ERROR, "Undefined type (%d)", type);\n        result= -1;\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(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_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}']