]> git.sesse.net Git - vlc/commitdiff
Fixed potential segfault (on failures) with avcodec audio encoder.
authorLaurent Aimar <fenrir@videolan.org>
Sat, 1 May 2010 18:24:05 +0000 (20:24 +0200)
committerLaurent Aimar <fenrir@videolan.org>
Sat, 1 May 2010 22:23:29 +0000 (00:23 +0200)
modules/codec/avcodec/encoder.c

index 32870486135d2a632be9e6907cf226d8a5715963..ecbbe91be3c0dc9f5df17231a77c92a691e570a0 100644 (file)
@@ -947,13 +947,12 @@ static block_t *EncodeAudio( encoder_t *p_enc, aout_buffer_t *p_aout_buf )
 #if 0
         msg_Warn( p_enc, "avcodec_encode_audio: %d", i_out );
 #endif
-        if( i_out < 0 ) break;
-
         p_buffer += p_sys->i_frame_size;
         p_sys->i_samples_delay -= p_sys->p_context->frame_size;
         i_samples -= p_sys->p_context->frame_size;
 
-        if( i_out == 0 ) continue;
+        if( i_out <= 0 )
+            continue;
 
         p_block = block_New( p_enc, i_out );
         memcpy( p_block->p_buffer, p_sys->p_buffer_out, i_out );
@@ -972,8 +971,8 @@ static block_t *EncodeAudio( encoder_t *p_enc, aout_buffer_t *p_aout_buf )
     /* Backup the remaining raw samples */
     if( i_samples )
     {
-        memcpy( p_sys->p_buffer + i_samples_delay * 2 *
-                p_sys->p_context->channels, p_buffer,
+        memcpy( &p_sys->p_buffer[i_samples_delay * 2 * p_sys->p_context->channels],
+                p_buffer,
                 i_samples * 2 * p_sys->p_context->channels );
     }