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

libavcodec/flacdec.c:493:1: start of procedure flac_decode_frame()
491. }
492. 
493. static int flac_decode_frame(AVCodecContext *avctx, void *data,
     ^
494.                              int *got_frame_ptr, AVPacket *avpkt)
495. {

libavcodec/flacdec.c:496:5: 
494.                              int *got_frame_ptr, AVPacket *avpkt)
495. {
496.     const uint8_t *buf = avpkt->data;
         ^
497.     int buf_size = avpkt->size;
498.     FLACContext *s = avctx->priv_data;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

libavcodec/get_bits.h:376:5: 
  374. {
  375.     int buffer_size;
  376.     int ret = 0;
           ^
  377. 
  378.     if (bit_size > INT_MAX - 7 || bit_size <= 0) {

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

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

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

libavcodec/get_bits.h:381:9: 
  379.         buffer_size = bit_size = 0;
  380.         buffer = NULL;
  381.         ret = AVERROR_INVALIDDATA;
               ^
  382.     }
  383. 

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

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

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

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

libavcodec/get_bits.h:391:5: 
  389.     s->size_in_bits_plus8 = bit_size + 8;
  390. #endif
  391.     s->buffer_end   = buffer + buffer_size;
           ^
  392.     s->index        = 0;
  393.     return ret;

libavcodec/get_bits.h:392:5: 
  390. #endif
  391.     s->buffer_end   = buffer + buffer_size;
  392.     s->index        = 0;
           ^
  393.     return ret;
  394. }

libavcodec/get_bits.h:393:5: 
  391.     s->buffer_end   = buffer + buffer_size;
  392.     s->index        = 0;
  393.     return ret;
           ^
  394. }
  395. 

libavcodec/get_bits.h:394:1: return from a call to init_get_bits
  392.     s->index        = 0;
  393.     return ret;
  394. }
       ^
  395. 
  396. static inline void align_get_bits(GetBitContext *s)

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

libavcodec/flacdec.c:410:1: start of procedure decode_frame()
  408. }
  409. 
  410. static int decode_frame(FLACContext *s)
       ^
  411. {
  412.     int i, ret;

libavcodec/flacdec.c:413:5: 
  411. {
  412.     int i, ret;
  413.     GetBitContext *gb = &s->gb;
           ^
  414.     FLACFrameInfo fi;
  415. 

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

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

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

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

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

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

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

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

libavcodec/get_bits.h:274:5: 
      272. #ifdef BITSTREAM_READER_LE
      273.     result >>= index & 7;
      274.     result &= 1;
               ^
      275. #else
      276.     result <<= index & 7;

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

libavcodec/get_bits.h:283:5: 
      281. #endif
      282.         index++;
      283.     s->index = index;
               ^
      284. 
      285.     return result;

libavcodec/get_bits.h:285:5: 
      283.     s->index = index;
      284. 
      285.     return result;
               ^
      286. }
      287. 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

static int flac_decode_frame(AVCodecContext *avctx, void *data,
                             int *got_frame_ptr, AVPacket *avpkt)
{
    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;
    s->frame.nb_samples = s->blocksize;
    if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
        return ret;
    }
    s->dsp.decorrelate[s->ch_mode](s->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;
    *(AVFrame *)data = s->frame;
    return bytes_read;
}
['static int flac_decode_frame(AVCodecContext *avctx, void *data,\n                             int *got_frame_ptr, AVPacket *avpkt)\n{\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    s->frame.nb_samples = s->blocksize;\n    if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {\n        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n        return ret;\n    }\n    s->dsp.decorrelate[s->ch_mode](s->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    *(AVFrame *)data = s->frame;\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) {\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 && s->channels <= 6)\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}']