[asterisk-dev] Re: Question about zt_read() in chan_zap

Nic Bellamy nicb-lists at vadacom.co.nz
Wed Jan 17 14:33:36 MST 2007


Tony Mountifield wrote:
> In article <45AE6F68.6070808 at digium.com>,
> Kevin P. Fleming <kpfleming at digium.com> wrote:
>   
>> Tony Mountifield wrote:
>>     
>>> readbuf = ((unsigned char *)p->subs[index].buffer) + AST_FRIENDLY_OFFSET;
>>>       
>> p->subs[index].buffer is an array of 'short's, so here is has been cast
>> to (unsigned char) and AST_FRIENDLY_OFFSET is interpreted as count of
>> 'char' size.
>>
>>     
>>> p->subs[index].f.data = p->subs[index].buffer + AST_FRIENDLY_OFFSET/2;
>>>       
>> Here p->subs[index].buffer has NOT been cast to char, so the offset
>> would be interpreted as a count of 'short' size. Thus, it needs to be
>> halved to end up with the same number of bytes.
>>     
>
> Aha - kerching! I didn't think something like that would have gone
> unnoticed for so long if it were an error.
>
> Perhaps a comment in the code would reassure the mext person who wonders!
>   
Making it divided by sizeof(short) rather than a literal "2" might also 
help make things clearer.

I've not yet met a machine where sizeof(char) * 2 != sizeof(short), but 
you never know ;-)

Cheers,
    Nic.

-- 
Nic Bellamy,
Head Of Engineering, Vadacom Ltd - http://www.vadacom.co.nz/



More information about the asterisk-dev mailing list