libavformat/mms.c:111: error: Null Dereference
  pointer `mms->streams` last assigned on line 108 could be null and is dereferenced at line 111, column 17.

libavformat/mms.c:58:1: start of procedure ff_mms_asf_header_parser()
56. }
57. 
58. int ff_mms_asf_header_parser(MMSContext *mms)
    ^
59. {
60.     uint8_t *p = mms->asf_header;

libavformat/mms.c:60:5: 
58. int ff_mms_asf_header_parser(MMSContext *mms)
59. {
60.     uint8_t *p = mms->asf_header;
        ^
61.     uint8_t *end;
62.     int flags, stream_id;

libavformat/mms.c:63:5: 
61.     uint8_t *end;
62.     int flags, stream_id;
63.     mms->stream_num = 0;
        ^
64. 
65.     if (mms->asf_header_size < sizeof(ff_asf_guid) * 2 + 22 ||

libavformat/mms.c:65:9: Taking false branch
63.     mms->stream_num = 0;
64. 
65.     if (mms->asf_header_size < sizeof(ff_asf_guid) * 2 + 22 ||
            ^
66.         memcmp(p, ff_asf_header, sizeof(ff_asf_guid))) {
67.         av_log(NULL, AV_LOG_ERROR,

libavformat/mms.c:66:9: Taking false branch
64. 
65.     if (mms->asf_header_size < sizeof(ff_asf_guid) * 2 + 22 ||
66.         memcmp(p, ff_asf_header, sizeof(ff_asf_guid))) {
            ^
67.         av_log(NULL, AV_LOG_ERROR,
68.                "Corrupt stream (invalid ASF header, size=%d)\n",

libavformat/mms.c:73:5: 
71.     }
72. 
73.     end = mms->asf_header + mms->asf_header_size;
        ^
74. 
75.     p += sizeof(ff_asf_guid) + 14;

libavformat/mms.c:75:5: 
73.     end = mms->asf_header + mms->asf_header_size;
74. 
75.     p += sizeof(ff_asf_guid) + 14;
        ^
76.     while(end - p >= sizeof(ff_asf_guid) + 8) {
77.         uint64_t chunksize;

libavformat/mms.c:76:11: Loop condition is true. Entering loop body
74. 
75.     p += sizeof(ff_asf_guid) + 14;
76.     while(end - p >= sizeof(ff_asf_guid) + 8) {
              ^
77.         uint64_t chunksize;
78.         if (!memcmp(p, ff_asf_data_header, sizeof(ff_asf_guid))) {

libavformat/mms.c:78:14: Taking false branch
76.     while(end - p >= sizeof(ff_asf_guid) + 8) {
77.         uint64_t chunksize;
78.         if (!memcmp(p, ff_asf_data_header, sizeof(ff_asf_guid))) {
                 ^
79.             chunksize = 50; // see Reference [2] section 5.1
80.         } else {

libavformat/mms.c:81:13: 
79.             chunksize = 50; // see Reference [2] section 5.1
80.         } else {
81.             chunksize = AV_RL64(p + sizeof(ff_asf_guid));
                ^
82.         }
83.         if (!chunksize || chunksize > end - p) {

libavformat/mms.c:83:14: Taking false branch
81.             chunksize = AV_RL64(p + sizeof(ff_asf_guid));
82.         }
83.         if (!chunksize || chunksize > end - p) {
                 ^
84.             av_log(NULL, AV_LOG_ERROR,
85.                    "Corrupt stream (header chunksize %"PRId64" is invalid)\n",

libavformat/mms.c:83:27: Taking false branch
81.             chunksize = AV_RL64(p + sizeof(ff_asf_guid));
82.         }
83.         if (!chunksize || chunksize > end - p) {
                              ^
84.             av_log(NULL, AV_LOG_ERROR,
85.                    "Corrupt stream (header chunksize %"PRId64" is invalid)\n",

libavformat/mms.c:89:14: Taking false branch
87.             return AVERROR_INVALIDDATA;
88.         }
89.         if (!memcmp(p, ff_asf_file_header, sizeof(ff_asf_guid))) {
                 ^
90.             /* read packet size */
91.             if (end - p > sizeof(ff_asf_guid) * 2 + 68) {

libavformat/mms.c:100:21: Taking true branch
 98.                 }
 99.             }
100.         } else if (!memcmp(p, ff_asf_stream_header, sizeof(ff_asf_guid))) {
                         ^
101.             flags     = AV_RL16(p + sizeof(ff_asf_guid)*3 + 24);
102.             stream_id = flags & 0x7F;

libavformat/mms.c:101:13: 
 99.             }
100.         } else if (!memcmp(p, ff_asf_stream_header, sizeof(ff_asf_guid))) {
101.             flags     = AV_RL16(p + sizeof(ff_asf_guid)*3 + 24);
                 ^
102.             stream_id = flags & 0x7F;
103.             //The second condition is for checking CS_PKT_STREAM_ID_REQUEST packet size,

libavformat/mms.c:102:13: 
100.         } else if (!memcmp(p, ff_asf_stream_header, sizeof(ff_asf_guid))) {
101.             flags     = AV_RL16(p + sizeof(ff_asf_guid)*3 + 24);
102.             stream_id = flags & 0x7F;
                 ^
103.             //The second condition is for checking CS_PKT_STREAM_ID_REQUEST packet size,
104.             //we can calcuate the packet size by stream_num.

libavformat/mms.c:106:17: Taking true branch
104.             //we can calcuate the packet size by stream_num.
105.             //Please see function send_stream_selection_request().
106.             if (mms->stream_num < MMS_MAX_STREAMS &&
                     ^
107.                     46 + mms->stream_num * 6 < sizeof(mms->out_buffer)) {
108.                 mms->streams = av_fast_realloc(mms->streams,

libavformat/mms.c:107:21: Taking true branch
105.             //Please see function send_stream_selection_request().
106.             if (mms->stream_num < MMS_MAX_STREAMS &&
107.                     46 + mms->stream_num * 6 < sizeof(mms->out_buffer)) {
                         ^
108.                 mms->streams = av_fast_realloc(mms->streams,
109.                                    &mms->nb_streams_allocated,

libavformat/mms.c:108:17: 
106.             if (mms->stream_num < MMS_MAX_STREAMS &&
107.                     46 + mms->stream_num * 6 < sizeof(mms->out_buffer)) {
108.                 mms->streams = av_fast_realloc(mms->streams,
                     ^
109.                                    &mms->nb_streams_allocated,
110.                                    (mms->stream_num + 1) * sizeof(MMSStream));

libavcodec/utils.c:48:1: start of procedure av_fast_realloc()
  46. static void *codec_mutex;
  47. 
  48. void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)
      ^
  49. {
  50.     if(min_size < *size)

libavcodec/utils.c:50:8: Taking false branch
  48. void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)
  49. {
  50.     if(min_size < *size)
             ^
  51.         return ptr;
  52. 

libavcodec/utils.c:53:12: Condition is false
  51.         return ptr;
  52. 
  53.     *size= FFMAX(17*min_size/16 + 32, min_size);
                 ^
  54. 
  55.     ptr= av_realloc(ptr, *size);

libavcodec/utils.c:53:5: 
  51.         return ptr;
  52. 
  53.     *size= FFMAX(17*min_size/16 + 32, min_size);
          ^
  54. 
  55.     ptr= av_realloc(ptr, *size);

libavcodec/utils.c:55:5: 
  53.     *size= FFMAX(17*min_size/16 + 32, min_size);
  54. 
  55.     ptr= av_realloc(ptr, *size);
          ^
  56.     if(!ptr) //we could set this to the unmodified min_size but this is safer if the user lost the ptr and uses NULL now
  57.         *size= 0;

libavutil/mem.c:119:1: start of procedure av_realloc()
    117. }
    118. 
    119. void *av_realloc(void *ptr, unsigned int size)
         ^
    120. {
    121. #if CONFIG_MEMALIGN_HACK

libavutil/mem.c:126:8: Taking true branch
    124. 
    125.     /* let's disallow possible ambiguous cases */
    126.     if(size > (INT_MAX-16) )
                ^
    127.         return NULL;
    128. 

libavutil/mem.c:127:9: 
    125.     /* let's disallow possible ambiguous cases */
    126.     if(size > (INT_MAX-16) )
    127.         return NULL;
                 ^
    128. 
    129. #if CONFIG_MEMALIGN_HACK

libavutil/mem.c:137:1: return from a call to av_realloc
    135.     return realloc(ptr, size);
    136. #endif
    137. }
         ^
    138. 
    139. void av_free(void *ptr)

libavcodec/utils.c:56:9: Taking true branch
  54. 
  55.     ptr= av_realloc(ptr, *size);
  56.     if(!ptr) //we could set this to the unmodified min_size but this is safer if the user lost the ptr and uses NULL now
              ^
  57.         *size= 0;
  58. 

libavcodec/utils.c:57:9: 
  55.     ptr= av_realloc(ptr, *size);
  56.     if(!ptr) //we could set this to the unmodified min_size but this is safer if the user lost the ptr and uses NULL now
  57.         *size= 0;
              ^
  58. 
  59.     return ptr;

libavcodec/utils.c:59:5: 
  57.         *size= 0;
  58. 
  59.     return ptr;
          ^
  60. }
  61. 

libavcodec/utils.c:60:1: return from a call to av_fast_realloc
  58. 
  59.     return ptr;
  60. }
      ^
  61. 
  62. void av_fast_malloc(void *ptr, unsigned int *size, unsigned int min_size)

libavformat/mms.c:111:17: 
109.                                    &mms->nb_streams_allocated,
110.                                    (mms->stream_num + 1) * sizeof(MMSStream));
111.                 mms->streams[mms->stream_num].id = stream_id;
                     ^
112.                 mms->stream_num++;
113.             } else {

int ff_mms_asf_header_parser(MMSContext *mms)
{
    uint8_t *p = mms->asf_header;
    uint8_t *end;
    int flags, stream_id;
    mms->stream_num = 0;
    if (mms->asf_header_size < sizeof(ff_asf_guid) * 2 + 22 ||
        memcmp(p, ff_asf_header, sizeof(ff_asf_guid))) {
        av_log(NULL, AV_LOG_ERROR,
               "Corrupt stream (invalid ASF header, size=%d)\n",
               mms->asf_header_size);
        return AVERROR_INVALIDDATA;
    }
    end = mms->asf_header + mms->asf_header_size;
    p += sizeof(ff_asf_guid) + 14;
    while(end - p >= sizeof(ff_asf_guid) + 8) {
        uint64_t chunksize;
        if (!memcmp(p, ff_asf_data_header, sizeof(ff_asf_guid))) {
            chunksize = 50;
        } else {
            chunksize = AV_RL64(p + sizeof(ff_asf_guid));
        }
        if (!chunksize || chunksize > end - p) {
            av_log(NULL, AV_LOG_ERROR,
                   "Corrupt stream (header chunksize %"PRId64" is invalid)\n",
                   chunksize);
            return AVERROR_INVALIDDATA;
        }
        if (!memcmp(p, ff_asf_file_header, sizeof(ff_asf_guid))) {
            if (end - p > sizeof(ff_asf_guid) * 2 + 68) {
                mms->asf_packet_len = AV_RL32(p + sizeof(ff_asf_guid) * 2 + 64);
                if (mms->asf_packet_len <= 0 || mms->asf_packet_len > sizeof(mms->in_buffer)) {
                    av_log(NULL, AV_LOG_ERROR,
                           "Corrupt stream (too large pkt_len %d)\n",
                           mms->asf_packet_len);
                    return AVERROR_INVALIDDATA;
                }
            }
        } else if (!memcmp(p, ff_asf_stream_header, sizeof(ff_asf_guid))) {
            flags     = AV_RL16(p + sizeof(ff_asf_guid)*3 + 24);
            stream_id = flags & 0x7F;
            if (mms->stream_num < MMS_MAX_STREAMS &&
                    46 + mms->stream_num * 6 < sizeof(mms->out_buffer)) {
                mms->streams = av_fast_realloc(mms->streams,
                                   &mms->nb_streams_allocated,
                                   (mms->stream_num + 1) * sizeof(MMSStream));
                mms->streams[mms->stream_num].id = stream_id;
                mms->stream_num++;
            } else {
                av_log(NULL, AV_LOG_ERROR,
                       "Corrupt stream (too many A/V streams)\n");
                return AVERROR_INVALIDDATA;
            }
        } else if (!memcmp(p, ff_asf_head1_guid, sizeof(ff_asf_guid))) {
            chunksize = 46;
        }
        p += chunksize;
    }
    return 0;
}
['int ff_mms_asf_header_parser(MMSContext *mms)\n{\n    uint8_t *p = mms->asf_header;\n    uint8_t *end;\n    int flags, stream_id;\n    mms->stream_num = 0;\n    if (mms->asf_header_size < sizeof(ff_asf_guid) * 2 + 22 ||\n        memcmp(p, ff_asf_header, sizeof(ff_asf_guid))) {\n        av_log(NULL, AV_LOG_ERROR,\n               "Corrupt stream (invalid ASF header, size=%d)\\n",\n               mms->asf_header_size);\n        return AVERROR_INVALIDDATA;\n    }\n    end = mms->asf_header + mms->asf_header_size;\n    p += sizeof(ff_asf_guid) + 14;\n    while(end - p >= sizeof(ff_asf_guid) + 8) {\n        uint64_t chunksize;\n        if (!memcmp(p, ff_asf_data_header, sizeof(ff_asf_guid))) {\n            chunksize = 50;\n        } else {\n            chunksize = AV_RL64(p + sizeof(ff_asf_guid));\n        }\n        if (!chunksize || chunksize > end - p) {\n            av_log(NULL, AV_LOG_ERROR,\n                   "Corrupt stream (header chunksize %"PRId64" is invalid)\\n",\n                   chunksize);\n            return AVERROR_INVALIDDATA;\n        }\n        if (!memcmp(p, ff_asf_file_header, sizeof(ff_asf_guid))) {\n            if (end - p > sizeof(ff_asf_guid) * 2 + 68) {\n                mms->asf_packet_len = AV_RL32(p + sizeof(ff_asf_guid) * 2 + 64);\n                if (mms->asf_packet_len <= 0 || mms->asf_packet_len > sizeof(mms->in_buffer)) {\n                    av_log(NULL, AV_LOG_ERROR,\n                           "Corrupt stream (too large pkt_len %d)\\n",\n                           mms->asf_packet_len);\n                    return AVERROR_INVALIDDATA;\n                }\n            }\n        } else if (!memcmp(p, ff_asf_stream_header, sizeof(ff_asf_guid))) {\n            flags     = AV_RL16(p + sizeof(ff_asf_guid)*3 + 24);\n            stream_id = flags & 0x7F;\n            if (mms->stream_num < MMS_MAX_STREAMS &&\n                    46 + mms->stream_num * 6 < sizeof(mms->out_buffer)) {\n                mms->streams = av_fast_realloc(mms->streams,\n                                   &mms->nb_streams_allocated,\n                                   (mms->stream_num + 1) * sizeof(MMSStream));\n                mms->streams[mms->stream_num].id = stream_id;\n                mms->stream_num++;\n            } else {\n                av_log(NULL, AV_LOG_ERROR,\n                       "Corrupt stream (too many A/V streams)\\n");\n                return AVERROR_INVALIDDATA;\n            }\n        } else if (!memcmp(p, ff_asf_head1_guid, sizeof(ff_asf_guid))) {\n            chunksize = 46;\n        }\n        p += chunksize;\n    }\n    return 0;\n}', 'void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)\n{\n    if(min_size < *size)\n        return ptr;\n    *size= FFMAX(17*min_size/16 + 32, min_size);\n    ptr= av_realloc(ptr, *size);\n    if(!ptr)\n        *size= 0;\n    return ptr;\n}', 'void *av_realloc(void *ptr, unsigned int size)\n{\n#if CONFIG_MEMALIGN_HACK\n    int diff;\n#endif\n    if(size > (INT_MAX-16) )\n        return NULL;\n#if CONFIG_MEMALIGN_HACK\n    if(!ptr) return av_malloc(size);\n    diff= ((char*)ptr)[-1];\n    return (char*)realloc((char*)ptr - diff, size + diff) + diff;\n#else\n    return realloc(ptr, size);\n#endif\n}']