libavcodec/mp3_header_compress_bsf.c:51: error: Null Dereference
  pointer `avctx->extradata` last assigned on line 50 could be null and is dereferenced by call to `strcpy()` at line 51, column 9.

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. 

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.     x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);

libavutil/bswap.h:68:5: 
  66. static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
  67. {
  68.     x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
          ^
  69.     x= (x>>16) | (x<<16);
  70.     return x;

libavutil/bswap.h:69:5: 
  67. {
  68.     x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  69.     x= (x>>16) | (x<<16);
          ^
  70.     return x;
  71. }

libavutil/bswap.h:70:5: 
  68.     x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  69.     x= (x>>16) | (x<<16);
  70.     return x;
          ^
  71. }
  72. #endif

libavutil/bswap.h:71:1: return from a call to av_bswap32
  69.     x= (x>>16) | (x<<16);
  70.     return x;
  71. }
      ^
  72. #endif
  73. 

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:194:1: start of procedure ff_mpa_check_header()
  192. 
  193. /* fast header check for resync */
  194. static inline int ff_mpa_check_header(uint32_t header){
       ^
  195.     /* header */
  196.     if ((header & 0xffe00000) != 0xffe00000)

libavcodec/mpegaudio.h:196:9: Taking false branch
  194. static inline int ff_mpa_check_header(uint32_t header){
  195.     /* header */
  196.     if ((header & 0xffe00000) != 0xffe00000)
               ^
  197.         return -1;
  198.     /* layer check */

libavcodec/mpegaudio.h:199:9: Taking false branch
  197.         return -1;
  198.     /* layer check */
  199.     if ((header & (3<<17)) == 0)
               ^
  200.         return -1;
  201.     /* bit rate */

libavcodec/mpegaudio.h:202:9: Taking false branch
  200.         return -1;
  201.     /* bit rate */
  202.     if ((header & (0xf<<12)) == 0xf<<12)
               ^
  203.         return -1;
  204.     /* frequency */

libavcodec/mpegaudio.h:205:9: Taking false branch
  203.         return -1;
  204.     /* frequency */
  205.     if ((header & (3<<10)) == 3<<10)
               ^
  206.         return -1;
  207.     return 0;

libavcodec/mpegaudio.h:207:5: 
  205.     if ((header & (3<<10)) == 3<<10)
  206.         return -1;
  207.     return 0;
           ^
  208. }
  209. 

libavcodec/mpegaudio.h:208:1: return from a call to ff_mpa_check_header
  206.         return -1;
  207.     return 0;
  208. }
       ^
  209. 
  210. #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:64:1: start of procedure av_malloc()
  62.    linker will do it automatically. */
  63. 
  64. void *av_malloc(unsigned int size)
      ^
  65. {
  66.     void *ptr = NULL;

libavutil/mem.c:66:5: 
  64. void *av_malloc(unsigned int size)
  65. {
  66.     void *ptr = NULL;
          ^
  67. #if CONFIG_MEMALIGN_HACK
  68.     long diff;

libavutil/mem.c:72:8: Taking false branch
  70. 
  71.     /* let's disallow possible ambiguous cases */
  72.     if(size > (INT_MAX-16) )
             ^
  73.         return NULL;
  74. 

libavutil/mem.c:83:9: Taking true branch
  81.     ((char*)ptr)[-1]= diff;
  82. #elif HAVE_POSIX_MEMALIGN
  83.     if (posix_memalign(&ptr,16,size))
              ^
  84.         ptr = NULL;
  85. #elif HAVE_MEMALIGN

libavutil/mem.c:84:9: 
  82. #elif HAVE_POSIX_MEMALIGN
  83.     if (posix_memalign(&ptr,16,size))
  84.         ptr = NULL;
              ^
  85. #elif HAVE_MEMALIGN
  86.     ptr = memalign(16,size);

libavutil/mem.c:116:5: 
  114.     ptr = malloc(size);
  115. #endif
  116.     return ptr;
           ^
  117. }
  118. 

libavutil/mem.c:117:1: return from a call to av_malloc
  115. #endif
  116.     return ptr;
  117. }
       ^
  118. 
  119. 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.     }

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 av_always_inline av_const uint32_t av_bswap32(uint32_t x)\n{\n    x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);\n    x= (x>>16) | (x<<16);\n    return x;\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#if CONFIG_MEMALIGN_HACK\n    long diff;\n#endif\n    if(size > (INT_MAX-16) )\n        return NULL;\n#if 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 HAVE_POSIX_MEMALIGN\n    if (posix_memalign(&ptr,16,size))\n        ptr = NULL;\n#elif HAVE_MEMALIGN\n    ptr = memalign(16,size);\n#else\n    ptr = malloc(size);\n#endif\n    return ptr;\n}']