Changeset 282 for pjproject


Ignore:
Timestamp:
Mar 5, 2006 11:51:10 AM (19 years ago)
Author:
bennylp
Message:

Added assert checking in speex codec

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia-codec/speex_codec.c

    r278 r282  
    677677{ 
    678678    struct spx_private *spx; 
    679     float tmp[640]; /* 20ms at 32KHz */ 
     679    float tmp[642]; /* 20ms at 32KHz + 2 */ 
    680680    pj_int16_t *samp_in; 
    681     unsigned i, samp_count; 
     681    unsigned i, samp_count, sz; 
    682682 
    683683    spx = (struct spx_private*) codec->codec_data; 
     
    693693    /* Copy frame to float buffer. */ 
    694694    samp_count = input->size / 2; 
     695    pj_assert(samp_count <= PJ_ARRAY_SIZE(tmp)); 
    695696    samp_in = input->buf; 
    696697    for (i=0; i<samp_count; ++i) { 
     
    703704    /* Encode the frame */ 
    704705    speex_encode(spx->enc, tmp, &spx->enc_bits); 
     706 
     707    /* Check size. */ 
     708    sz = speex_bits_nbytes(&spx->enc_bits); 
     709    pj_assert(sz <= output_buf_len); 
    705710 
    706711    /* Copy the bits to an array of char that can be written */ 
     
    722727{ 
    723728    struct spx_private *spx; 
    724     float tmp[640]; /* 20ms at 32KHz */ 
     729    float tmp[642]; /* 20ms at 32KHz + 2 */ 
    725730    pj_int16_t *dst_buf; 
    726     unsigned i, count; 
     731    unsigned i, count, sz; 
    727732 
    728733    spx = (struct spx_private*) codec->codec_data; 
     
    745750    speex_decode(spx->dec, &spx->dec_bits, tmp); 
    746751 
     752    /* Check size. */ 
     753    sz = speex_bits_nbytes(&spx->enc_bits); 
     754    pj_assert(sz <= output_buf_len); 
     755 
     756    /* Copy from float to short samples. */ 
    747757    count = spx_factory.speex_param[spx->param_id].clock_rate * 20 / 1000; 
     758    pj_assert((count <= output_buf_len/2) && count <= PJ_ARRAY_SIZE(tmp)); 
    748759    dst_buf = output->buf; 
    749760    for (i=0; i<count; ++i) { 
Note: See TracChangeset for help on using the changeset viewer.