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

libavcodec/flashsvenc.c:135:1: start of procedure encode_bitstream()
133. 
134. 
135. static int encode_bitstream(FlashSVContext *s, AVFrame *p, uint8_t *buf, int buf_size,
     ^
136.      int block_width, int block_height, uint8_t *previous_frame, int* I_frame) {
137. 

libavcodec/flashsvenc.c:141:5: 
139.     int h_blocks, v_blocks, h_part, v_part, i, j;
140.     int buf_pos, res;
141.     int pred_blocks = 0;
         ^
142. 
143.     init_put_bits(&pb, buf, buf_size*8);

libavcodec/flashsvenc.c:143:5: 
141.     int pred_blocks = 0;
142. 
143.     init_put_bits(&pb, buf, buf_size*8);
         ^
144. 
145.     put_bits(&pb, 4, (block_width/16)-1);

libavcodec/bitstream.h:91:1: start of procedure init_put_bits()
  89. } PutBitContext;
  90. 
  91. static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
      ^
  92. {
  93.     if(buffer_size < 0) {

libavcodec/bitstream.h:93:8: Taking true branch
  91. static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
  92. {
  93.     if(buffer_size < 0) {
             ^
  94.         buffer_size = 0;
  95.         buffer = NULL;

libavcodec/bitstream.h:94:9: 
  92. {
  93.     if(buffer_size < 0) {
  94.         buffer_size = 0;
              ^
  95.         buffer = NULL;
  96.     }

libavcodec/bitstream.h:95:9: 
  93.     if(buffer_size < 0) {
  94.         buffer_size = 0;
  95.         buffer = NULL;
              ^
  96.     }
  97. 

libavcodec/bitstream.h:98:5: 
   96.     }
   97. 
   98.     s->size_in_bits= 8*buffer_size;
           ^
   99.     s->buf = buffer;
  100.     s->buf_end = s->buf + buffer_size;

libavcodec/bitstream.h:99:5: 
   97. 
   98.     s->size_in_bits= 8*buffer_size;
   99.     s->buf = buffer;
           ^
  100.     s->buf_end = s->buf + buffer_size;
  101. #ifdef ALT_BITSTREAM_WRITER

libavcodec/bitstream.h:100:5: 
   98.     s->size_in_bits= 8*buffer_size;
   99.     s->buf = buffer;
  100.     s->buf_end = s->buf + buffer_size;
           ^
  101. #ifdef ALT_BITSTREAM_WRITER
  102.     s->index=0;

libavcodec/bitstream.h:106:5: 
  104. //    memset(buffer, 0, buffer_size);
  105. #else
  106.     s->buf_ptr = s->buf;
           ^
  107.     s->bit_left=32;
  108.     s->bit_buf=0;

libavcodec/bitstream.h:107:5: 
  105. #else
  106.     s->buf_ptr = s->buf;
  107.     s->bit_left=32;
           ^
  108.     s->bit_buf=0;
  109. #endif

libavcodec/bitstream.h:108:5: 
  106.     s->buf_ptr = s->buf;
  107.     s->bit_left=32;
  108.     s->bit_buf=0;
           ^
  109. #endif
  110. }

libavcodec/bitstream.h:110:1: return from a call to init_put_bits
  108.     s->bit_buf=0;
  109. #endif
  110. }
       ^
  111. 
  112. /* return the number of bits output */

libavcodec/flashsvenc.c:145:5: 
143.     init_put_bits(&pb, buf, buf_size*8);
144. 
145.     put_bits(&pb, 4, (block_width/16)-1);
         ^
146.     put_bits(&pb, 12, s->image_width);
147.     put_bits(&pb, 4, (block_height/16)-1);

libavcodec/bitstream.h:185:1: start of procedure put_bits()
  183. 
  184. #ifndef ALT_BITSTREAM_WRITER
  185. static inline void put_bits(PutBitContext *s, int n, unsigned int value)
       ^
  186. {
  187.     unsigned int bit_buf;

libavcodec/bitstream.h:191:5: 
  189. 
  190.     //    printf("put_bits=%d %x\n", n, value);
  191.     assert(n == 32 || value < (1U << n));
           ^
  192. 
  193.     bit_buf = s->bit_buf;

libavcodec/bitstream.h:193:5: 
  191.     assert(n == 32 || value < (1U << n));
  192. 
  193.     bit_buf = s->bit_buf;
           ^
  194.     bit_left = s->bit_left;
  195. 

libavcodec/bitstream.h:194:5: 
  192. 
  193.     bit_buf = s->bit_buf;
  194.     bit_left = s->bit_left;
           ^
  195. 
  196.     //    printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);

libavcodec/bitstream.h:213:9: Taking true branch
  211.     bit_left-=n;
  212. #else
  213.     if (n < bit_left) {
               ^
  214.         bit_buf = (bit_buf<<n) | value;
  215.         bit_left-=n;

libavcodec/bitstream.h:214:9: 
  212. #else
  213.     if (n < bit_left) {
  214.         bit_buf = (bit_buf<<n) | value;
               ^
  215.         bit_left-=n;
  216.     } else {

libavcodec/bitstream.h:215:9: 
  213.     if (n < bit_left) {
  214.         bit_buf = (bit_buf<<n) | value;
  215.         bit_left-=n;
               ^
  216.     } else {
  217.         bit_buf<<=bit_left;

libavcodec/bitstream.h:232:5: 
  230. #endif
  231. 
  232.     s->bit_buf = bit_buf;
           ^
  233.     s->bit_left = bit_left;
  234. }

libavcodec/bitstream.h:233:5: 
  231. 
  232.     s->bit_buf = bit_buf;
  233.     s->bit_left = bit_left;
           ^
  234. }
  235. #endif

libavcodec/bitstream.h:234:1: return from a call to put_bits
  232.     s->bit_buf = bit_buf;
  233.     s->bit_left = bit_left;
  234. }
       ^
  235. #endif
  236. 

libavcodec/flashsvenc.c:146:5: 
144. 
145.     put_bits(&pb, 4, (block_width/16)-1);
146.     put_bits(&pb, 12, s->image_width);
         ^
147.     put_bits(&pb, 4, (block_height/16)-1);
148.     put_bits(&pb, 12, s->image_height);

libavcodec/bitstream.h:185:1: start of procedure put_bits()
  183. 
  184. #ifndef ALT_BITSTREAM_WRITER
  185. static inline void put_bits(PutBitContext *s, int n, unsigned int value)
       ^
  186. {
  187.     unsigned int bit_buf;

libavcodec/bitstream.h:191:5: 
  189. 
  190.     //    printf("put_bits=%d %x\n", n, value);
  191.     assert(n == 32 || value < (1U << n));
           ^
  192. 
  193.     bit_buf = s->bit_buf;

libavcodec/bitstream.h:193:5: 
  191.     assert(n == 32 || value < (1U << n));
  192. 
  193.     bit_buf = s->bit_buf;
           ^
  194.     bit_left = s->bit_left;
  195. 

libavcodec/bitstream.h:194:5: 
  192. 
  193.     bit_buf = s->bit_buf;
  194.     bit_left = s->bit_left;
           ^
  195. 
  196.     //    printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);

libavcodec/bitstream.h:213:9: Taking true branch
  211.     bit_left-=n;
  212. #else
  213.     if (n < bit_left) {
               ^
  214.         bit_buf = (bit_buf<<n) | value;
  215.         bit_left-=n;

libavcodec/bitstream.h:214:9: 
  212. #else
  213.     if (n < bit_left) {
  214.         bit_buf = (bit_buf<<n) | value;
               ^
  215.         bit_left-=n;
  216.     } else {

libavcodec/bitstream.h:215:9: 
  213.     if (n < bit_left) {
  214.         bit_buf = (bit_buf<<n) | value;
  215.         bit_left-=n;
               ^
  216.     } else {
  217.         bit_buf<<=bit_left;

libavcodec/bitstream.h:232:5: 
  230. #endif
  231. 
  232.     s->bit_buf = bit_buf;
           ^
  233.     s->bit_left = bit_left;
  234. }

libavcodec/bitstream.h:233:5: 
  231. 
  232.     s->bit_buf = bit_buf;
  233.     s->bit_left = bit_left;
           ^
  234. }
  235. #endif

libavcodec/bitstream.h:234:1: return from a call to put_bits
  232.     s->bit_buf = bit_buf;
  233.     s->bit_left = bit_left;
  234. }
       ^
  235. #endif
  236. 

libavcodec/flashsvenc.c:147:5: 
145.     put_bits(&pb, 4, (block_width/16)-1);
146.     put_bits(&pb, 12, s->image_width);
147.     put_bits(&pb, 4, (block_height/16)-1);
         ^
148.     put_bits(&pb, 12, s->image_height);
149.     flush_put_bits(&pb);

libavcodec/bitstream.h:185:1: start of procedure put_bits()
  183. 
  184. #ifndef ALT_BITSTREAM_WRITER
  185. static inline void put_bits(PutBitContext *s, int n, unsigned int value)
       ^
  186. {
  187.     unsigned int bit_buf;

libavcodec/bitstream.h:191:5: 
  189. 
  190.     //    printf("put_bits=%d %x\n", n, value);
  191.     assert(n == 32 || value < (1U << n));
           ^
  192. 
  193.     bit_buf = s->bit_buf;

libavcodec/bitstream.h:193:5: 
  191.     assert(n == 32 || value < (1U << n));
  192. 
  193.     bit_buf = s->bit_buf;
           ^
  194.     bit_left = s->bit_left;
  195. 

libavcodec/bitstream.h:194:5: 
  192. 
  193.     bit_buf = s->bit_buf;
  194.     bit_left = s->bit_left;
           ^
  195. 
  196.     //    printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);

libavcodec/bitstream.h:213:9: Taking true branch
  211.     bit_left-=n;
  212. #else
  213.     if (n < bit_left) {
               ^
  214.         bit_buf = (bit_buf<<n) | value;
  215.         bit_left-=n;

libavcodec/bitstream.h:214:9: 
  212. #else
  213.     if (n < bit_left) {
  214.         bit_buf = (bit_buf<<n) | value;
               ^
  215.         bit_left-=n;
  216.     } else {

libavcodec/bitstream.h:215:9: 
  213.     if (n < bit_left) {
  214.         bit_buf = (bit_buf<<n) | value;
  215.         bit_left-=n;
               ^
  216.     } else {
  217.         bit_buf<<=bit_left;

libavcodec/bitstream.h:232:5: 
  230. #endif
  231. 
  232.     s->bit_buf = bit_buf;
           ^
  233.     s->bit_left = bit_left;
  234. }

libavcodec/bitstream.h:233:5: 
  231. 
  232.     s->bit_buf = bit_buf;
  233.     s->bit_left = bit_left;
           ^
  234. }
  235. #endif

libavcodec/bitstream.h:234:1: return from a call to put_bits
  232.     s->bit_buf = bit_buf;
  233.     s->bit_left = bit_left;
  234. }
       ^
  235. #endif
  236. 

libavcodec/flashsvenc.c:148:5: 
146.     put_bits(&pb, 12, s->image_width);
147.     put_bits(&pb, 4, (block_height/16)-1);
148.     put_bits(&pb, 12, s->image_height);
         ^
149.     flush_put_bits(&pb);
150.     buf_pos=4;

libavcodec/bitstream.h:185:1: start of procedure put_bits()
  183. 
  184. #ifndef ALT_BITSTREAM_WRITER
  185. static inline void put_bits(PutBitContext *s, int n, unsigned int value)
       ^
  186. {
  187.     unsigned int bit_buf;

libavcodec/bitstream.h:191:5: 
  189. 
  190.     //    printf("put_bits=%d %x\n", n, value);
  191.     assert(n == 32 || value < (1U << n));
           ^
  192. 
  193.     bit_buf = s->bit_buf;

libavcodec/bitstream.h:193:5: 
  191.     assert(n == 32 || value < (1U << n));
  192. 
  193.     bit_buf = s->bit_buf;
           ^
  194.     bit_left = s->bit_left;
  195. 

libavcodec/bitstream.h:194:5: 
  192. 
  193.     bit_buf = s->bit_buf;
  194.     bit_left = s->bit_left;
           ^
  195. 
  196.     //    printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);

libavcodec/bitstream.h:213:9: Taking false branch
  211.     bit_left-=n;
  212. #else
  213.     if (n < bit_left) {
               ^
  214.         bit_buf = (bit_buf<<n) | value;
  215.         bit_left-=n;

libavcodec/bitstream.h:217:9: 
  215.         bit_left-=n;
  216.     } else {
  217.         bit_buf<<=bit_left;
               ^
  218.         bit_buf |= value >> (n - bit_left);
  219. #if !HAVE_FAST_UNALIGNED

libavcodec/bitstream.h:218:9: 
  216.     } else {
  217.         bit_buf<<=bit_left;
  218.         bit_buf |= value >> (n - bit_left);
               ^
  219. #if !HAVE_FAST_UNALIGNED
  220.         if (3 & (intptr_t) s->buf_ptr) {

libavcodec/bitstream.h:220:13: Taking false branch
  218.         bit_buf |= value >> (n - bit_left);
  219. #if !HAVE_FAST_UNALIGNED
  220.         if (3 & (intptr_t) s->buf_ptr) {
                   ^
  221.             AV_WB32(s->buf_ptr, bit_buf);
  222.         } else

libavcodec/bitstream.h:224:9: 
  222.         } else
  223. #endif
  224.         *(uint32_t *)s->buf_ptr = be2me_32(bit_buf);
               ^
  225.         //printf("bitbuf = %08x\n", bit_buf);
  226.         s->buf_ptr+=4;

libavutil/bswap.h:52:1: start of procedure bswap_32()
    50. 
    51. #ifndef bswap_32
    52. static av_always_inline av_const uint32_t bswap_32(uint32_t x)
        ^
    53. {
    54.     x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);

libavutil/bswap.h:54:5: 
    52. static av_always_inline av_const uint32_t bswap_32(uint32_t x)
    53. {
    54.     x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
            ^
    55.     x= (x>>16) | (x<<16);
    56.     return x;

libavutil/bswap.h:55:5: 
    53. {
    54.     x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
    55.     x= (x>>16) | (x<<16);
            ^
    56.     return x;
    57. }

libavutil/bswap.h:56:5: 
    54.     x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
    55.     x= (x>>16) | (x<<16);
    56.     return x;
            ^
    57. }
    58. #endif

libavutil/bswap.h:57:1: return from a call to bswap_32
    55.     x= (x>>16) | (x<<16);
    56.     return x;
    57. }
        ^
    58. #endif
    59. 

libavcodec/bitstream.h:226:9: 
  224.         *(uint32_t *)s->buf_ptr = be2me_32(bit_buf);
  225.         //printf("bitbuf = %08x\n", bit_buf);
  226.         s->buf_ptr+=4;
               ^
  227.         bit_left+=32 - n;
  228.         bit_buf = value;

libavcodec/bitstream.h:227:9: 
  225.         //printf("bitbuf = %08x\n", bit_buf);
  226.         s->buf_ptr+=4;
  227.         bit_left+=32 - n;
               ^
  228.         bit_buf = value;
  229.     }

libavcodec/bitstream.h:228:9: 
  226.         s->buf_ptr+=4;
  227.         bit_left+=32 - n;
  228.         bit_buf = value;
               ^
  229.     }
  230. #endif

libavcodec/bitstream.h:232:5: 
  230. #endif
  231. 
  232.     s->bit_buf = bit_buf;
           ^
  233.     s->bit_left = bit_left;
  234. }

libavcodec/bitstream.h:233:5: 
  231. 
  232.     s->bit_buf = bit_buf;
  233.     s->bit_left = bit_left;
           ^
  234. }
  235. #endif

libavcodec/bitstream.h:234:1: return from a call to put_bits
  232.     s->bit_buf = bit_buf;
  233.     s->bit_left = bit_left;
  234. }
       ^
  235. #endif
  236. 

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 hp = j*block_height;
        int hs = (j<v_blocks)?block_height:v_part;
        for (i = 0; i < h_blocks + (h_part?1:0); i++)
        {
            int wp = i*block_width;
            int ws = (i<h_blocks)?block_width:h_part;
            int ret=Z_OK;
            uint8_t *ptr;
            ptr = buf+buf_pos;
            res = copy_region_enc(p->data[0], s->tmpblock, s->image_height-(hp+hs+1), wp, hs, ws, p->linesize[0], previous_frame);
            if (res || *I_frame) {
                unsigned long zsize;
                zsize = 3*block_width*block_height;
                ret = compress2(ptr+2, &zsize, s->tmpblock, 3*ws*hs, 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,(unsigned int)zsize);
                buf_pos += zsize+2;
            } 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, int buf_size,\n     int block_width, int block_height, uint8_t *previous_frame, int* I_frame) {\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    {\n        int hp = j*block_height;\n        int hs = (j<v_blocks)?block_height:v_part;\n        for (i = 0; i < h_blocks + (h_part?1:0); i++)\n        {\n            int wp = i*block_width;\n            int ws = (i<h_blocks)?block_width:h_part;\n            int ret=Z_OK;\n            uint8_t *ptr;\n            ptr = buf+buf_pos;\n            res = copy_region_enc(p->data[0], s->tmpblock, s->image_height-(hp+hs+1), wp, hs, ws, p->linesize[0], previous_frame);\n            if (res || *I_frame) {\n                unsigned long zsize;\n                zsize = 3*block_width*block_height;\n                ret = compress2(ptr+2, &zsize, s->tmpblock, 3*ws*hs, 9);\n                if (ret != Z_OK)\n                    av_log(s->avctx, AV_LOG_ERROR, "error while compressing block %dx%d\\n", i, j);\n                bytestream_put_be16(&ptr,(unsigned int)zsize);\n                buf_pos += zsize+2;\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#ifdef ALT_BITSTREAM_WRITER\n    s->index=0;\n    ((uint32_t*)(s->buf))[0]=0;\n#else\n    s->buf_ptr = s->buf;\n    s->bit_left=32;\n    s->bit_buf=0;\n#endif\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 == 32 || 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#if !HAVE_FAST_UNALIGNED\n        if (3 & (intptr_t) s->buf_ptr) {\n            AV_WL32(s->buf_ptr, bit_buf);\n        } else\n#endif\n        *(uint32_t *)s->buf_ptr = le2me_32(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#if !HAVE_FAST_UNALIGNED\n        if (3 & (intptr_t) s->buf_ptr) {\n            AV_WB32(s->buf_ptr, bit_buf);\n        } else\n#endif\n        *(uint32_t *)s->buf_ptr = be2me_32(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}', 'static av_always_inline av_const uint32_t bswap_32(uint32_t x)\n{\n    x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);\n    x= (x>>16) | (x<<16);\n    return x;\n}']