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

Tony Mountifield tony at softins.clara.co.uk
Wed Jan 17 13:00:06 MST 2007


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!

Thanks
Tony
-- 
Tony Mountifield
Work: tony at softins.co.uk - http://www.softins.co.uk
Play: tony at mountifield.org - http://tony.mountifield.org


More information about the asterisk-dev mailing list