Changeset a74d5452eb0c1b7846e14090c1063169ebd9681a

Show
Ignore:
Timestamp:
03/04/08 15:35:01 (6 months ago)
Author:
Jean-Paul Saman <jpsaman@videolan.org>
git-committer:
Jean-Paul Saman <jpsaman@videolan.org> 1204641301 +0100
git-parent:

[93b4565847b0f951ac5cf036d14d5b0544cfe64c]

git-author:
Jean-Paul Saman <jpsaman@videolan.org> 1204481576 +0100
Message:

Check malloc return values and small cleanup.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/packetizer/mpeg4audio.c

    r079a181 ra74d545  
    141141 
    142142enum { 
    143  
    144143    STATE_NOSYNC, 
    145144    STATE_SYNC, 
     
    250249        p_dec->fmt_out.i_extra = p_dec->fmt_in.i_extra; 
    251250        p_dec->fmt_out.p_extra = malloc( p_dec->fmt_in.i_extra ); 
     251        if( !p_dec->fmt_out.p_extra ) 
     252        { 
     253            p_dec->fmt_out.i_extra = 0; 
     254            return VLC_ENOMEM; 
     255        } 
    252256        memcpy( p_dec->fmt_out.p_extra, p_dec->fmt_in.p_extra, 
    253257                p_dec->fmt_in.i_extra ); 
     
    353357    if( !p_dec->fmt_out.i_extra ) 
    354358    { 
     359        p_dec->fmt_out.p_extra = malloc( 2 ); 
     360        if( !p_dec->fmt_out.p_extra ) 
     361        { 
     362            p_dec->fmt_out.i_extra = 0; 
     363            return 0; 
     364        } 
    355365        p_dec->fmt_out.i_extra = 2; 
    356         p_dec->fmt_out.p_extra = malloc( 2 ); 
    357366        ((uint8_t *)p_dec->fmt_out.p_extra)[0] = 
    358367            (i_profile + 1) << 3 | (i_sample_rate_idx >> 1); 
     
    366375    return i_frame_size - *pi_header_size; 
    367376} 
     377 
    368378/**************************************************************************** 
    369379 * LOAS helpers 
     
    374384    return ( ( p_header[1] & 0x1f ) << 8 ) + p_header[2]; 
    375385} 
     386 
    376387static int Mpeg4GAProgramConfigElement( bs_t *s ) 
    377388{ 
     
    406417    return 0; 
    407418} 
     419 
    408420static int Mpeg4GASpecificConfig( mpeg4_cfg_t *p_cfg, bs_t *s ) 
    409421{ 
     
    437449    return 0; 
    438450} 
     451 
    439452static int Mpeg4ReadAudioObjectType( bs_t *s ) 
    440453{ 
     
    444457    return i_type; 
    445458} 
     459 
    446460static int Mpeg4ReadAudioSamplerate( bs_t *s ) 
    447461{ 
     
    451465    return bs_read( s, 24 ); 
    452466} 
     467 
    453468static int Mpeg4ReadAudioSpecificInfo( mpeg4_cfg_t *p_cfg, int *pi_extra, uint8_t *p_extra, bs_t *s, int i_max_size ) 
    454469{ 
     
    480495    memset( p_cfg, 0, sizeof(*p_cfg) ); 
    481496    *pi_extra = 0; 
    482      
     497 
    483498    p_cfg->i_object_type = Mpeg4ReadAudioObjectType( s ); 
    484499    p_cfg->i_samplerate = Mpeg4ReadAudioSamplerate( s ); 
     
    566581        break; 
    567582    } 
     583 
    568584    if( p_cfg->extension.i_object_type != 5 && i_max_size > 0 && i_max_size - (bs_pos(s) - i_pos_start) >= 16 &&  
    569585        bs_read( s, 11 ) == 0x2b7 ) 
     
    734750    if( !bs_read1( &s ) ) 
    735751    { 
    736         if( !LatmReadStreamMuxConfiguration( &p_sys->latm, &s ) && p_sys->latm.i_streams > 0 ) 
     752        if( !LatmReadStreamMuxConfiguration( &p_sys->latm, &s ) && 
     753            p_sys->latm.i_streams > 0 ) 
    737754        { 
    738755            const latm_stream_t *st = &p_sys->latm.stream[0]; 
     
    747764                p_dec->fmt_out.i_extra = st->i_extra; 
    748765                p_dec->fmt_out.p_extra = malloc( st->i_extra ); 
     766                if( !p_dec->fmt_out.p_extra ) 
     767                { 
     768                    p_dec->fmt_out.i_extra = 0; 
     769                    return 0; 
     770                } 
    749771                memcpy( p_dec->fmt_out.p_extra, st->extra, st->i_extra ); 
    750772            } 
     
    790812                        pi_payload[i_program][i_layer] = st->i_frame_length / 8; /* XXX not correct */ 
    791813                    } 
    792                     else if( st->i_frame_length_type == 3 || st->i_frame_length_type == 5 || st->i_frame_length_type == 7 ) 
     814                    else if( ( st->i_frame_length_type == 3 ) || 
     815                             ( st->i_frame_length_type == 5 ) || 
     816                             ( st->i_frame_length_type == 7 ) ) 
    793817                    { 
    794818                        bs_skip( &s, 2 ); // muxSlotLengthCoded 
     
    857881                    pi_payload[i_program][i_layer] = st->i_frame_length / 8; /* XXX not correct */ 
    858882                } 
    859                 else if( st->i_frame_length_type == 3 || st->i_frame_length_type == 5 || st->i_frame_length_type == 7 ) 
     883                else if( ( st->i_frame_length_type == 3 ) || 
     884                         ( st->i_frame_length_type == 5 ) || 
     885                         ( st->i_frame_length_type == 7 ) ) 
    860886                { 
    861887                    bs_read( &s, 2 ); // muxSlotLengthCoded 
     
    10161042            /* TODO: If p_block == NULL, flush the buffer without checking the 
    10171043             * next sync word */ 
     1044            if( p_sys->bytestream.p_block == NULL ) 
     1045            { 
     1046                p_sys->i_state = STATE_NOSYNC; 
     1047                block_BytestreamFlush( &p_sys->bytestream ); 
     1048                return NULL; 
     1049            } 
    10181050 
    10191051            /* Check if next expected frame contains the sync word */ 
     
    10261058            } 
    10271059 
    1028             assert( p_sys->i_type == TYPE_ADTS || p_sys->i_type == TYPE_LOAS ); 
    1029             if( ( p_sys->i_type == TYPE_ADTS && ( p_header[0] != 0xff || (p_header[1] & 0xf6) != 0xf0 ) ) || 
    1030                 ( p_sys->i_type == TYPE_LOAS && ( p_header[0] != 0x56 || (p_header[1] & 0xe0) != 0xe0 ) ) ) 
     1060            assert( (p_sys->i_type == TYPE_ADTS) || (p_sys->i_type == TYPE_LOAS) ); 
     1061            if( ( ( p_sys->i_type == TYPE_ADTS ) && 
     1062                  ( p_header[0] != 0xff || (p_header[1] & 0xf6) != 0xf0 ) ) || 
     1063                ( ( p_sys->i_type == TYPE_LOAS ) && 
     1064                  ( p_header[0] != 0x56 || (p_header[1] & 0xe0) != 0xe0 ) ) ) 
    10311065            { 
    10321066                msg_Dbg( p_dec, "emulated sync word " 
     
    11051139} 
    11061140 
    1107  
    11081141/***************************************************************************** 
    11091142 * SetupBuffer: 
     
    11521185    free( p_dec->p_sys ); 
    11531186} 
    1154  
    1155