libavcodec/flashsvenc.c:139: error: Null Dereference
  pointer `&pb->buf_ptr` last assigned on line 134 could be null and is dereferenced by call to `put_bits()` at line 139, column 5.

libavcodec/flashsvenc.c:124:1: start of procedure encode_bitstream()
122. 
123. 
124. static int encode_bitstream(FlashSVContext *s, AVFrame *p, uint8_t *buf,
     ^
125.                             int buf_size, int block_width, int block_height,
126.                             uint8_t *previous_frame, int *I_frame)

libavcodec/flashsvenc.c:132:5: 
130.     int h_blocks, v_blocks, h_part, v_part, i, j;
131.     int buf_pos, res;
132.     int pred_blocks = 0;
         ^
133. 
134.     init_put_bits(&pb, buf, buf_size * 8);

libavcodec/flashsvenc.c:134:5: 
132.     int pred_blocks = 0;
133. 
134.     init_put_bits(&pb, buf, buf_size * 8);
         ^
135. 
136.     put_bits(&pb,  4, block_width / 16 - 1);

libavcodec/put_bits.h:52:1: start of procedure init_put_bits()
  50.  * @param buffer_size the size in bytes of buffer
  51.  */
  52. static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
      ^
  53. {
  54.     if(buffer_size < 0) {

libavcodec/put_bits.h:54:8: Taking true branch
  52. static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
  53. {
  54.     if(buffer_size < 0) {
             ^
  55.         buffer_size = 0;
  56.         buffer = NULL;

libavcodec/put_bits.h:55:9: 
  53. {
  54.     if(buffer_size < 0) {
  55.         buffer_size = 0;
              ^
  56.         buffer = NULL;
  57.     }

libavcodec/put_bits.h:56:9: 
  54.     if(buffer_size < 0) {
  55.         buffer_size = 0;
  56.         buffer = NULL;
              ^
  57.     }
  58. 

libavcodec/put_bits.h:59:5: 
  57.     }
  58. 
  59.     s->size_in_bits= 8*buffer_size;
          ^
  60.     s->buf = buffer;
  61.     s->buf_end = s->buf + buffer_size;

libavcodec/put_bits.h:60:5: 
  58. 
  59.     s->size_in_bits= 8*buffer_size;
  60.     s->buf = buffer;
          ^
  61.     s->buf_end = s->buf + buffer_size;
  62.     s->buf_ptr = s->buf;

libavcodec/put_bits.h:61:5: 
  59.     s->size_in_bits= 8*buffer_size;
  60.     s->buf = buffer;
  61.     s->buf_end = s->buf + buffer_size;
          ^
  62.     s->buf_ptr = s->buf;
  63.     s->bit_left=32;

libavcodec/put_bits.h:62:5: 
  60.     s->buf = buffer;
  61.     s->buf_end = s->buf + buffer_size;
  62.     s->buf_ptr = s->buf;
          ^
  63.     s->bit_left=32;
  64.     s->bit_buf=0;

libavcodec/put_bits.h:63:5: 
  61.     s->buf_end = s->buf + buffer_size;
  62.     s->buf_ptr = s->buf;
  63.     s->bit_left=32;
          ^
  64.     s->bit_buf=0;
  65. }

libavcodec/put_bits.h:64:5: 
  62.     s->buf_ptr = s->buf;
  63.     s->bit_left=32;
  64.     s->bit_buf=0;
          ^
  65. }
  66. 

libavcodec/put_bits.h:65:1: return from a call to init_put_bits
  63.     s->bit_left=32;
  64.     s->bit_buf=0;
  65. }
      ^
  66. 
  67. /**

libavcodec/flashsvenc.c:136:5: 
134.     init_put_bits(&pb, buf, buf_size * 8);
135. 
136.     put_bits(&pb,  4, block_width / 16 - 1);
         ^
137.     put_bits(&pb, 12, s->image_width);
138.     put_bits(&pb,  4, block_height / 16 - 1);

libavcodec/put_bits.h:128:1: start of procedure put_bits()
  126.  * Use put_bits32 to write 32 bits.
  127.  */
  128. static inline void put_bits(PutBitContext *s, int n, unsigned int value)
       ^
  129. {
  130.     unsigned int bit_buf;

libavcodec/put_bits.h:134:5: 
  132. 
  133.     //    printf("put_bits=%d %x\n", n, value);
  134.     assert(n <= 31 && value < (1U << n));
           ^
  135. 
  136.     bit_buf = s->bit_buf;

libavcodec/put_bits.h:136:5: 
  134.     assert(n <= 31 && value < (1U << n));
  135. 
  136.     bit_buf = s->bit_buf;
           ^
  137.     bit_left = s->bit_left;
  138. 

libavcodec/put_bits.h:137:5: 
  135. 
  136.     bit_buf = s->bit_buf;
  137.     bit_left = s->bit_left;
           ^
  138. 
  139.     //    printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);

libavcodec/put_bits.h:151:9: Taking true branch
  149.     bit_left-=n;
  150. #else
  151.     if (n < bit_left) {
               ^
  152.         bit_buf = (bit_buf<<n) | value;
  153.         bit_left-=n;

libavcodec/put_bits.h:152:9: 
  150. #else
  151.     if (n < bit_left) {
  152.         bit_buf = (bit_buf<<n) | value;
               ^
  153.         bit_left-=n;
  154.     } else {

libavcodec/put_bits.h:153:9: 
  151.     if (n < bit_left) {
  152.         bit_buf = (bit_buf<<n) | value;
  153.         bit_left-=n;
               ^
  154.     } else {
  155.         bit_buf<<=bit_left;

libavcodec/put_bits.h:165:5: 
  163. #endif
  164. 
  165.     s->bit_buf = bit_buf;
           ^
  166.     s->bit_left = bit_left;
  167. }

libavcodec/put_bits.h:166:5: 
  164. 
  165.     s->bit_buf = bit_buf;
  166.     s->bit_left = bit_left;
           ^
  167. }
  168. 

libavcodec/put_bits.h:167:1: return from a call to put_bits
  165.     s->bit_buf = bit_buf;
  166.     s->bit_left = bit_left;
  167. }
       ^
  168. 
  169. static inline void put_sbits(PutBitContext *pb, int n, int32_t value)

libavcodec/flashsvenc.c:137:5: 
135. 
136.     put_bits(&pb,  4, block_width / 16 - 1);
137.     put_bits(&pb, 12, s->image_width);
         ^
138.     put_bits(&pb,  4, block_height / 16 - 1);
139.     put_bits(&pb, 12, s->image_height);

libavcodec/put_bits.h:128:1: start of procedure put_bits()
  126.  * Use put_bits32 to write 32 bits.
  127.  */
  128. static inline void put_bits(PutBitContext *s, int n, unsigned int value)
       ^
  129. {
  130.     unsigned int bit_buf;

libavcodec/put_bits.h:134:5: 
  132. 
  133.     //    printf("put_bits=%d %x\n", n, value);
  134.     assert(n <= 31 && value < (1U << n));
           ^
  135. 
  136.     bit_buf = s->bit_buf;

libavcodec/put_bits.h:136:5: 
  134.     assert(n <= 31 && value < (1U << n));
  135. 
  136.     bit_buf = s->bit_buf;
           ^
  137.     bit_left = s->bit_left;
  138. 

libavcodec/put_bits.h:137:5: 
  135. 
  136.     bit_buf = s->bit_buf;
  137.     bit_left = s->bit_left;
           ^
  138. 
  139.     //    printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);

libavcodec/put_bits.h:151:9: Taking true branch
  149.     bit_left-=n;
  150. #else
  151.     if (n < bit_left) {
               ^
  152.         bit_buf = (bit_buf<<n) | value;
  153.         bit_left-=n;

libavcodec/put_bits.h:152:9: 
  150. #else
  151.     if (n < bit_left) {
  152.         bit_buf = (bit_buf<<n) | value;
               ^
  153.         bit_left-=n;
  154.     } else {

libavcodec/put_bits.h:153:9: 
  151.     if (n < bit_left) {
  152.         bit_buf = (bit_buf<<n) | value;
  153.         bit_left-=n;
               ^
  154.     } else {
  155.         bit_buf<<=bit_left;

libavcodec/put_bits.h:165:5: 
  163. #endif
  164. 
  165.     s->bit_buf = bit_buf;
           ^
  166.     s->bit_left = bit_left;
  167. }

libavcodec/put_bits.h:166:5: 
  164. 
  165.     s->bit_buf = bit_buf;
  166.     s->bit_left = bit_left;
           ^
  167. }
  168. 

libavcodec/put_bits.h:167:1: return from a call to put_bits
  165.     s->bit_buf = bit_buf;
  166.     s->bit_left = bit_left;
  167. }
       ^
  168. 
  169. static inline void put_sbits(PutBitContext *pb, int n, int32_t value)

libavcodec/flashsvenc.c:138:5: 
136.     put_bits(&pb,  4, block_width / 16 - 1);
137.     put_bits(&pb, 12, s->image_width);
138.     put_bits(&pb,  4, block_height / 16 - 1);
         ^
139.     put_bits(&pb, 12, s->image_height);
140.     flush_put_bits(&pb);

libavcodec/put_bits.h:128:1: start of procedure put_bits()
  126.  * Use put_bits32 to write 32 bits.
  127.  */
  128. static inline void put_bits(PutBitContext *s, int n, unsigned int value)
       ^
  129. {
  130.     unsigned int bit_buf;

libavcodec/put_bits.h:134:5: 
  132. 
  133.     //    printf("put_bits=%d %x\n", n, value);
  134.     assert(n <= 31 && value < (1U << n));
           ^
  135. 
  136.     bit_buf = s->bit_buf;

libavcodec/put_bits.h:136:5: 
  134.     assert(n <= 31 && value < (1U << n));
  135. 
  136.     bit_buf = s->bit_buf;
           ^
  137.     bit_left = s->bit_left;
  138. 

libavcodec/put_bits.h:137:5: 
  135. 
  136.     bit_buf = s->bit_buf;
  137.     bit_left = s->bit_left;
           ^
  138. 
  139.     //    printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);

libavcodec/put_bits.h:151:9: Taking true branch
  149.     bit_left-=n;
  150. #else
  151.     if (n < bit_left) {
               ^
  152.         bit_buf = (bit_buf<<n) | value;
  153.         bit_left-=n;

libavcodec/put_bits.h:152:9: 
  150. #else
  151.     if (n < bit_left) {
  152.         bit_buf = (bit_buf<<n) | value;
               ^
  153.         bit_left-=n;
  154.     } else {

libavcodec/put_bits.h:153:9: 
  151.     if (n < bit_left) {
  152.         bit_buf = (bit_buf<<n) | value;
  153.         bit_left-=n;
               ^
  154.     } else {
  155.         bit_buf<<=bit_left;

libavcodec/put_bits.h:165:5: 
  163. #endif
  164. 
  165.     s->bit_buf = bit_buf;
           ^
  166.     s->bit_left = bit_left;
  167. }

libavcodec/put_bits.h:166:5: 
  164. 
  165.     s->bit_buf = bit_buf;
  166.     s->bit_left = bit_left;
           ^
  167. }
  168. 

libavcodec/put_bits.h:167:1: return from a call to put_bits
  165.     s->bit_buf = bit_buf;
  166.     s->bit_left = bit_left;
  167. }
       ^
  168. 
  169. static inline void put_sbits(PutBitContext *pb, int n, int32_t value)

libavcodec/flashsvenc.c:139:5: 
137.     put_bits(&pb, 12, s->image_width);
138.     put_bits(&pb,  4, block_height / 16 - 1);
139.     put_bits(&pb, 12, s->image_height);
         ^
140.     flush_put_bits(&pb);
141.     buf_pos = 4;

libavcodec/put_bits.h:128:1: start of procedure put_bits()
  126.  * Use put_bits32 to write 32 bits.
  127.  */
  128. static inline void put_bits(PutBitContext *s, int n, unsigned int value)
       ^
  129. {
  130.     unsigned int bit_buf;

libavcodec/put_bits.h:134:5: 
  132. 
  133.     //    printf("put_bits=%d %x\n", n, value);
  134.     assert(n <= 31 && value < (1U << n));
           ^
  135. 
  136.     bit_buf = s->bit_buf;

libavcodec/put_bits.h:136:5: 
  134.     assert(n <= 31 && value < (1U << n));
  135. 
  136.     bit_buf = s->bit_buf;
           ^
  137.     bit_left = s->bit_left;
  138. 

libavcodec/put_bits.h:137:5: 
  135. 
  136.     bit_buf = s->bit_buf;
  137.     bit_left = s->bit_left;
           ^
  138. 
  139.     //    printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);

libavcodec/put_bits.h:151:9: Taking false branch
  149.     bit_left-=n;
  150. #else
  151.     if (n < bit_left) {
               ^
  152.         bit_buf = (bit_buf<<n) | value;
  153.         bit_left-=n;

libavcodec/put_bits.h:155:9: 
  153.         bit_left-=n;
  154.     } else {
  155.         bit_buf<<=bit_left;
               ^
  156.         bit_buf |= value >> (n - bit_left);
  157.         AV_WB32(s->buf_ptr, bit_buf);

libavcodec/put_bits.h:156:9: 
  154.     } else {
  155.         bit_buf<<=bit_left;
  156.         bit_buf |= value >> (n - bit_left);
               ^
  157.         AV_WB32(s->buf_ptr, bit_buf);
  158.         //printf("bitbuf = %08x\n", bit_buf);

libavcodec/put_bits.h:157:9: 
  155.         bit_buf<<=bit_left;
  156.         bit_buf |= value >> (n - bit_left);
  157.         AV_WB32(s->buf_ptr, bit_buf);
               ^
  158.         //printf("bitbuf = %08x\n", bit_buf);
  159.         s->buf_ptr+=4;

static int encode_bitstream(FlashSVContext *s, AVFrame *p, uint8_t *buf,
                            int buf_size, int block_width, int block_height,
                            uint8_t *previous_frame, int *I_frame)
{
    PutBitContext pb;
    int h_blocks, v_blocks, h_part, v_part, i, j;
    int buf_pos, res;
    int pred_blocks = 0;
    init_put_bits(&pb, buf, buf_size * 8);
    put_bits(&pb,  4, block_width / 16 - 1);
    put_bits(&pb, 12, s->image_width);
    put_bits(&pb,  4, block_height / 16 - 1);
    put_bits(&pb, 12, s->image_height);
    flush_put_bits(&pb);
    buf_pos = 4;
    h_blocks = s->image_width  / block_width;
    h_part   = s->image_width  % block_width;
    v_blocks = s->image_height / block_height;
    v_part   = s->image_height % block_height;
    for (j = 0; j < v_blocks + (v_part ? 1 : 0); j++) {
        int y_pos = j * block_height;
        int cur_blk_height = (j < v_blocks) ? block_height : v_part;
        for (i = 0; i < h_blocks + (h_part ? 1 : 0); i++) {
            int x_pos = i * block_width;
            int cur_blk_width = (i < h_blocks) ? block_width : h_part;
            int ret = Z_OK;
            uint8_t *ptr = buf + buf_pos;
            res = copy_region_enc(p->data[0], s->tmpblock,
                                  s->image_height - (y_pos + cur_blk_height + 1),
                                  x_pos, cur_blk_height, cur_blk_width,
                                  p->linesize[0], previous_frame);
            if (res || *I_frame) {
                unsigned long zsize = 3 * block_width * block_height;
                ret = compress2(ptr + 2, &zsize, s->tmpblock,
                                3 * cur_blk_width * cur_blk_height, 9);
                if (ret != Z_OK)
                    av_log(s->avctx, AV_LOG_ERROR,
                           "error while compressing block %dx%d\n", i, j);
                bytestream_put_be16(&ptr, zsize);
                buf_pos += zsize + 2;
                av_dlog(s->avctx, "buf_pos = %d\n", buf_pos);
            } else {
                pred_blocks++;
                bytestream_put_be16(&ptr, 0);
                buf_pos += 2;
            }
        }
    }
    if (pred_blocks)
        *I_frame = 0;
    else
        *I_frame = 1;
    return buf_pos;
}
['static int encode_bitstream(FlashSVContext *s, AVFrame *p, uint8_t *buf,\n                            int buf_size, int block_width, int block_height,\n                            uint8_t *previous_frame, int *I_frame)\n{\n    PutBitContext pb;\n    int h_blocks, v_blocks, h_part, v_part, i, j;\n    int buf_pos, res;\n    int pred_blocks = 0;\n    init_put_bits(&pb, buf, buf_size * 8);\n    put_bits(&pb,  4, block_width / 16 - 1);\n    put_bits(&pb, 12, s->image_width);\n    put_bits(&pb,  4, block_height / 16 - 1);\n    put_bits(&pb, 12, s->image_height);\n    flush_put_bits(&pb);\n    buf_pos = 4;\n    h_blocks = s->image_width  / block_width;\n    h_part   = s->image_width  % block_width;\n    v_blocks = s->image_height / block_height;\n    v_part   = s->image_height % block_height;\n    for (j = 0; j < v_blocks + (v_part ? 1 : 0); j++) {\n        int y_pos = j * block_height;\n        int cur_blk_height = (j < v_blocks) ? block_height : v_part;\n        for (i = 0; i < h_blocks + (h_part ? 1 : 0); i++) {\n            int x_pos = i * block_width;\n            int cur_blk_width = (i < h_blocks) ? block_width : h_part;\n            int ret = Z_OK;\n            uint8_t *ptr = buf + buf_pos;\n            res = copy_region_enc(p->data[0], s->tmpblock,\n                                  s->image_height - (y_pos + cur_blk_height + 1),\n                                  x_pos, cur_blk_height, cur_blk_width,\n                                  p->linesize[0], previous_frame);\n            if (res || *I_frame) {\n                unsigned long zsize = 3 * block_width * block_height;\n                ret = compress2(ptr + 2, &zsize, s->tmpblock,\n                                3 * cur_blk_width * cur_blk_height, 9);\n                if (ret != Z_OK)\n                    av_log(s->avctx, AV_LOG_ERROR,\n                           "error while compressing block %dx%d\\n", i, j);\n                bytestream_put_be16(&ptr, zsize);\n                buf_pos += zsize + 2;\n                av_dlog(s->avctx, "buf_pos = %d\\n", buf_pos);\n            } else {\n                pred_blocks++;\n                bytestream_put_be16(&ptr, 0);\n                buf_pos += 2;\n            }\n        }\n    }\n    if (pred_blocks)\n        *I_frame = 0;\n    else\n        *I_frame = 1;\n    return buf_pos;\n}', 'static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)\n{\n    if(buffer_size < 0) {\n        buffer_size = 0;\n        buffer = NULL;\n    }\n    s->size_in_bits= 8*buffer_size;\n    s->buf = buffer;\n    s->buf_end = s->buf + buffer_size;\n    s->buf_ptr = s->buf;\n    s->bit_left=32;\n    s->bit_buf=0;\n}', 'static inline void put_bits(PutBitContext *s, int n, unsigned int value)\n{\n    unsigned int bit_buf;\n    int bit_left;\n    assert(n <= 31 && value < (1U << n));\n    bit_buf = s->bit_buf;\n    bit_left = s->bit_left;\n#ifdef BITSTREAM_WRITER_LE\n    bit_buf |= value << (32 - bit_left);\n    if (n >= bit_left) {\n        AV_WL32(s->buf_ptr, bit_buf);\n        s->buf_ptr+=4;\n        bit_buf = (bit_left==32)?0:value >> bit_left;\n        bit_left+=32;\n    }\n    bit_left-=n;\n#else\n    if (n < bit_left) {\n        bit_buf = (bit_buf<<n) | value;\n        bit_left-=n;\n    } else {\n        bit_buf<<=bit_left;\n        bit_buf |= value >> (n - bit_left);\n        AV_WB32(s->buf_ptr, bit_buf);\n        s->buf_ptr+=4;\n        bit_left+=32 - n;\n        bit_buf = value;\n    }\n#endif\n    s->bit_buf = bit_buf;\n    s->bit_left = bit_left;\n}']