From 7fed380d0a9ebfaa91599ab0cfc12b408251aa19 Mon Sep 17 00:00:00 2001 From: Kamal Mostafa Date: Tue, 16 Oct 2012 18:02:21 -0700 Subject: [PATCH] callerid: do not use recursive call to reset Testing by Mike Tedesco shows the recursive databits_decode_callerid() seems to break on OS X (only); I don't see why it should. Avoid the issue by not making a recursive call. --- src/databits_callerid.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/databits_callerid.c b/src/databits_callerid.c index b1459ec..69324b1 100644 --- a/src/databits_callerid.c +++ b/src/databits_callerid.c @@ -60,13 +60,13 @@ decode_mdmf_callerid( char *dataout_p, unsigned int dataout_size ) unsigned int cid_datatype = *m++; if ( cid_datatype >= CID_DATA_NAME_NA ) { // FIXME: bad datastream -- print something here - return databits_decode_callerid(0, 0, 0, 0); // reset + return 0; } unsigned int cid_datalen = *m++; if ( m + 2 + cid_datalen >= cid_buf + sizeof(cid_buf) ) { // FIXME: bad datastream -- print something here - return databits_decode_callerid(0, 0, 0, 0); // reset + return 0; } // dataout_n += sprintf(dataout_p+dataout_n, "CID: %d (%d)\n", cid_datatype, cid_datalen); @@ -119,6 +119,13 @@ decode_sdmf_callerid( char *dataout_p, unsigned int dataout_size ) return dataout_n; } +static unsigned int +decode_cid_reset() +{ + cid_msgtype = 0; + cid_ndata = 0; + return 0; +} // FIXME: doesn't respect dataout_size at all! /* returns nbytes decoded */ @@ -126,11 +133,8 @@ unsigned int databits_decode_callerid( char *dataout_p, unsigned int dataout_size, unsigned int bits, unsigned int n_databits ) { - if ( ! dataout_p ) { // databits processor reset - cid_msgtype = 0; - cid_ndata = 0; - return 0; - } + if ( ! dataout_p ) // databits processor reset + return decode_cid_reset(); if ( cid_msgtype == 0 ) { if ( bits == CID_MSG_MDMF ) @@ -145,7 +149,7 @@ databits_decode_callerid( char *dataout_p, unsigned int dataout_size, if ( cid_ndata >= sizeof(cid_buf) ) { // FIXME? buffer overflow; do what here? - return databits_decode_callerid(0, 0, 0, 0); // reset + return decode_cid_reset(); } cid_buf[cid_ndata++] = bits; @@ -173,7 +177,7 @@ databits_decode_callerid( char *dataout_p, unsigned int dataout_size, dataout_size-dataout_n); // All done; reset for the next one - databits_decode_callerid(0, 0, 0, 0); + decode_cid_reset(); return dataout_n; }