From eb1e2af188dade737d3d566a3b416f15a02aac53 Mon Sep 17 00:00:00 2001 From: baobrien Date: Sun, 17 Sep 2017 21:36:23 +0000 Subject: [PATCH] Fix for segfault-on-NaN problem git-svn-id: https://svn.code.sf.net/p/freetel/code@3367 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/src/fsk.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/codec2-dev/src/fsk.c b/codec2-dev/src/fsk.c index 86d4fb7a..62ad98bd 100644 --- a/codec2-dev/src/fsk.c +++ b/codec2-dev/src/fsk.c @@ -828,7 +828,13 @@ void fsk2_demod(struct FSK *fsk, uint8_t rx_bits[], float rx_sd[], COMP fsk_in[] /* Spin the oscillator for the magic line shift */ phi_ft = cmult(phi_ft,dphift); } - //fprintf(stderr,"t_c: %f+%f i\n",t_c.real,t_c.imag); + + /* Check for NaNs in the fine timing estimate, return if found */ + /* otherwise segfaults happen */ + if( isnan(t_c.real) || isnan(t_c.imag)){ + return; + } + /* Get the magic angle */ norm_rx_timing = atan2f(t_c.imag,t_c.real)/(2*M_PI); rx_timing = norm_rx_timing*(float)P; @@ -863,8 +869,6 @@ void fsk2_demod(struct FSK *fsk, uint8_t rx_bits[], float rx_sd[], COMP fsk_in[] int low_sample = (int)floorf(rx_timing); float fract = rx_timing - (float)low_sample; int high_sample = (int)ceilf(rx_timing); - - //fprintf(stderr,"rx_timing: %f %f\n",rx_timing,fract); /* Vars for finding the max-of-4 for each bit */ float tmax[M]; @@ -879,8 +883,6 @@ void fsk2_demod(struct FSK *fsk, uint8_t rx_bits[], float rx_sd[], COMP fsk_in[] for(i=0; i