libavcodec/flacdec.c:524: error: Null Dereference
  pointer `s->gb.buffer` last assigned on line 523 could be null and is dereferenced by call to `decode_frame()` at line 524, column 9.

libavcodec/flacdec.c:489:1: start of procedure flac_decode_frame()
487. }
488. 
489. static int flac_decode_frame(AVCodecContext *avctx, void *data,
     ^
490.                              int *got_frame_ptr, AVPacket *avpkt)
491. {

libavcodec/flacdec.c:492:5: 
490.                              int *got_frame_ptr, AVPacket *avpkt)
491. {
492.     AVFrame *frame     = data;
         ^
493.     const uint8_t *buf = avpkt->data;
494.     int buf_size = avpkt->size;

libavcodec/flacdec.c:493:5: 
491. {
492.     AVFrame *frame     = data;
493.     const uint8_t *buf = avpkt->data;
         ^
494.     int buf_size = avpkt->size;
495.     FLACContext *s = avctx->priv_data;

libavcodec/flacdec.c:494:5: 
492.     AVFrame *frame     = data;
493.     const uint8_t *buf = avpkt->data;
494.     int buf_size = avpkt->size;
         ^
495.     FLACContext *s = avctx->priv_data;
496.     int bytes_read = 0;

libavcodec/flacdec.c:495:5: 
493.     const uint8_t *buf = avpkt->data;
494.     int buf_size = avpkt->size;
495.     FLACContext *s = avctx->priv_data;
         ^
496.     int bytes_read = 0;
497.     int ret;

libavcodec/flacdec.c:496:5: 
494.     int buf_size = avpkt->size;
495.     FLACContext *s = avctx->priv_data;
496.     int bytes_read = 0;
         ^
497.     int ret;
498. 

libavcodec/flacdec.c:499:5: 
497.     int ret;
498. 
499.     *got_frame_ptr = 0;
         ^
500. 
501.     if (s->max_framesize == 0) {

libavcodec/flacdec.c:501:9: Taking true branch
499.     *got_frame_ptr = 0;
500. 
501.     if (s->max_framesize == 0) {
             ^
502.         s->max_framesize =
503.             ff_flac_get_max_frame_size(s->max_blocksize ? s->max_blocksize : FLAC_MAX_BLOCKSIZE,

libavcodec/flacdec.c:503:40: Condition is true
501.     if (s->max_framesize == 0) {
502.         s->max_framesize =
503.             ff_flac_get_max_frame_size(s->max_blocksize ? s->max_blocksize : FLAC_MAX_BLOCKSIZE,
                                            ^
504.                                        FLAC_MAX_CHANNELS, 32);
505.     }

libavcodec/flacdec.c:502:9: 
500. 
501.     if (s->max_framesize == 0) {
502.         s->max_framesize =
             ^
503.             ff_flac_get_max_frame_size(s->max_blocksize ? s->max_blocksize : FLAC_MAX_BLOCKSIZE,
504.                                        FLAC_MAX_CHANNELS, 32);

libavcodec/flac.c:148:1: start of procedure ff_flac_get_max_frame_size()
  146. }
  147. 
  148. int ff_flac_get_max_frame_size(int blocksize, int ch, int bps)
       ^
  149. {
  150.     /* Technically, there is no limit to FLAC frame size, but an encoder

libavcodec/flac.c:156:5: 
  154.     int count;
  155. 
  156.     count = 16;                  /* frame header */
           ^
  157.     count += ch * ((7+bps+7)/8); /* subframe headers */
  158.     if (ch == 2) {

libavcodec/flac.c:157:5: 
  155. 
  156.     count = 16;                  /* frame header */
  157.     count += ch * ((7+bps+7)/8); /* subframe headers */
           ^
  158.     if (ch == 2) {
  159.         /* for stereo, need to account for using decorrelation */

libavcodec/flac.c:158:9: Taking false branch
  156.     count = 16;                  /* frame header */
  157.     count += ch * ((7+bps+7)/8); /* subframe headers */
  158.     if (ch == 2) {
               ^
  159.         /* for stereo, need to account for using decorrelation */
  160.         count += (( 2*bps+1) * blocksize + 7) / 8;

libavcodec/flac.c:162:9: 
  160.         count += (( 2*bps+1) * blocksize + 7) / 8;
  161.     } else {
  162.         count += ( ch*bps    * blocksize + 7) / 8;
               ^
  163.     }
  164.     count += 2; /* frame footer */

libavcodec/flac.c:164:5: 
  162.         count += ( ch*bps    * blocksize + 7) / 8;
  163.     }
  164.     count += 2; /* frame footer */
           ^
  165. 
  166.     return count;

libavcodec/flac.c:166:5: 
  164.     count += 2; /* frame footer */
  165. 
  166.     return count;
           ^
  167. }
  168. 

libavcodec/flac.c:167:1: return from a call to ff_flac_get_max_frame_size
  165. 
  166.     return count;
  167. }
       ^
  168. 
  169. int avpriv_flac_is_extradata_valid(AVCodecContext *avctx,

libavcodec/flacdec.c:510:9: Taking false branch
508.        this amount corresponds to the smallest valid FLAC frame possible.
509.        FF F8 69 02 00 00 9A 00 00 34 46 */
510.     if (buf_size < FLAC_MIN_FRAME_SIZE)
             ^
511.         return buf_size;
512. 

libavcodec/flacdec.c:514:9: 
512. 
513.     /* check for inline header */
514.     if (AV_RB32(buf) == MKBETAG('f','L','a','C')) {
             ^
515.         if (!s->got_streaminfo && parse_streaminfo(s, buf, buf_size)) {
516.             av_log(s->avctx, AV_LOG_ERROR, "invalid header\n");

libavutil/ppc/intreadwrite.h:44:1: start of procedure AV_RL32()
  42. 
  43. #define AV_RL32 AV_RL32
  44. static av_always_inline uint32_t AV_RL32(const void *p)
      ^
  45. {
  46.     uint32_t v;

libavutil/ppc/intreadwrite.h:47:5: Skipping __infer_skip_gcc_asm_stmt(): function or method not found
  45. {
  46.     uint32_t v;
  47.     __asm__ ("lwbrx   %0, %y1" : "=r"(v) : "Z"(*(const uint32_t*)p));
          ^
  48.     return v;
  49. }

libavutil/ppc/intreadwrite.h:48:5: 
  46.     uint32_t v;
  47.     __asm__ ("lwbrx   %0, %y1" : "=r"(v) : "Z"(*(const uint32_t*)p));
  48.     return v;
          ^
  49. }
  50. 

libavutil/ppc/intreadwrite.h:49:1: return from a call to AV_RL32
  47.     __asm__ ("lwbrx   %0, %y1" : "=r"(v) : "Z"(*(const uint32_t*)p));
  48.     return v;
  49. }
      ^
  50. 
  51. #define AV_WL32 AV_WL32

libavutil/bswap.h:66:1: start of procedure av_bswap32()
  64. 
  65. #ifndef av_bswap32
  66. static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
      ^
  67. {
  68.     return AV_BSWAP32C(x);

libavutil/bswap.h:68:5: 
  66. static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
  67. {
  68.     return AV_BSWAP32C(x);
          ^
  69. }
  70. #endif

libavutil/bswap.h:69:1: return from a call to av_bswap32
  67. {
  68.     return AV_BSWAP32C(x);
  69. }
      ^
  70. #endif
  71. 

libavcodec/flacdec.c:514:9: Taking false branch
512. 
513.     /* check for inline header */
514.     if (AV_RB32(buf) == MKBETAG('f','L','a','C')) {
             ^
515.         if (!s->got_streaminfo && parse_streaminfo(s, buf, buf_size)) {
516.             av_log(s->avctx, AV_LOG_ERROR, "invalid header\n");

libavcodec/flacdec.c:523:5: 
521. 
522.     /* decode frame */
523.     init_get_bits(&s->gb, buf, buf_size*8);
         ^
524.     if (decode_frame(s) < 0) {
525.         av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\n");

libavcodec/get_bits.h:375:1: start of procedure init_get_bits()
  373.  * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
  374.  */
  375. static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,
       ^
  376.                                 int bit_size)
  377. {

libavcodec/get_bits.h:379:5: 
  377. {
  378.     int buffer_size;
  379.     int ret = 0;
           ^
  380. 
  381.     if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {

libavcodec/get_bits.h:381:9: Taking true branch
  379.     int ret = 0;
  380. 
  381.     if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {
               ^
  382.         buffer_size = bit_size = 0;
  383.         buffer      = NULL;

libavcodec/get_bits.h:382:9: 
  380. 
  381.     if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {
  382.         buffer_size = bit_size = 0;
               ^
  383.         buffer      = NULL;
  384.         ret         = AVERROR_INVALIDDATA;

libavcodec/get_bits.h:383:9: 
  381.     if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {
  382.         buffer_size = bit_size = 0;
  383.         buffer      = NULL;
               ^
  384.         ret         = AVERROR_INVALIDDATA;
  385.     }

libavcodec/get_bits.h:384:9: 
  382.         buffer_size = bit_size = 0;
  383.         buffer      = NULL;
  384.         ret         = AVERROR_INVALIDDATA;
               ^
  385.     }
  386. 

libavcodec/get_bits.h:387:5: 
  385.     }
  386. 
  387.     buffer_size = (bit_size + 7) >> 3;
           ^
  388. 
  389.     s->buffer             = buffer;

libavcodec/get_bits.h:389:5: 
  387.     buffer_size = (bit_size + 7) >> 3;
  388. 
  389.     s->buffer             = buffer;
           ^
  390.     s->size_in_bits       = bit_size;
  391. #if !UNCHECKED_BITSTREAM_READER

libavcodec/get_bits.h:390:5: 
  388. 
  389.     s->buffer             = buffer;
  390.     s->size_in_bits       = bit_size;
           ^
  391. #if !UNCHECKED_BITSTREAM_READER
  392.     s->size_in_bits_plus8 = bit_size + 8;

libavcodec/get_bits.h:392:5: 
  390.     s->size_in_bits       = bit_size;
  391. #if !UNCHECKED_BITSTREAM_READER
  392.     s->size_in_bits_plus8 = bit_size + 8;
           ^
  393. #endif
  394.     s->buffer_end         = buffer + buffer_size;

libavcodec/get_bits.h:394:5: 
  392.     s->size_in_bits_plus8 = bit_size + 8;
  393. #endif
  394.     s->buffer_end         = buffer + buffer_size;
           ^
  395.     s->index              = 0;
  396. 

libavcodec/get_bits.h:395:5: 
  393. #endif
  394.     s->buffer_end         = buffer + buffer_size;
  395.     s->index              = 0;
           ^
  396. 
  397.     return ret;

libavcodec/get_bits.h:397:5: 
  395.     s->index              = 0;
  396. 
  397.     return ret;
           ^
  398. }
  399. 

libavcodec/get_bits.h:398:1: return from a call to init_get_bits
  396. 
  397.     return ret;
  398. }
       ^
  399. 
  400. /**

libavcodec/flacdec.c:524:9: 
522.     /* decode frame */
523.     init_get_bits(&s->gb, buf, buf_size*8);
524.     if (decode_frame(s) < 0) {
             ^
525.         av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\n");
526.         return -1;

libavcodec/flacdec.c:406:1: start of procedure decode_frame()
  404. }
  405. 
  406. static int decode_frame(FLACContext *s)
       ^
  407. {
  408.     int i, ret;

libavcodec/flacdec.c:409:5: 
  407. {
  408.     int i, ret;
  409.     GetBitContext *gb = &s->gb;
           ^
  410.     FLACFrameInfo fi;
  411. 

libavcodec/flacdec.c:412:9: 
  410.     FLACFrameInfo fi;
  411. 
  412.     if (ff_flac_decode_frame_header(s->avctx, gb, &fi, 0)) {
               ^
  413.         av_log(s->avctx, AV_LOG_ERROR, "invalid frame header\n");
  414.         return -1;

libavcodec/flac.c:50:1: start of procedure ff_flac_decode_frame_header()
    48. }
    49. 
    50. int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
        ^
    51.                                 FLACFrameInfo *fi, int log_level_offset)
    52. {

libavcodec/flac.c:56:9: Taking false branch
    54. 
    55.     /* frame sync code */
    56.     if ((get_bits(gb, 15) & 0x7FFF) != 0x7FFC) {
                ^
    57.         av_log(avctx, AV_LOG_ERROR + log_level_offset, "invalid sync code\n");
    58.         return -1;

libavcodec/flac.c:62:5: 
    60. 
    61.     /* variable block size stream code */
    62.     fi->is_var_size = get_bits1(gb);
            ^
    63. 
    64.     /* block size and sample rate codes */

libavcodec/get_bits.h:271:1: start of procedure get_bits1()
      269. }
      270. 
      271. static inline unsigned int get_bits1(GetBitContext *s)
           ^
      272. {
      273.     unsigned int index = s->index;

libavcodec/get_bits.h:273:5: 
      271. static inline unsigned int get_bits1(GetBitContext *s)
      272. {
      273.     unsigned int index = s->index;
               ^
      274.     uint8_t result     = s->buffer[index >> 3];
      275. #ifdef BITSTREAM_READER_LE

libavcodec/get_bits.h:274:5: 
      272. {
      273.     unsigned int index = s->index;
      274.     uint8_t result     = s->buffer[index >> 3];
               ^
      275. #ifdef BITSTREAM_READER_LE
      276.     result >>= index & 7;

libavcodec/get_bits.h:276:5: 
      274.     uint8_t result     = s->buffer[index >> 3];
      275. #ifdef BITSTREAM_READER_LE
      276.     result >>= index & 7;
               ^
      277.     result  &= 1;
      278. #else

libavcodec/get_bits.h:277:5: 
      275. #ifdef BITSTREAM_READER_LE
      276.     result >>= index & 7;
      277.     result  &= 1;
               ^
      278. #else
      279.     result <<= index & 7;

libavcodec/get_bits.h:283:9: Taking false branch
      281. #endif
      282. #if !UNCHECKED_BITSTREAM_READER
      283.     if (s->index < s->size_in_bits_plus8)
                   ^
      284. #endif
      285.         index++;

libavcodec/get_bits.h:286:5: 
      284. #endif
      285.         index++;
      286.     s->index = index;
               ^
      287. 
      288.     return result;

libavcodec/get_bits.h:288:5: 
      286.     s->index = index;
      287. 
      288.     return result;
               ^
      289. }
      290. 

libavcodec/get_bits.h:289:1: return from a call to get_bits1
      287. 
      288.     return result;
      289. }
           ^
      290. 
      291. static inline unsigned int show_bits1(GetBitContext *s)

libavcodec/flac.c:65:5: Skipping get_bits(): empty list of specs
    63. 
    64.     /* block size and sample rate codes */
    65.     bs_code = get_bits(gb, 4);
            ^
    66.     sr_code = get_bits(gb, 4);
    67. 

libavcodec/flac.c:66:5: Skipping get_bits(): empty list of specs
    64.     /* block size and sample rate codes */
    65.     bs_code = get_bits(gb, 4);
    66.     sr_code = get_bits(gb, 4);
            ^
    67. 
    68.     /* channels and decorrelation */

libavcodec/flac.c:69:5: Skipping get_bits(): empty list of specs
    67. 
    68.     /* channels and decorrelation */
    69.     fi->ch_mode = get_bits(gb, 4);
            ^
    70.     if (fi->ch_mode < FLAC_MAX_CHANNELS) {
    71.         fi->channels = fi->ch_mode + 1;

libavcodec/flac.c:70:9: Taking true branch
    68.     /* channels and decorrelation */
    69.     fi->ch_mode = get_bits(gb, 4);
    70.     if (fi->ch_mode < FLAC_MAX_CHANNELS) {
                ^
    71.         fi->channels = fi->ch_mode + 1;
    72.         fi->ch_mode = FLAC_CHMODE_INDEPENDENT;

libavcodec/flac.c:71:9: 
    69.     fi->ch_mode = get_bits(gb, 4);
    70.     if (fi->ch_mode < FLAC_MAX_CHANNELS) {
    71.         fi->channels = fi->ch_mode + 1;
                ^
    72.         fi->ch_mode = FLAC_CHMODE_INDEPENDENT;
    73.     } else if (fi->ch_mode < FLAC_MAX_CHANNELS + FLAC_CHMODE_MID_SIDE) {

libavcodec/flac.c:72:9: 
    70.     if (fi->ch_mode < FLAC_MAX_CHANNELS) {
    71.         fi->channels = fi->ch_mode + 1;
    72.         fi->ch_mode = FLAC_CHMODE_INDEPENDENT;
                ^
    73.     } else if (fi->ch_mode < FLAC_MAX_CHANNELS + FLAC_CHMODE_MID_SIDE) {
    74.         fi->channels = 2;

libavcodec/flac.c:83:5: Skipping get_bits(): empty list of specs
    81. 
    82.     /* bits per sample */
    83.     bps_code = get_bits(gb, 3);
            ^
    84.     if (bps_code == 3 || bps_code == 7) {
    85.         av_log(avctx, AV_LOG_ERROR + log_level_offset,

libavcodec/flac.c:84:9: Taking false branch
    82.     /* bits per sample */
    83.     bps_code = get_bits(gb, 3);
    84.     if (bps_code == 3 || bps_code == 7) {
                ^
    85.         av_log(avctx, AV_LOG_ERROR + log_level_offset,
    86.                "invalid sample size code (%d)\n",

libavcodec/flac.c:84:26: Taking false branch
    82.     /* bits per sample */
    83.     bps_code = get_bits(gb, 3);
    84.     if (bps_code == 3 || bps_code == 7) {
                                 ^
    85.         av_log(avctx, AV_LOG_ERROR + log_level_offset,
    86.                "invalid sample size code (%d)\n",

libavcodec/flac.c:90:5: 
    88.         return -1;
    89.     }
    90.     fi->bps = sample_size_table[bps_code];
            ^
    91. 
    92.     /* reserved bit */

libavcodec/flac.c:93:9: 
    91. 
    92.     /* reserved bit */
    93.     if (get_bits1(gb)) {
                ^
    94.         av_log(avctx, AV_LOG_ERROR + log_level_offset,
    95.                "broken stream, invalid padding\n");

libavcodec/get_bits.h:271:1: start of procedure get_bits1()
      269. }
      270. 
      271. static inline unsigned int get_bits1(GetBitContext *s)
           ^
      272. {
      273.     unsigned int index = s->index;

libavcodec/get_bits.h:273:5: 
      271. static inline unsigned int get_bits1(GetBitContext *s)
      272. {
      273.     unsigned int index = s->index;
               ^
      274.     uint8_t result     = s->buffer[index >> 3];
      275. #ifdef BITSTREAM_READER_LE

libavcodec/get_bits.h:274:5: 
      272. {
      273.     unsigned int index = s->index;
      274.     uint8_t result     = s->buffer[index >> 3];
               ^
      275. #ifdef BITSTREAM_READER_LE
      276.     result >>= index & 7;

static int flac_decode_frame(AVCodecContext *avctx, void *data,
                             int *got_frame_ptr, AVPacket *avpkt)
{
    AVFrame *frame     = data;
    const uint8_t *buf = avpkt->data;
    int buf_size = avpkt->size;
    FLACContext *s = avctx->priv_data;
    int bytes_read = 0;
    int ret;
    *got_frame_ptr = 0;
    if (s->max_framesize == 0) {
        s->max_framesize =
            ff_flac_get_max_frame_size(s->max_blocksize ? s->max_blocksize : FLAC_MAX_BLOCKSIZE,
                                       FLAC_MAX_CHANNELS, 32);
    }
    if (buf_size < FLAC_MIN_FRAME_SIZE)
        return buf_size;
    if (AV_RB32(buf) == MKBETAG('f','L','a','C')) {
        if (!s->got_streaminfo && parse_streaminfo(s, buf, buf_size)) {
            av_log(s->avctx, AV_LOG_ERROR, "invalid header\n");
            return -1;
        }
        return get_metadata_size(buf, buf_size);
    }
    init_get_bits(&s->gb, buf, buf_size*8);
    if (decode_frame(s) < 0) {
        av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\n");
        return -1;
    }
    bytes_read = (get_bits_count(&s->gb)+7)/8;
    frame->nb_samples = s->blocksize;
    if ((ret = ff_get_buffer(avctx, frame)) < 0) {
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
        return ret;
    }
    s->dsp.decorrelate[s->ch_mode](frame->data, s->decoded, s->channels,
                                   s->blocksize, s->sample_shift);
    if (bytes_read > buf_size) {
        av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", bytes_read - buf_size);
        return -1;
    }
    if (bytes_read < buf_size) {
        av_log(s->avctx, AV_LOG_DEBUG, "underread: %d orig size: %d\n",
               buf_size - bytes_read, buf_size);
    }
    *got_frame_ptr = 1;
    return bytes_read;
}
['static int flac_decode_frame(AVCodecContext *avctx, void *data,\n                             int *got_frame_ptr, AVPacket *avpkt)\n{\n    AVFrame *frame     = data;\n    const uint8_t *buf = avpkt->data;\n    int buf_size = avpkt->size;\n    FLACContext *s = avctx->priv_data;\n    int bytes_read = 0;\n    int ret;\n    *got_frame_ptr = 0;\n    if (s->max_framesize == 0) {\n        s->max_framesize =\n            ff_flac_get_max_frame_size(s->max_blocksize ? s->max_blocksize : FLAC_MAX_BLOCKSIZE,\n                                       FLAC_MAX_CHANNELS, 32);\n    }\n    if (buf_size < FLAC_MIN_FRAME_SIZE)\n        return buf_size;\n    if (AV_RB32(buf) == MKBETAG(\'f\',\'L\',\'a\',\'C\')) {\n        if (!s->got_streaminfo && parse_streaminfo(s, buf, buf_size)) {\n            av_log(s->avctx, AV_LOG_ERROR, "invalid header\\n");\n            return -1;\n        }\n        return get_metadata_size(buf, buf_size);\n    }\n    init_get_bits(&s->gb, buf, buf_size*8);\n    if (decode_frame(s) < 0) {\n        av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\\n");\n        return -1;\n    }\n    bytes_read = (get_bits_count(&s->gb)+7)/8;\n    frame->nb_samples = s->blocksize;\n    if ((ret = ff_get_buffer(avctx, frame)) < 0) {\n        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n        return ret;\n    }\n    s->dsp.decorrelate[s->ch_mode](frame->data, s->decoded, s->channels,\n                                   s->blocksize, s->sample_shift);\n    if (bytes_read > buf_size) {\n        av_log(s->avctx, AV_LOG_ERROR, "overread: %d\\n", bytes_read - buf_size);\n        return -1;\n    }\n    if (bytes_read < buf_size) {\n        av_log(s->avctx, AV_LOG_DEBUG, "underread: %d orig size: %d\\n",\n               buf_size - bytes_read, buf_size);\n    }\n    *got_frame_ptr = 1;\n    return bytes_read;\n}', 'int ff_flac_get_max_frame_size(int blocksize, int ch, int bps)\n{\n    int count;\n    count = 16;\n    count += ch * ((7+bps+7)/8);\n    if (ch == 2) {\n        count += (( 2*bps+1) * blocksize + 7) / 8;\n    } else {\n        count += ( ch*bps    * blocksize + 7) / 8;\n    }\n    count += 2;\n    return count;\n}', 'static av_always_inline av_const uint32_t av_bswap32(uint32_t x)\n{\n    return AV_BSWAP32C(x);\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n                                int bit_size)\n{\n    int buffer_size;\n    int ret = 0;\n    if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {\n        buffer_size = bit_size = 0;\n        buffer      = NULL;\n        ret         = AVERROR_INVALIDDATA;\n    }\n    buffer_size = (bit_size + 7) >> 3;\n    s->buffer             = buffer;\n    s->size_in_bits       = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n    s->size_in_bits_plus8 = bit_size + 8;\n#endif\n    s->buffer_end         = buffer + buffer_size;\n    s->index              = 0;\n    return ret;\n}', 'static int decode_frame(FLACContext *s)\n{\n    int i, ret;\n    GetBitContext *gb = &s->gb;\n    FLACFrameInfo fi;\n    if (ff_flac_decode_frame_header(s->avctx, gb, &fi, 0)) {\n        av_log(s->avctx, AV_LOG_ERROR, "invalid frame header\\n");\n        return -1;\n    }\n    if (s->channels && fi.channels != s->channels && s->got_streaminfo) {\n        s->channels = s->avctx->channels = fi.channels;\n        ff_flac_set_channel_layout(s->avctx);\n        ret = allocate_buffers(s);\n        if (ret < 0)\n            return ret;\n    }\n    s->channels = s->avctx->channels = fi.channels;\n    if (!s->avctx->channel_layout)\n        ff_flac_set_channel_layout(s->avctx);\n    s->ch_mode = fi.ch_mode;\n    if (!s->bps && !fi.bps) {\n        av_log(s->avctx, AV_LOG_ERROR, "bps not found in STREAMINFO or frame header\\n");\n        return -1;\n    }\n    if (!fi.bps) {\n        fi.bps = s->bps;\n    } else if (s->bps && fi.bps != s->bps) {\n        av_log(s->avctx, AV_LOG_ERROR, "switching bps mid-stream is not "\n                                       "supported\\n");\n        return -1;\n    }\n    if (!s->bps) {\n        s->bps = s->avctx->bits_per_raw_sample = fi.bps;\n        flac_set_bps(s);\n    }\n    if (!s->max_blocksize)\n        s->max_blocksize = FLAC_MAX_BLOCKSIZE;\n    if (fi.blocksize > s->max_blocksize) {\n        av_log(s->avctx, AV_LOG_ERROR, "blocksize %d > %d\\n", fi.blocksize,\n               s->max_blocksize);\n        return -1;\n    }\n    s->blocksize = fi.blocksize;\n    if (!s->samplerate && !fi.samplerate) {\n        av_log(s->avctx, AV_LOG_ERROR, "sample rate not found in STREAMINFO"\n                                        " or frame header\\n");\n        return -1;\n    }\n    if (fi.samplerate == 0)\n        fi.samplerate = s->samplerate;\n    s->samplerate = s->avctx->sample_rate = fi.samplerate;\n    if (!s->got_streaminfo) {\n        ret = allocate_buffers(s);\n        if (ret < 0)\n            return ret;\n        ff_flacdsp_init(&s->dsp, s->avctx->sample_fmt, s->bps);\n        s->got_streaminfo = 1;\n        dump_headers(s->avctx, (FLACStreaminfo *)s);\n    }\n    for (i = 0; i < s->channels; i++) {\n        if (decode_subframe(s, i) < 0)\n            return -1;\n    }\n    align_get_bits(gb);\n    skip_bits(gb, 16);\n    return 0;\n}', 'int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,\n                                FLACFrameInfo *fi, int log_level_offset)\n{\n    int bs_code, sr_code, bps_code;\n    if ((get_bits(gb, 15) & 0x7FFF) != 0x7FFC) {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset, "invalid sync code\\n");\n        return -1;\n    }\n    fi->is_var_size = get_bits1(gb);\n    bs_code = get_bits(gb, 4);\n    sr_code = get_bits(gb, 4);\n    fi->ch_mode = get_bits(gb, 4);\n    if (fi->ch_mode < FLAC_MAX_CHANNELS) {\n        fi->channels = fi->ch_mode + 1;\n        fi->ch_mode = FLAC_CHMODE_INDEPENDENT;\n    } else if (fi->ch_mode < FLAC_MAX_CHANNELS + FLAC_CHMODE_MID_SIDE) {\n        fi->channels = 2;\n        fi->ch_mode -= FLAC_MAX_CHANNELS - 1;\n    } else {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "invalid channel mode: %d\\n", fi->ch_mode);\n        return -1;\n    }\n    bps_code = get_bits(gb, 3);\n    if (bps_code == 3 || bps_code == 7) {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "invalid sample size code (%d)\\n",\n               bps_code);\n        return -1;\n    }\n    fi->bps = sample_size_table[bps_code];\n    if (get_bits1(gb)) {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "broken stream, invalid padding\\n");\n        return -1;\n    }\n    fi->frame_or_sample_num = get_utf8(gb);\n    if (fi->frame_or_sample_num < 0) {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "sample/frame number invalid; utf8 fscked\\n");\n        return -1;\n    }\n    if (bs_code == 0) {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "reserved blocksize code: 0\\n");\n        return -1;\n    } else if (bs_code == 6) {\n        fi->blocksize = get_bits(gb, 8) + 1;\n    } else if (bs_code == 7) {\n        fi->blocksize = get_bits(gb, 16) + 1;\n    } else {\n        fi->blocksize = ff_flac_blocksize_table[bs_code];\n    }\n    if (sr_code < 12) {\n        fi->samplerate = ff_flac_sample_rate_table[sr_code];\n    } else if (sr_code == 12) {\n        fi->samplerate = get_bits(gb, 8) * 1000;\n    } else if (sr_code == 13) {\n        fi->samplerate = get_bits(gb, 16);\n    } else if (sr_code == 14) {\n        fi->samplerate = get_bits(gb, 16) * 10;\n    } else {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "illegal sample rate code %d\\n",\n               sr_code);\n        return -1;\n    }\n    skip_bits(gb, 8);\n    if (av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, gb->buffer,\n               get_bits_count(gb)/8)) {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "header crc mismatch\\n");\n        return -1;\n    }\n    return 0;\n}', 'static inline unsigned int get_bits1(GetBitContext *s)\n{\n    unsigned int index = s->index;\n    uint8_t result     = s->buffer[index >> 3];\n#ifdef BITSTREAM_READER_LE\n    result >>= index & 7;\n    result  &= 1;\n#else\n    result <<= index & 7;\n    result >>= 8 - 1;\n#endif\n#if !UNCHECKED_BITSTREAM_READER\n    if (s->index < s->size_in_bits_plus8)\n#endif\n        index++;\n    s->index = index;\n    return result;\n}']