libavcodec/mp3_header_compress_bsf.c:66: error: Null Dereference
  pointer `*poutbuf` last assigned on line 65 could be null and is dereferenced by call to `memcpy()` at line 66, column 5.

libavcodec/mp3_header_compress_bsf.c:25:1: start of procedure mp3_header_compress()
23. 
24. 
25. static int mp3_header_compress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
    ^
26.                      uint8_t **poutbuf, int *poutbuf_size,
27.                      const uint8_t *buf, int buf_size, int keyframe){

libavcodec/mp3_header_compress_bsf.c:31:8: Taking false branch
29.     int mode_extension, header_size;
30. 
31.     if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){
           ^
32.         av_log(avctx, AV_LOG_ERROR, "not standards compliant\n");
33.         return -1;

libavcodec/mp3_header_compress_bsf.c:36:5: 
34.     }
35. 
36.     header = AV_RB32(buf);
        ^
37.     mode_extension= (header>>4)&3;
38. 

libavcodec/mp3_header_compress_bsf.c:37:5: 
35. 
36.     header = AV_RB32(buf);
37.     mode_extension= (header>>4)&3;
        ^
38. 
39.     if(ff_mpa_check_header(header) < 0 || (header&0x60000) != 0x20000){

libavcodec/mp3_header_compress_bsf.c:39:8: 
37.     mode_extension= (header>>4)&3;
38. 
39.     if(ff_mpa_check_header(header) < 0 || (header&0x60000) != 0x20000){
           ^
40. output_unchanged:
41.         *poutbuf= (uint8_t *) buf;

libavcodec/mpegaudio.h:139:1: start of procedure ff_mpa_check_header()
  137. 
  138. /* fast header check for resync */
  139. static inline int ff_mpa_check_header(uint32_t header){
       ^
  140.     /* header */
  141.     if ((header & 0xffe00000) != 0xffe00000)

libavcodec/mpegaudio.h:141:9: Taking false branch
  139. static inline int ff_mpa_check_header(uint32_t header){
  140.     /* header */
  141.     if ((header & 0xffe00000) != 0xffe00000)
               ^
  142.         return -1;
  143.     /* layer check */

libavcodec/mpegaudio.h:144:9: Taking false branch
  142.         return -1;
  143.     /* layer check */
  144.     if ((header & (3<<17)) == 0)
               ^
  145.         return -1;
  146.     /* bit rate */

libavcodec/mpegaudio.h:147:9: Taking false branch
  145.         return -1;
  146.     /* bit rate */
  147.     if ((header & (0xf<<12)) == 0xf<<12)
               ^
  148.         return -1;
  149.     /* frequency */

libavcodec/mpegaudio.h:150:9: Taking false branch
  148.         return -1;
  149.     /* frequency */
  150.     if ((header & (3<<10)) == 3<<10)
               ^
  151.         return -1;
  152.     return 0;

libavcodec/mpegaudio.h:152:5: 
  150.     if ((header & (3<<10)) == 3<<10)
  151.         return -1;
  152.     return 0;
           ^
  153. }
  154. 

libavcodec/mpegaudio.h:153:1: return from a call to ff_mpa_check_header
  151.         return -1;
  152.     return 0;
  153. }
       ^
  154. 
  155. #endif /* AVCODEC_MPEGAUDIO_H */

libavcodec/mp3_header_compress_bsf.c:39:8: Taking false branch
37.     mode_extension= (header>>4)&3;
38. 
39.     if(ff_mpa_check_header(header) < 0 || (header&0x60000) != 0x20000){
           ^
40. output_unchanged:
41.         *poutbuf= (uint8_t *) buf;

libavcodec/mp3_header_compress_bsf.c:39:43: Taking false branch
37.     mode_extension= (header>>4)&3;
38. 
39.     if(ff_mpa_check_header(header) < 0 || (header&0x60000) != 0x20000){
                                              ^
40. output_unchanged:
41.         *poutbuf= (uint8_t *) buf;

libavcodec/mp3_header_compress_bsf.c:48:8: Taking true branch
46.     }
47. 
48.     if(avctx->extradata_size == 0){
           ^
49.         avctx->extradata_size=15;
50.         avctx->extradata= av_malloc(avctx->extradata_size);

libavcodec/mp3_header_compress_bsf.c:49:9: 
47. 
48.     if(avctx->extradata_size == 0){
49.         avctx->extradata_size=15;
            ^
50.         avctx->extradata= av_malloc(avctx->extradata_size);
51.         strcpy(avctx->extradata, "FFCMP3 0.0");

libavcodec/mp3_header_compress_bsf.c:50:9: 
48.     if(avctx->extradata_size == 0){
49.         avctx->extradata_size=15;
50.         avctx->extradata= av_malloc(avctx->extradata_size);
            ^
51.         strcpy(avctx->extradata, "FFCMP3 0.0");
52.         memcpy(avctx->extradata+11, buf, 4);

libavutil/mem.c:43:1: start of procedure av_malloc()
  41.    linker will do it automatically */
  42. 
  43. void *av_malloc(unsigned int size)
      ^
  44. {
  45.     void *ptr = NULL;

libavutil/mem.c:45:5: 
  43. void *av_malloc(unsigned int size)
  44. {
  45.     void *ptr = NULL;
          ^
  46. #ifdef CONFIG_MEMALIGN_HACK
  47.     long diff;

libavutil/mem.c:51:8: Taking false branch
  49. 
  50.     /* let's disallow possible ambiguous cases */
  51.     if(size > (INT_MAX-16) )
             ^
  52.         return NULL;
  53. 

libavutil/mem.c:62:5: Skipping posix_memalign(): method has no implementation
  60.     ((char*)ptr)[-1]= diff;
  61. #elif defined (HAVE_POSIX_MEMALIGN)
  62.     posix_memalign(&ptr,16,size);
          ^
  63. #elif defined (HAVE_MEMALIGN)
  64.     ptr = memalign(16,size);

libavutil/mem.c:94:5: 
  92.     ptr = malloc(size);
  93. #endif
  94.     return ptr;
          ^
  95. }
  96. 

libavutil/mem.c:95:1: return from a call to av_malloc
  93. #endif
  94.     return ptr;
  95. }
      ^
  96. 
  97. void *av_realloc(void *ptr, unsigned int size)

libavcodec/mp3_header_compress_bsf.c:51:9: 
49.         avctx->extradata_size=15;
50.         avctx->extradata= av_malloc(avctx->extradata_size);
51.         strcpy(avctx->extradata, "FFCMP3 0.0");
            ^
52.         memcpy(avctx->extradata+11, buf, 4);
53.     }

libavcodec/mp3_header_compress_bsf.c:52:9: 
50.         avctx->extradata= av_malloc(avctx->extradata_size);
51.         strcpy(avctx->extradata, "FFCMP3 0.0");
52.         memcpy(avctx->extradata+11, buf, 4);
            ^
53.     }
54.     if(avctx->extradata_size != 15){

libavcodec/mp3_header_compress_bsf.c:54:8: Taking false branch
52.         memcpy(avctx->extradata+11, buf, 4);
53.     }
54.     if(avctx->extradata_size != 15){
           ^
55.         av_log(avctx, AV_LOG_ERROR, "Extradata invalid\n");
56.         return -1;

libavcodec/mp3_header_compress_bsf.c:58:5: 
56.         return -1;
57.     }
58.     extraheader = AV_RB32(avctx->extradata+11);
        ^
59.     if((extraheader&MP3_MASK) != (header&MP3_MASK))
60.         goto output_unchanged;

libavcodec/mp3_header_compress_bsf.c:59:8: Taking false branch
57.     }
58.     extraheader = AV_RB32(avctx->extradata+11);
59.     if((extraheader&MP3_MASK) != (header&MP3_MASK))
           ^
60.         goto output_unchanged;
61. 

libavcodec/mp3_header_compress_bsf.c:62:19: Condition is false
60.         goto output_unchanged;
61. 
62.     header_size= (header&0x10000) ? 4 : 6;
                      ^
63. 
64.     *poutbuf_size= buf_size - header_size;

libavcodec/mp3_header_compress_bsf.c:62:18: 
60.         goto output_unchanged;
61. 
62.     header_size= (header&0x10000) ? 4 : 6;
                     ^
63. 
64.     *poutbuf_size= buf_size - header_size;

libavcodec/mp3_header_compress_bsf.c:62:5: 
60.         goto output_unchanged;
61. 
62.     header_size= (header&0x10000) ? 4 : 6;
        ^
63. 
64.     *poutbuf_size= buf_size - header_size;

libavcodec/mp3_header_compress_bsf.c:64:5: 
62.     header_size= (header&0x10000) ? 4 : 6;
63. 
64.     *poutbuf_size= buf_size - header_size;
        ^
65.     *poutbuf= av_malloc(buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
66.     memcpy(*poutbuf, buf + header_size, buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);

libavcodec/mp3_header_compress_bsf.c:65:5: 
63. 
64.     *poutbuf_size= buf_size - header_size;
65.     *poutbuf= av_malloc(buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
        ^
66.     memcpy(*poutbuf, buf + header_size, buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
67. 

libavutil/mem.c:43:1: start of procedure av_malloc()
  41.    linker will do it automatically */
  42. 
  43. void *av_malloc(unsigned int size)
      ^
  44. {
  45.     void *ptr = NULL;

libavutil/mem.c:45:5: 
  43. void *av_malloc(unsigned int size)
  44. {
  45.     void *ptr = NULL;
          ^
  46. #ifdef CONFIG_MEMALIGN_HACK
  47.     long diff;

libavutil/mem.c:51:8: Taking true branch
  49. 
  50.     /* let's disallow possible ambiguous cases */
  51.     if(size > (INT_MAX-16) )
             ^
  52.         return NULL;
  53. 

libavutil/mem.c:52:9: 
  50.     /* let's disallow possible ambiguous cases */
  51.     if(size > (INT_MAX-16) )
  52.         return NULL;
              ^
  53. 
  54. #ifdef CONFIG_MEMALIGN_HACK

libavutil/mem.c:95:1: return from a call to av_malloc
  93. #endif
  94.     return ptr;
  95. }
      ^
  96. 
  97. void *av_realloc(void *ptr, unsigned int size)

libavcodec/mp3_header_compress_bsf.c:66:5: 
64.     *poutbuf_size= buf_size - header_size;
65.     *poutbuf= av_malloc(buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
66.     memcpy(*poutbuf, buf + header_size, buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
        ^
67. 
68.     if(avctx->channels==2){

static int mp3_header_compress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
                     uint8_t **poutbuf, int *poutbuf_size,
                     const uint8_t *buf, int buf_size, int keyframe){
    uint32_t header, extraheader;
    int mode_extension, header_size;
    if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){
        av_log(avctx, AV_LOG_ERROR, "not standards compliant\n");
        return -1;
    }
    header = AV_RB32(buf);
    mode_extension= (header>>4)&3;
    if(ff_mpa_check_header(header) < 0 || (header&0x60000) != 0x20000){
output_unchanged:
        *poutbuf= (uint8_t *) buf;
        *poutbuf_size= buf_size;
        av_log(avctx, AV_LOG_INFO, "cannot compress %08X\n", header);
        return 0;
    }
    if(avctx->extradata_size == 0){
        avctx->extradata_size=15;
        avctx->extradata= av_malloc(avctx->extradata_size);
        strcpy(avctx->extradata, "FFCMP3 0.0");
        memcpy(avctx->extradata+11, buf, 4);
    }
    if(avctx->extradata_size != 15){
        av_log(avctx, AV_LOG_ERROR, "Extradata invalid\n");
        return -1;
    }
    extraheader = AV_RB32(avctx->extradata+11);
    if((extraheader&MP3_MASK) != (header&MP3_MASK))
        goto output_unchanged;
    header_size= (header&0x10000) ? 4 : 6;
    *poutbuf_size= buf_size - header_size;
    *poutbuf= av_malloc(buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
    memcpy(*poutbuf, buf + header_size, buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
    if(avctx->channels==2){
        if((header & (3<<19)) != 3<<19){
            (*poutbuf)[1] &= 0x3F;
            (*poutbuf)[1] |= mode_extension<<6;
            FFSWAP(int, (*poutbuf)[1], (*poutbuf)[2]);
        }else{
            (*poutbuf)[1] &= 0x8F;
            (*poutbuf)[1] |= mode_extension<<4;
        }
    }
    return 1;
}
['static int mp3_header_compress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,\n                     uint8_t **poutbuf, int *poutbuf_size,\n                     const uint8_t *buf, int buf_size, int keyframe){\n    uint32_t header, extraheader;\n    int mode_extension, header_size;\n    if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){\n        av_log(avctx, AV_LOG_ERROR, "not standards compliant\\n");\n        return -1;\n    }\n    header = AV_RB32(buf);\n    mode_extension= (header>>4)&3;\n    if(ff_mpa_check_header(header) < 0 || (header&0x60000) != 0x20000){\noutput_unchanged:\n        *poutbuf= (uint8_t *) buf;\n        *poutbuf_size= buf_size;\n        av_log(avctx, AV_LOG_INFO, "cannot compress %08X\\n", header);\n        return 0;\n    }\n    if(avctx->extradata_size == 0){\n        avctx->extradata_size=15;\n        avctx->extradata= av_malloc(avctx->extradata_size);\n        strcpy(avctx->extradata, "FFCMP3 0.0");\n        memcpy(avctx->extradata+11, buf, 4);\n    }\n    if(avctx->extradata_size != 15){\n        av_log(avctx, AV_LOG_ERROR, "Extradata invalid\\n");\n        return -1;\n    }\n    extraheader = AV_RB32(avctx->extradata+11);\n    if((extraheader&MP3_MASK) != (header&MP3_MASK))\n        goto output_unchanged;\n    header_size= (header&0x10000) ? 4 : 6;\n    *poutbuf_size= buf_size - header_size;\n    *poutbuf= av_malloc(buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);\n    memcpy(*poutbuf, buf + header_size, buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);\n    if(avctx->channels==2){\n        if((header & (3<<19)) != 3<<19){\n            (*poutbuf)[1] &= 0x3F;\n            (*poutbuf)[1] |= mode_extension<<6;\n            FFSWAP(int, (*poutbuf)[1], (*poutbuf)[2]);\n        }else{\n            (*poutbuf)[1] &= 0x8F;\n            (*poutbuf)[1] |= mode_extension<<4;\n        }\n    }\n    return 1;\n}', 'static inline int ff_mpa_check_header(uint32_t header){\n    if ((header & 0xffe00000) != 0xffe00000)\n        return -1;\n    if ((header & (3<<17)) == 0)\n        return -1;\n    if ((header & (0xf<<12)) == 0xf<<12)\n        return -1;\n    if ((header & (3<<10)) == 3<<10)\n        return -1;\n    return 0;\n}', 'void *av_malloc(unsigned int size)\n{\n    void *ptr = NULL;\n#ifdef CONFIG_MEMALIGN_HACK\n    long diff;\n#endif\n    if(size > (INT_MAX-16) )\n        return NULL;\n#ifdef CONFIG_MEMALIGN_HACK\n    ptr = malloc(size+16);\n    if(!ptr)\n        return ptr;\n    diff= ((-(long)ptr - 1)&15) + 1;\n    ptr = (char*)ptr + diff;\n    ((char*)ptr)[-1]= diff;\n#elif defined (HAVE_POSIX_MEMALIGN)\n    posix_memalign(&ptr,16,size);\n#elif defined (HAVE_MEMALIGN)\n    ptr = memalign(16,size);\n#else\n    ptr = malloc(size);\n#endif\n    return ptr;\n}']