Summary:ASTERISK-04167: likely bug in [undocumented] handling of fout field of ast_channel
Reporter:Luigi Rizzo (rizzo)Labels:
Date Opened:2005-05-14 15:52:55Date Closed:2011-06-07 14:10:12
Versions:Frequency of
Description:There is some [undocumented] code in channel.c, cli.c, apps/app_dumpchan.c
that uses bit 31 of the fin and fout fields to mark some kind of debugging.
So only the initial 31 bits (0..30) are available as a counter.

Being completely undocumented, i cannot follow the logic but one
reasonable options is to handle wraps so that bit 31 is unaffected.
If this is the case, then channel.c::ast_write() near the end has
an extra  chan->fout++ that should be removed.
Of course a comment describing the mechanism, and the definition of
a constant for the magic number 0x80000000 and ~0x80000000
would be a good thing.
Something as below in channels.h, and then CHAN_INC(chan->fin) etc
in channel.c


   /* Frames in/out counters.  
    * Bit 31 is used to signal debugging, so the actual counter
    * can only use 31 bits, and increments should take care not
    * to toggle the high bit.
#define DEBUGCHAN_FLAG  0x80000000U
#define CHAN_INC(v) do {                                \
   if ((v) & (DEBUGCHAN_FLAG-1) == (DEBUGCHAN_FLAG-1)) \
       v &= DEBUGCHAN_FLAG; else (v)++; } while (0)
   unsigned int fin;  
   unsigned int fout;
Comments:By: Mark Spencer (markster) 2005-05-14 19:21:10

Removed the extra fout++ and added a comment.

By: Russell Bryant (russell) 2005-05-15 23:07:02

fixed in 1.0 as well

By: Digium Subversion (svnbot) 2008-01-15 15:34:19.000-0600

Repository: asterisk
Revision: 5649

U   trunk/channel.c

r5649 | markster | 2008-01-15 15:34:18 -0600 (Tue, 15 Jan 2008) | 2 lines

Remove double fout++ and comment on flag (bug ASTERISK-4167)



By: Digium Subversion (svnbot) 2008-01-15 15:35:00.000-0600

Repository: asterisk
Revision: 5695

U   branches/v1-0/channel.c

r5695 | russell | 2008-01-15 15:34:59 -0600 (Tue, 15 Jan 2008) | 2 lines

Remove double fout++ and comment on flag (bug ASTERISK-4167)