libavcodec/flac.c:622: error: Null Dereference
  pointer `s->bitstream` last assigned on line 618 could be null and is dereferenced at line 622, column 41.

libavcodec/flac.c:605:1: start of procedure flac_decode_frame()
603. }
604. 
605. static int flac_decode_frame(AVCodecContext *avctx,
     ^
606.                             void *data, int *data_size,
607.                             const uint8_t *buf, int buf_size)

libavcodec/flac.c:609:5: 
607.                             const uint8_t *buf, int buf_size)
608. {
609.     FLACContext *s = avctx->priv_data;
         ^
610.     int tmp = 0, i, j = 0, input_buf_size = 0;
611.     int16_t *samples = data;

libavcodec/flac.c:610:5: 
608. {
609.     FLACContext *s = avctx->priv_data;
610.     int tmp = 0, i, j = 0, input_buf_size = 0;
         ^
611.     int16_t *samples = data;
612.     int alloc_data_size= *data_size;

libavcodec/flac.c:611:5: 
609.     FLACContext *s = avctx->priv_data;
610.     int tmp = 0, i, j = 0, input_buf_size = 0;
611.     int16_t *samples = data;
         ^
612.     int alloc_data_size= *data_size;
613. 

libavcodec/flac.c:612:5: 
610.     int tmp = 0, i, j = 0, input_buf_size = 0;
611.     int16_t *samples = data;
612.     int alloc_data_size= *data_size;
         ^
613. 
614.     *data_size=0;

libavcodec/flac.c:614:5: 
612.     int alloc_data_size= *data_size;
613. 
614.     *data_size=0;
         ^
615. 
616.     if(s->max_framesize == 0){

libavcodec/flac.c:616:8: Taking true branch
614.     *data_size=0;
615. 
616.     if(s->max_framesize == 0){
            ^
617.         s->max_framesize= FFMAX(4, buf_size); // should hopefully be enough for the first header
618.         s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize);

libavcodec/flac.c:617:27: Condition is false
615. 
616.     if(s->max_framesize == 0){
617.         s->max_framesize= FFMAX(4, buf_size); // should hopefully be enough for the first header
                               ^
618.         s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize);
619.     }

libavcodec/flac.c:617:9: 
615. 
616.     if(s->max_framesize == 0){
617.         s->max_framesize= FFMAX(4, buf_size); // should hopefully be enough for the first header
             ^
618.         s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize);
619.     }

libavcodec/flac.c:618:9: 
616.     if(s->max_framesize == 0){
617.         s->max_framesize= FFMAX(4, buf_size); // should hopefully be enough for the first header
618.         s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize);
             ^
619.     }
620. 

libavcodec/utils.c:67:1: start of procedure av_fast_realloc()
  65. static int volatile entangled_thread_counter=0;
  66. 
  67. void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)
      ^
  68. {
  69.     if(min_size < *size)

libavcodec/utils.c:69:8: Taking false branch
  67. void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)
  68. {
  69.     if(min_size < *size)
             ^
  70.         return ptr;
  71. 

libavcodec/utils.c:72:12: Condition is false
  70.         return ptr;
  71. 
  72.     *size= FFMAX(17*min_size/16 + 32, min_size);
                 ^
  73. 
  74.     ptr= av_realloc(ptr, *size);

libavcodec/utils.c:72:5: 
  70.         return ptr;
  71. 
  72.     *size= FFMAX(17*min_size/16 + 32, min_size);
          ^
  73. 
  74.     ptr= av_realloc(ptr, *size);

libavcodec/utils.c:74:5: 
  72.     *size= FFMAX(17*min_size/16 + 32, min_size);
  73. 
  74.     ptr= av_realloc(ptr, *size);
          ^
  75.     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
  76.         *size= 0;

libavutil/mem.c:94:1: start of procedure av_realloc()
    92. }
    93. 
    94. void *av_realloc(void *ptr, unsigned int size)
        ^
    95. {
    96. #ifdef CONFIG_MEMALIGN_HACK

libavutil/mem.c:101:8: Taking true branch
     99. 
    100.     /* let's disallow possible ambiguous cases */
    101.     if(size > (INT_MAX-16) )
                ^
    102.         return NULL;
    103. 

libavutil/mem.c:102:9: 
    100.     /* let's disallow possible ambiguous cases */
    101.     if(size > (INT_MAX-16) )
    102.         return NULL;
                 ^
    103. 
    104. #ifdef CONFIG_MEMALIGN_HACK

libavutil/mem.c:112:1: return from a call to av_realloc
    110.     return realloc(ptr, size);
    111. #endif
    112. }
         ^
    113. 
    114. void av_free(void *ptr)

libavcodec/utils.c:75:9: Taking true branch
  73. 
  74.     ptr= av_realloc(ptr, *size);
  75.     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
              ^
  76.         *size= 0;
  77. 

libavcodec/utils.c:76:9: 
  74.     ptr= av_realloc(ptr, *size);
  75.     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
  76.         *size= 0;
              ^
  77. 
  78.     return ptr;

libavcodec/utils.c:78:5: 
  76.         *size= 0;
  77. 
  78.     return ptr;
          ^
  79. }
  80. 

libavcodec/utils.c:79:1: return from a call to av_fast_realloc
  77. 
  78.     return ptr;
  79. }
      ^
  80. 
  81. /* encoder management */

libavcodec/flac.c:621:8: Taking true branch
619.     }
620. 
621.     if(1 && s->max_framesize){//FIXME truncated
            ^
622.             if(s->bitstream_size < 4 || AV_RL32(s->bitstream) != MKTAG('f','L','a','C'))
623.                 buf_size= FFMIN(buf_size, s->max_framesize - FFMIN(s->bitstream_size, s->max_framesize));

libavcodec/flac.c:621:13: Taking true branch
619.     }
620. 
621.     if(1 && s->max_framesize){//FIXME truncated
                 ^
622.             if(s->bitstream_size < 4 || AV_RL32(s->bitstream) != MKTAG('f','L','a','C'))
623.                 buf_size= FFMIN(buf_size, s->max_framesize - FFMIN(s->bitstream_size, s->max_framesize));

libavcodec/flac.c:622:16: Taking false branch
620. 
621.     if(1 && s->max_framesize){//FIXME truncated
622.             if(s->bitstream_size < 4 || AV_RL32(s->bitstream) != MKTAG('f','L','a','C'))
                    ^
623.                 buf_size= FFMIN(buf_size, s->max_framesize - FFMIN(s->bitstream_size, s->max_framesize));
624.             input_buf_size= buf_size;

libavcodec/flac.c:622:41: 
620. 
621.     if(1 && s->max_framesize){//FIXME truncated
622.             if(s->bitstream_size < 4 || AV_RL32(s->bitstream) != MKTAG('f','L','a','C'))
                                             ^
623.                 buf_size= FFMIN(buf_size, s->max_framesize - FFMIN(s->bitstream_size, s->max_framesize));
624.             input_buf_size= buf_size;

static int flac_decode_frame(AVCodecContext *avctx,
                            void *data, int *data_size,
                            const uint8_t *buf, int buf_size)
{
    FLACContext *s = avctx->priv_data;
    int tmp = 0, i, j = 0, input_buf_size = 0;
    int16_t *samples = data;
    int alloc_data_size= *data_size;
    *data_size=0;
    if(s->max_framesize == 0){
        s->max_framesize= FFMAX(4, buf_size);
        s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize);
    }
    if(1 && s->max_framesize){
            if(s->bitstream_size < 4 || AV_RL32(s->bitstream) != MKTAG('f','L','a','C'))
                buf_size= FFMIN(buf_size, s->max_framesize - FFMIN(s->bitstream_size, s->max_framesize));
            input_buf_size= buf_size;
            if(s->bitstream_size + buf_size < buf_size || s->bitstream_index + s->bitstream_size + buf_size < s->bitstream_index)
                return -1;
            if(s->allocated_bitstream_size < s->bitstream_size + buf_size)
                s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->bitstream_size + buf_size);
            if(s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size){
                memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size);
                s->bitstream_index=0;
            }
            memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size);
            buf= &s->bitstream[s->bitstream_index];
            buf_size += s->bitstream_size;
            s->bitstream_size= buf_size;
            if(buf_size < s->max_framesize && input_buf_size){
                return input_buf_size;
            }
    }
    init_get_bits(&s->gb, buf, buf_size*8);
    if(metadata_parse(s))
        goto end;
        tmp = show_bits(&s->gb, 16);
        if((tmp & 0xFFFE) != 0xFFF8){
            av_log(s->avctx, AV_LOG_ERROR, "FRAME HEADER not here\n");
            while(get_bits_count(&s->gb)/8+2 < buf_size && (show_bits(&s->gb, 16) & 0xFFFE) != 0xFFF8)
                skip_bits(&s->gb, 8);
            goto end;
        }
        skip_bits(&s->gb, 16);
        if (decode_frame(s, alloc_data_size) < 0){
            av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\n");
            s->bitstream_size=0;
            s->bitstream_index=0;
            return -1;
        }
#if 0
    if (s->order == MID_SIDE)
    {
        short *left = samples;
        short *right = samples + s->blocksize;
        for (i = 0; i < s->blocksize; i += 2)
        {
            uint32_t x = s->decoded[0][i];
            uint32_t y = s->decoded[0][i+1];
            right[i] = x - (y / 2);
            left[i] = right[i] + y;
        }
        *data_size = 2 * s->blocksize;
    }
    else
    {
    for (i = 0; i < s->channels; i++)
    {
        switch(s->order)
        {
            case INDEPENDENT:
                for (j = 0; j < s->blocksize; j++)
                    samples[(s->blocksize*i)+j] = s->decoded[i][j];
                break;
            case LEFT_SIDE:
            case RIGHT_SIDE:
                if (i == 0)
                    for (j = 0; j < s->blocksize; j++)
                        samples[(s->blocksize*i)+j] = s->decoded[0][j];
                else
                    for (j = 0; j < s->blocksize; j++)
                        samples[(s->blocksize*i)+j] = s->decoded[0][j] - s->decoded[i][j];
                break;
        }
        *data_size += s->blocksize;
    }
    }
#else
#define DECORRELATE(left, right)\
            assert(s->channels == 2);\
            for (i = 0; i < s->blocksize; i++)\
            {\
                int a= s->decoded[0][i];\
                int b= s->decoded[1][i];\
                *samples++ = ((left)  << (24 - s->bps)) >> 8;\
                *samples++ = ((right) << (24 - s->bps)) >> 8;\
            }\
            break;
    switch(s->decorrelation)
    {
        case INDEPENDENT:
            for (j = 0; j < s->blocksize; j++)
            {
                for (i = 0; i < s->channels; i++)
                    *samples++ = (s->decoded[i][j] << (24 - s->bps)) >> 8;
            }
            break;
        case LEFT_SIDE:
            DECORRELATE(a,a-b)
        case RIGHT_SIDE:
            DECORRELATE(a+b,b)
        case MID_SIDE:
            DECORRELATE( (a-=b>>1) + b, a)
    }
#endif
    *data_size = (int8_t *)samples - (int8_t *)data;
end:
    i= (get_bits_count(&s->gb)+7)/8;
    if(i > buf_size){
        av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", i - buf_size);
        s->bitstream_size=0;
        s->bitstream_index=0;
        return -1;
    }
    if(s->bitstream_size){
        s->bitstream_index += i;
        s->bitstream_size  -= i;
        return input_buf_size;
    }else
        return i;
}
['static int flac_decode_frame(AVCodecContext *avctx,\n                            void *data, int *data_size,\n                            const uint8_t *buf, int buf_size)\n{\n    FLACContext *s = avctx->priv_data;\n    int tmp = 0, i, j = 0, input_buf_size = 0;\n    int16_t *samples = data;\n    int alloc_data_size= *data_size;\n    *data_size=0;\n    if(s->max_framesize == 0){\n        s->max_framesize= FFMAX(4, buf_size);\n        s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize);\n    }\n    if(1 && s->max_framesize){\n            if(s->bitstream_size < 4 || AV_RL32(s->bitstream) != MKTAG(\'f\',\'L\',\'a\',\'C\'))\n                buf_size= FFMIN(buf_size, s->max_framesize - FFMIN(s->bitstream_size, s->max_framesize));\n            input_buf_size= buf_size;\n            if(s->bitstream_size + buf_size < buf_size || s->bitstream_index + s->bitstream_size + buf_size < s->bitstream_index)\n                return -1;\n            if(s->allocated_bitstream_size < s->bitstream_size + buf_size)\n                s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->bitstream_size + buf_size);\n            if(s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size){\n                memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size);\n                s->bitstream_index=0;\n            }\n            memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size);\n            buf= &s->bitstream[s->bitstream_index];\n            buf_size += s->bitstream_size;\n            s->bitstream_size= buf_size;\n            if(buf_size < s->max_framesize && input_buf_size){\n                return input_buf_size;\n            }\n    }\n    init_get_bits(&s->gb, buf, buf_size*8);\n    if(metadata_parse(s))\n        goto end;\n        tmp = show_bits(&s->gb, 16);\n        if((tmp & 0xFFFE) != 0xFFF8){\n            av_log(s->avctx, AV_LOG_ERROR, "FRAME HEADER not here\\n");\n            while(get_bits_count(&s->gb)/8+2 < buf_size && (show_bits(&s->gb, 16) & 0xFFFE) != 0xFFF8)\n                skip_bits(&s->gb, 8);\n            goto end;\n        }\n        skip_bits(&s->gb, 16);\n        if (decode_frame(s, alloc_data_size) < 0){\n            av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\\n");\n            s->bitstream_size=0;\n            s->bitstream_index=0;\n            return -1;\n        }\n#if 0\n    if (s->order == MID_SIDE)\n    {\n        short *left = samples;\n        short *right = samples + s->blocksize;\n        for (i = 0; i < s->blocksize; i += 2)\n        {\n            uint32_t x = s->decoded[0][i];\n            uint32_t y = s->decoded[0][i+1];\n            right[i] = x - (y / 2);\n            left[i] = right[i] + y;\n        }\n        *data_size = 2 * s->blocksize;\n    }\n    else\n    {\n    for (i = 0; i < s->channels; i++)\n    {\n        switch(s->order)\n        {\n            case INDEPENDENT:\n                for (j = 0; j < s->blocksize; j++)\n                    samples[(s->blocksize*i)+j] = s->decoded[i][j];\n                break;\n            case LEFT_SIDE:\n            case RIGHT_SIDE:\n                if (i == 0)\n                    for (j = 0; j < s->blocksize; j++)\n                        samples[(s->blocksize*i)+j] = s->decoded[0][j];\n                else\n                    for (j = 0; j < s->blocksize; j++)\n                        samples[(s->blocksize*i)+j] = s->decoded[0][j] - s->decoded[i][j];\n                break;\n        }\n        *data_size += s->blocksize;\n    }\n    }\n#else\n#define DECORRELATE(left, right)\\\n            assert(s->channels == 2);\\\n            for (i = 0; i < s->blocksize; i++)\\\n            {\\\n                int a= s->decoded[0][i];\\\n                int b= s->decoded[1][i];\\\n                *samples++ = ((left)  << (24 - s->bps)) >> 8;\\\n                *samples++ = ((right) << (24 - s->bps)) >> 8;\\\n            }\\\n            break;\n    switch(s->decorrelation)\n    {\n        case INDEPENDENT:\n            for (j = 0; j < s->blocksize; j++)\n            {\n                for (i = 0; i < s->channels; i++)\n                    *samples++ = (s->decoded[i][j] << (24 - s->bps)) >> 8;\n            }\n            break;\n        case LEFT_SIDE:\n            DECORRELATE(a,a-b)\n        case RIGHT_SIDE:\n            DECORRELATE(a+b,b)\n        case MID_SIDE:\n            DECORRELATE( (a-=b>>1) + b, a)\n    }\n#endif\n    *data_size = (int8_t *)samples - (int8_t *)data;\nend:\n    i= (get_bits_count(&s->gb)+7)/8;\n    if(i > buf_size){\n        av_log(s->avctx, AV_LOG_ERROR, "overread: %d\\n", i - buf_size);\n        s->bitstream_size=0;\n        s->bitstream_index=0;\n        return -1;\n    }\n    if(s->bitstream_size){\n        s->bitstream_index += i;\n        s->bitstream_size  -= i;\n        return input_buf_size;\n    }else\n        return i;\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#ifdef CONFIG_MEMALIGN_HACK\n    int diff;\n#endif\n    if(size > (INT_MAX-16) )\n        return NULL;\n#ifdef 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}']