libavcodec/resample.c:189: error: Null Dereference
  pointer `bufin[i]` last assigned on line 188 could be null and is dereferenced by call to `memcpy()` at line 189, column 9.

libavcodec/resample.c:172:1: start of procedure audio_resample()
170. /* resample audio. 'nb_samples' is the number of input samples */
171. /* XXX: optimize it ! */
172. int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples)
     ^
173. {
174.     int i, nb_samples1;

libavcodec/resample.c:180:9: Taking false branch
178.     int lenout;
179. 
180.     if (s->input_channels == s->output_channels && s->ratio == 1.0 && 0) {
             ^
181.         /* nothing to do */
182.         memcpy(output, input, nb_samples * s->input_channels * sizeof(short));

libavcodec/resample.c:187:9: 
185. 
186.     /* XXX: move those malloc to resample init code */
187.     for(i=0; i<s->filter_channels; i++){
             ^
188.         bufin[i]= av_malloc( (nb_samples + s->temp_len) * sizeof(short) );
189.         memcpy(bufin[i], s->temp[i], s->temp_len * sizeof(short));

libavcodec/resample.c:187:14: Loop condition is true. Entering loop body
185. 
186.     /* XXX: move those malloc to resample init code */
187.     for(i=0; i<s->filter_channels; i++){
                  ^
188.         bufin[i]= av_malloc( (nb_samples + s->temp_len) * sizeof(short) );
189.         memcpy(bufin[i], s->temp[i], s->temp_len * sizeof(short));

libavcodec/resample.c:188:9: 
186.     /* XXX: move those malloc to resample init code */
187.     for(i=0; i<s->filter_channels; i++){
188.         bufin[i]= av_malloc( (nb_samples + s->temp_len) * sizeof(short) );
             ^
189.         memcpy(bufin[i], s->temp[i], s->temp_len * sizeof(short));
190.         buftmp2[i] = bufin[i] + s->temp_len;

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/resample.c:189:9: 
187.     for(i=0; i<s->filter_channels; i++){
188.         bufin[i]= av_malloc( (nb_samples + s->temp_len) * sizeof(short) );
189.         memcpy(bufin[i], s->temp[i], s->temp_len * sizeof(short));
             ^
190.         buftmp2[i] = bufin[i] + s->temp_len;
191.     }

int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples)
{
    int i, nb_samples1;
    short *bufin[2];
    short *bufout[2];
    short *buftmp2[2], *buftmp3[2];
    int lenout;
    if (s->input_channels == s->output_channels && s->ratio == 1.0 && 0) {
        memcpy(output, input, nb_samples * s->input_channels * sizeof(short));
        return nb_samples;
    }
    for(i=0; i<s->filter_channels; i++){
        bufin[i]= av_malloc( (nb_samples + s->temp_len) * sizeof(short) );
        memcpy(bufin[i], s->temp[i], s->temp_len * sizeof(short));
        buftmp2[i] = bufin[i] + s->temp_len;
    }
    lenout= 4*nb_samples * s->ratio + 16;
    bufout[0]= av_malloc( lenout * sizeof(short) );
    bufout[1]= av_malloc( lenout * sizeof(short) );
    if (s->input_channels == 2 &&
        s->output_channels == 1) {
        buftmp3[0] = output;
        stereo_to_mono(buftmp2[0], input, nb_samples);
    } else if (s->output_channels >= 2 && s->input_channels == 1) {
        buftmp3[0] = bufout[0];
        memcpy(buftmp2[0], input, nb_samples*sizeof(short));
    } else if (s->output_channels >= 2) {
        buftmp3[0] = bufout[0];
        buftmp3[1] = bufout[1];
        stereo_split(buftmp2[0], buftmp2[1], input, nb_samples);
    } else {
        buftmp3[0] = output;
        memcpy(buftmp2[0], input, nb_samples*sizeof(short));
    }
    nb_samples += s->temp_len;
    nb_samples1 = 0;
    for(i=0;i<s->filter_channels;i++) {
        int consumed;
        int is_last= i+1 == s->filter_channels;
        nb_samples1 = av_resample(s->resample_context, buftmp3[i], bufin[i], &consumed, nb_samples, lenout, is_last);
        s->temp_len= nb_samples - consumed;
        s->temp[i]= av_realloc(s->temp[i], s->temp_len*sizeof(short));
        memcpy(s->temp[i], bufin[i] + consumed, s->temp_len*sizeof(short));
    }
    if (s->output_channels == 2 && s->input_channels == 1) {
        mono_to_stereo(output, buftmp3[0], nb_samples1);
    } else if (s->output_channels == 2) {
        stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
    } else if (s->output_channels == 6) {
        ac3_5p1_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
    }
    for(i=0; i<s->filter_channels; i++)
        av_free(bufin[i]);
    av_free(bufout[0]);
    av_free(bufout[1]);
    return nb_samples1;
}
['int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples)\n{\n    int i, nb_samples1;\n    short *bufin[2];\n    short *bufout[2];\n    short *buftmp2[2], *buftmp3[2];\n    int lenout;\n    if (s->input_channels == s->output_channels && s->ratio == 1.0 && 0) {\n        memcpy(output, input, nb_samples * s->input_channels * sizeof(short));\n        return nb_samples;\n    }\n    for(i=0; i<s->filter_channels; i++){\n        bufin[i]= av_malloc( (nb_samples + s->temp_len) * sizeof(short) );\n        memcpy(bufin[i], s->temp[i], s->temp_len * sizeof(short));\n        buftmp2[i] = bufin[i] + s->temp_len;\n    }\n    lenout= 4*nb_samples * s->ratio + 16;\n    bufout[0]= av_malloc( lenout * sizeof(short) );\n    bufout[1]= av_malloc( lenout * sizeof(short) );\n    if (s->input_channels == 2 &&\n        s->output_channels == 1) {\n        buftmp3[0] = output;\n        stereo_to_mono(buftmp2[0], input, nb_samples);\n    } else if (s->output_channels >= 2 && s->input_channels == 1) {\n        buftmp3[0] = bufout[0];\n        memcpy(buftmp2[0], input, nb_samples*sizeof(short));\n    } else if (s->output_channels >= 2) {\n        buftmp3[0] = bufout[0];\n        buftmp3[1] = bufout[1];\n        stereo_split(buftmp2[0], buftmp2[1], input, nb_samples);\n    } else {\n        buftmp3[0] = output;\n        memcpy(buftmp2[0], input, nb_samples*sizeof(short));\n    }\n    nb_samples += s->temp_len;\n    nb_samples1 = 0;\n    for(i=0;i<s->filter_channels;i++) {\n        int consumed;\n        int is_last= i+1 == s->filter_channels;\n        nb_samples1 = av_resample(s->resample_context, buftmp3[i], bufin[i], &consumed, nb_samples, lenout, is_last);\n        s->temp_len= nb_samples - consumed;\n        s->temp[i]= av_realloc(s->temp[i], s->temp_len*sizeof(short));\n        memcpy(s->temp[i], bufin[i] + consumed, s->temp_len*sizeof(short));\n    }\n    if (s->output_channels == 2 && s->input_channels == 1) {\n        mono_to_stereo(output, buftmp3[0], nb_samples1);\n    } else if (s->output_channels == 2) {\n        stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1);\n    } else if (s->output_channels == 6) {\n        ac3_5p1_mux(output, buftmp3[0], buftmp3[1], nb_samples1);\n    }\n    for(i=0; i<s->filter_channels; i++)\n        av_free(bufin[i]);\n    av_free(bufout[0]);\n    av_free(bufout[1]);\n    return nb_samples1;\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}']