libavcodec/mlpdec.c:1018: error: Null Dereference
  pointer `&gb->buffer` last assigned on line 1016 could be null and is dereferenced by call to `show_bits_long()` at line 1018, column 9.

libavcodec/mlpdec.c:995:1: start of procedure read_access_unit()
993.  *  otherwise returns the number of bytes consumed. */
994. 
995. static int read_access_unit(AVCodecContext *avctx, void* data, int *data_size,
     ^
996.                             const uint8_t *buf, int buf_size)
997. {

libavcodec/mlpdec.c:998:5: 
 996.                             const uint8_t *buf, int buf_size)
 997. {
 998.     MLPDecodeContext *m = avctx->priv_data;
          ^
 999.     GetBitContext gb;
1000.     unsigned int length, substr;

libavcodec/mlpdec.c:1002:5: 
1000.     unsigned int length, substr;
1001.     unsigned int substream_start;
1002.     unsigned int header_size = 4;
          ^
1003.     unsigned int substr_header_size = 0;
1004.     uint8_t substream_parity_present[MAX_SUBSTREAMS];

libavcodec/mlpdec.c:1003:5: 
1001.     unsigned int substream_start;
1002.     unsigned int header_size = 4;
1003.     unsigned int substr_header_size = 0;
          ^
1004.     uint8_t substream_parity_present[MAX_SUBSTREAMS];
1005.     uint16_t substream_data_len[MAX_SUBSTREAMS];

libavcodec/mlpdec.c:1008:9: Taking false branch
1006.     uint8_t parity_bits;
1007. 
1008.     if (buf_size < 4)
              ^
1009.         return 0;
1010. 

libavcodec/mlpdec.c:1011:5: 
1009.         return 0;
1010. 
1011.     length = (AV_RB16(buf) & 0xfff) * 2;
          ^
1012. 
1013.     if (length > buf_size)

libavcodec/mlpdec.c:1013:9: Taking false branch
1011.     length = (AV_RB16(buf) & 0xfff) * 2;
1012. 
1013.     if (length > buf_size)
              ^
1014.         return -1;
1015. 

libavcodec/mlpdec.c:1016:5: 
1014.         return -1;
1015. 
1016.     init_get_bits(&gb, (buf + 4), (length - 4) * 8);
          ^
1017. 
1018.     if (show_bits_long(&gb, 31) == (0xf8726fba >> 1)) {

libavcodec/bitstream.h:719:1: start of procedure init_get_bits()
  717.  * @param bit_size the size of the buffer in bits
  718.  */
  719. static inline void init_get_bits(GetBitContext *s,
       ^
  720.                    const uint8_t *buffer, int bit_size)
  721. {

libavcodec/bitstream.h:722:5: 
  720.                    const uint8_t *buffer, int bit_size)
  721. {
  722.     int buffer_size= (bit_size+7)>>3;
           ^
  723.     if(buffer_size < 0 || bit_size < 0) {
  724.         buffer_size = bit_size = 0;

libavcodec/bitstream.h:723:8: Taking true branch
  721. {
  722.     int buffer_size= (bit_size+7)>>3;
  723.     if(buffer_size < 0 || bit_size < 0) {
              ^
  724.         buffer_size = bit_size = 0;
  725.         buffer = NULL;

libavcodec/bitstream.h:724:9: 
  722.     int buffer_size= (bit_size+7)>>3;
  723.     if(buffer_size < 0 || bit_size < 0) {
  724.         buffer_size = bit_size = 0;
               ^
  725.         buffer = NULL;
  726.     }

libavcodec/bitstream.h:725:9: 
  723.     if(buffer_size < 0 || bit_size < 0) {
  724.         buffer_size = bit_size = 0;
  725.         buffer = NULL;
               ^
  726.     }
  727. 

libavcodec/bitstream.h:728:5: 
  726.     }
  727. 
  728.     s->buffer= buffer;
           ^
  729.     s->size_in_bits= bit_size;
  730.     s->buffer_end= buffer + buffer_size;

libavcodec/bitstream.h:729:5: 
  727. 
  728.     s->buffer= buffer;
  729.     s->size_in_bits= bit_size;
           ^
  730.     s->buffer_end= buffer + buffer_size;
  731. #ifdef ALT_BITSTREAM_READER

libavcodec/bitstream.h:730:5: 
  728.     s->buffer= buffer;
  729.     s->size_in_bits= bit_size;
  730.     s->buffer_end= buffer + buffer_size;
           ^
  731. #ifdef ALT_BITSTREAM_READER
  732.     s->index=0;

libavcodec/bitstream.h:732:5: 
  730.     s->buffer_end= buffer + buffer_size;
  731. #ifdef ALT_BITSTREAM_READER
  732.     s->index=0;
           ^
  733. #elif defined LIBMPEG2_BITSTREAM_READER
  734.     s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));

libavcodec/bitstream.h:742:1: return from a call to init_get_bits
  740.     skip_bits_long(s, 0);
  741. #endif
  742. }
       ^
  743. 
  744. static inline void align_get_bits(GetBitContext *s)

libavcodec/mlpdec.c:1018:9: 
1016.     init_get_bits(&gb, (buf + 4), (length - 4) * 8);
1017. 
1018.     if (show_bits_long(&gb, 31) == (0xf8726fba >> 1)) {
              ^
1019.         dprintf(m->avctx, "Found major sync.\n");
1020.         if (read_major_sync(m, &gb) < 0)

libavcodec/bitstream.h:694:1: start of procedure show_bits_long()
  692.  * shows 0-32 bits.
  693.  */
  694. static inline unsigned int show_bits_long(GetBitContext *s, int n){
       ^
  695.     if(n<=17) return show_bits(s, n);
  696.     else{

libavcodec/bitstream.h:695:8: Taking true branch
  693.  */
  694. static inline unsigned int show_bits_long(GetBitContext *s, int n){
  695.     if(n<=17) return show_bits(s, n);
              ^
  696.     else{
  697.         GetBitContext gb= *s;

libavcodec/bitstream.h:695:15: 
  693.  */
  694. static inline unsigned int show_bits_long(GetBitContext *s, int n){
  695.     if(n<=17) return show_bits(s, n);
                     ^
  696.     else{
  697.         GetBitContext gb= *s;

libavcodec/bitstream.h:630:1: start of procedure show_bits()
    628.  * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
    629.  */
    630. static inline unsigned int show_bits(GetBitContext *s, int n){
         ^
    631.     register int tmp;
    632.     OPEN_READER(re, s)

libavcodec/bitstream.h:632:5: 
    630. static inline unsigned int show_bits(GetBitContext *s, int n){
    631.     register int tmp;
    632.     OPEN_READER(re, s)
             ^
    633.     UPDATE_CACHE(re, s)
    634.     tmp= SHOW_UBITS(re, s, n);

libavcodec/bitstream.h:633:5: 
    631.     register int tmp;
    632.     OPEN_READER(re, s)
    633.     UPDATE_CACHE(re, s)
             ^
    634.     tmp= SHOW_UBITS(re, s, n);
    635. //    CLOSE_READER(re, s)

static int read_access_unit(AVCodecContext *avctx, void* data, int *data_size,
                            const uint8_t *buf, int buf_size)
{
    MLPDecodeContext *m = avctx->priv_data;
    GetBitContext gb;
    unsigned int length, substr;
    unsigned int substream_start;
    unsigned int header_size = 4;
    unsigned int substr_header_size = 0;
    uint8_t substream_parity_present[MAX_SUBSTREAMS];
    uint16_t substream_data_len[MAX_SUBSTREAMS];
    uint8_t parity_bits;
    if (buf_size < 4)
        return 0;
    length = (AV_RB16(buf) & 0xfff) * 2;
    if (length > buf_size)
        return -1;
    init_get_bits(&gb, (buf + 4), (length - 4) * 8);
    if (show_bits_long(&gb, 31) == (0xf8726fba >> 1)) {
        dprintf(m->avctx, "Found major sync.\n");
        if (read_major_sync(m, &gb) < 0)
            goto error;
        header_size += 28;
    }
    if (!m->params_valid) {
        av_log(m->avctx, AV_LOG_WARNING,
               "Stream parameters not seen; skipping frame.\n");
        *data_size = 0;
        return length;
    }
    substream_start = 0;
    for (substr = 0; substr < m->num_substreams; substr++) {
        int extraword_present, checkdata_present, end;
        extraword_present = get_bits1(&gb);
        skip_bits1(&gb);
        checkdata_present = get_bits1(&gb);
        skip_bits1(&gb);
        end = get_bits(&gb, 12) * 2;
        substr_header_size += 2;
        if (extraword_present) {
            skip_bits(&gb, 16);
            substr_header_size += 2;
        }
        if (end + header_size + substr_header_size > length) {
            av_log(m->avctx, AV_LOG_ERROR,
                   "Indicated length of substream %d data goes off end of "
                   "packet.\n", substr);
            end = length - header_size - substr_header_size;
        }
        if (end < substream_start) {
            av_log(avctx, AV_LOG_ERROR,
                   "Indicated end offset of substream %d data "
                   "is smaller than calculated start offset.\n",
                   substr);
            goto error;
        }
        if (substr > m->max_decoded_substream)
            continue;
        substream_parity_present[substr] = checkdata_present;
        substream_data_len[substr] = end - substream_start;
        substream_start = end;
    }
    parity_bits  = calculate_parity(buf, 4);
    parity_bits ^= calculate_parity(buf + header_size, substr_header_size);
    if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) {
        av_log(avctx, AV_LOG_ERROR, "Parity check failed.\n");
        goto error;
    }
    buf += header_size + substr_header_size;
    for (substr = 0; substr <= m->max_decoded_substream; substr++) {
        SubStream *s = &m->substream[substr];
        init_get_bits(&gb, buf, substream_data_len[substr] * 8);
        s->blockpos = 0;
        do {
            if (get_bits1(&gb)) {
                if (get_bits1(&gb)) {
                    if (read_restart_header(m, &gb, buf, substr) < 0)
                        goto next_substr;
                    s->restart_seen = 1;
                }
                if (!s->restart_seen) {
                    av_log(m->avctx, AV_LOG_ERROR,
                           "No restart header present in substream %d.\n",
                           substr);
                    goto next_substr;
                }
                if (read_decoding_params(m, &gb, substr) < 0)
                    goto next_substr;
            }
            if (!s->restart_seen) {
                av_log(m->avctx, AV_LOG_ERROR,
                       "No restart header present in substream %d.\n",
                       substr);
                goto next_substr;
            }
            if (read_block_data(m, &gb, substr) < 0)
                return -1;
        } while ((get_bits_count(&gb) < substream_data_len[substr] * 8)
                 && get_bits1(&gb) == 0);
        skip_bits(&gb, (-get_bits_count(&gb)) & 15);
        if (substream_data_len[substr] * 8 - get_bits_count(&gb) >= 32 &&
            (show_bits_long(&gb, 32) == 0xd234d234 ||
             show_bits_long(&gb, 20) == 0xd234e)) {
            skip_bits(&gb, 18);
            if (substr == m->max_decoded_substream)
                av_log(m->avctx, AV_LOG_INFO, "End of stream indicated.\n");
            if (get_bits1(&gb)) {
                int shorten_by = get_bits(&gb, 13);
                shorten_by = FFMIN(shorten_by, s->blockpos);
                s->blockpos -= shorten_by;
            } else
                skip_bits(&gb, 13);
        }
        if (substream_data_len[substr] * 8 - get_bits_count(&gb) >= 16 &&
            substream_parity_present[substr]) {
            uint8_t parity, checksum;
            parity = calculate_parity(buf, substream_data_len[substr] - 2);
            if ((parity ^ get_bits(&gb, 8)) != 0xa9)
                av_log(m->avctx, AV_LOG_ERROR,
                       "Substream %d parity check failed.\n", substr);
            checksum = mlp_checksum8(buf, substream_data_len[substr] - 2);
            if (checksum != get_bits(&gb, 8))
                av_log(m->avctx, AV_LOG_ERROR, "Substream %d checksum failed.\n",
                       substr);
        }
        if (substream_data_len[substr] * 8 != get_bits_count(&gb)) {
            av_log(m->avctx, AV_LOG_ERROR, "substream %d length mismatch\n",
                   substr);
            return -1;
        }
next_substr:
        buf += substream_data_len[substr];
    }
    rematrix_channels(m, m->max_decoded_substream);
    if (output_data(m, m->max_decoded_substream, data, data_size) < 0)
        return -1;
    return length;
error:
    m->params_valid = 0;
    return -1;
}
['static int read_access_unit(AVCodecContext *avctx, void* data, int *data_size,\n                            const uint8_t *buf, int buf_size)\n{\n    MLPDecodeContext *m = avctx->priv_data;\n    GetBitContext gb;\n    unsigned int length, substr;\n    unsigned int substream_start;\n    unsigned int header_size = 4;\n    unsigned int substr_header_size = 0;\n    uint8_t substream_parity_present[MAX_SUBSTREAMS];\n    uint16_t substream_data_len[MAX_SUBSTREAMS];\n    uint8_t parity_bits;\n    if (buf_size < 4)\n        return 0;\n    length = (AV_RB16(buf) & 0xfff) * 2;\n    if (length > buf_size)\n        return -1;\n    init_get_bits(&gb, (buf + 4), (length - 4) * 8);\n    if (show_bits_long(&gb, 31) == (0xf8726fba >> 1)) {\n        dprintf(m->avctx, "Found major sync.\\n");\n        if (read_major_sync(m, &gb) < 0)\n            goto error;\n        header_size += 28;\n    }\n    if (!m->params_valid) {\n        av_log(m->avctx, AV_LOG_WARNING,\n               "Stream parameters not seen; skipping frame.\\n");\n        *data_size = 0;\n        return length;\n    }\n    substream_start = 0;\n    for (substr = 0; substr < m->num_substreams; substr++) {\n        int extraword_present, checkdata_present, end;\n        extraword_present = get_bits1(&gb);\n        skip_bits1(&gb);\n        checkdata_present = get_bits1(&gb);\n        skip_bits1(&gb);\n        end = get_bits(&gb, 12) * 2;\n        substr_header_size += 2;\n        if (extraword_present) {\n            skip_bits(&gb, 16);\n            substr_header_size += 2;\n        }\n        if (end + header_size + substr_header_size > length) {\n            av_log(m->avctx, AV_LOG_ERROR,\n                   "Indicated length of substream %d data goes off end of "\n                   "packet.\\n", substr);\n            end = length - header_size - substr_header_size;\n        }\n        if (end < substream_start) {\n            av_log(avctx, AV_LOG_ERROR,\n                   "Indicated end offset of substream %d data "\n                   "is smaller than calculated start offset.\\n",\n                   substr);\n            goto error;\n        }\n        if (substr > m->max_decoded_substream)\n            continue;\n        substream_parity_present[substr] = checkdata_present;\n        substream_data_len[substr] = end - substream_start;\n        substream_start = end;\n    }\n    parity_bits  = calculate_parity(buf, 4);\n    parity_bits ^= calculate_parity(buf + header_size, substr_header_size);\n    if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) {\n        av_log(avctx, AV_LOG_ERROR, "Parity check failed.\\n");\n        goto error;\n    }\n    buf += header_size + substr_header_size;\n    for (substr = 0; substr <= m->max_decoded_substream; substr++) {\n        SubStream *s = &m->substream[substr];\n        init_get_bits(&gb, buf, substream_data_len[substr] * 8);\n        s->blockpos = 0;\n        do {\n            if (get_bits1(&gb)) {\n                if (get_bits1(&gb)) {\n                    if (read_restart_header(m, &gb, buf, substr) < 0)\n                        goto next_substr;\n                    s->restart_seen = 1;\n                }\n                if (!s->restart_seen) {\n                    av_log(m->avctx, AV_LOG_ERROR,\n                           "No restart header present in substream %d.\\n",\n                           substr);\n                    goto next_substr;\n                }\n                if (read_decoding_params(m, &gb, substr) < 0)\n                    goto next_substr;\n            }\n            if (!s->restart_seen) {\n                av_log(m->avctx, AV_LOG_ERROR,\n                       "No restart header present in substream %d.\\n",\n                       substr);\n                goto next_substr;\n            }\n            if (read_block_data(m, &gb, substr) < 0)\n                return -1;\n        } while ((get_bits_count(&gb) < substream_data_len[substr] * 8)\n                 && get_bits1(&gb) == 0);\n        skip_bits(&gb, (-get_bits_count(&gb)) & 15);\n        if (substream_data_len[substr] * 8 - get_bits_count(&gb) >= 32 &&\n            (show_bits_long(&gb, 32) == 0xd234d234 ||\n             show_bits_long(&gb, 20) == 0xd234e)) {\n            skip_bits(&gb, 18);\n            if (substr == m->max_decoded_substream)\n                av_log(m->avctx, AV_LOG_INFO, "End of stream indicated.\\n");\n            if (get_bits1(&gb)) {\n                int shorten_by = get_bits(&gb, 13);\n                shorten_by = FFMIN(shorten_by, s->blockpos);\n                s->blockpos -= shorten_by;\n            } else\n                skip_bits(&gb, 13);\n        }\n        if (substream_data_len[substr] * 8 - get_bits_count(&gb) >= 16 &&\n            substream_parity_present[substr]) {\n            uint8_t parity, checksum;\n            parity = calculate_parity(buf, substream_data_len[substr] - 2);\n            if ((parity ^ get_bits(&gb, 8)) != 0xa9)\n                av_log(m->avctx, AV_LOG_ERROR,\n                       "Substream %d parity check failed.\\n", substr);\n            checksum = mlp_checksum8(buf, substream_data_len[substr] - 2);\n            if (checksum != get_bits(&gb, 8))\n                av_log(m->avctx, AV_LOG_ERROR, "Substream %d checksum failed.\\n",\n                       substr);\n        }\n        if (substream_data_len[substr] * 8 != get_bits_count(&gb)) {\n            av_log(m->avctx, AV_LOG_ERROR, "substream %d length mismatch\\n",\n                   substr);\n            return -1;\n        }\nnext_substr:\n        buf += substream_data_len[substr];\n    }\n    rematrix_channels(m, m->max_decoded_substream);\n    if (output_data(m, m->max_decoded_substream, data, data_size) < 0)\n        return -1;\n    return length;\nerror:\n    m->params_valid = 0;\n    return -1;\n}', 'static inline void init_get_bits(GetBitContext *s,\n                   const uint8_t *buffer, int bit_size)\n{\n    int buffer_size= (bit_size+7)>>3;\n    if(buffer_size < 0 || bit_size < 0) {\n        buffer_size = bit_size = 0;\n        buffer = NULL;\n    }\n    s->buffer= buffer;\n    s->size_in_bits= bit_size;\n    s->buffer_end= buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n    s->index=0;\n#elif defined LIBMPEG2_BITSTREAM_READER\n    s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));\n    s->bit_count = 16 + 8*((intptr_t)buffer&1);\n    skip_bits_long(s, 0);\n#elif defined A32_BITSTREAM_READER\n    s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));\n    s->bit_count = 32 + 8*((intptr_t)buffer&3);\n    skip_bits_long(s, 0);\n#endif\n}', 'static inline unsigned int show_bits_long(GetBitContext *s, int n){\n    if(n<=17) return show_bits(s, n);\n    else{\n        GetBitContext gb= *s;\n        int ret= get_bits_long(s, n);\n        *s= gb;\n        return ret;\n    }\n}', 'static inline unsigned int show_bits(GetBitContext *s, int n){\n    register int tmp;\n    OPEN_READER(re, s)\n    UPDATE_CACHE(re, s)\n    tmp= SHOW_UBITS(re, s, n);\n    return tmp;\n}']