Fix for segfault-on-NaN problem
authorbaobrien <baobrien@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 17 Sep 2017 21:36:23 +0000 (21:36 +0000)
committerbaobrien <baobrien@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 17 Sep 2017 21:36:23 +0000 (21:36 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3367 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/fsk.c

index 86d4fb7a5476dd8cca1a7d100adcd72473a4ef40..62ad98bdc5b24067941fb53f5e56d1d5c165bad8 100644 (file)
@@ -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<nsym; i++){
         int st = (i+1)*P;
         for( m=0; m<M; m++){
-            //fprintf(stderr,"%d %d\n",m,M);
-            //fprintf(stderr,"%d %d %d\n",st,low_sample,high_sample);
             t[m] =           fcmult(1-fract,f_int[m][st+ low_sample]);
             t[m] = cadd(t[m],fcmult(  fract,f_int[m][st+high_sample]));
             /* Figure mag^2 of each resampled fx_int */