rtl_fm: bugs found by Axiomatic, alkw0ia and cgommer

Signed-off-by: Steve Markgraf <steve@steve-m.de>
master
Kyle Keen 12 years ago committed by Steve Markgraf
parent 0c3c356d19
commit c792c4aeac
  1. 8
      src/rtl_fm.c

@ -187,10 +187,10 @@ void build_fir(struct fm_state *fm)
{ {
int i, len; int i, len;
len = fm->downsample; len = fm->downsample;
for(i = 0; i < len; i++) { for(i = 0; i < (len/2); i++) {
fm->fir[i] = i; fm->fir[i] = i;
} }
for(i = len-1; i <= 0; i--) { for(i = len-1; i >= (len/2); i--) {
fm->fir[i] = len - i; fm->fir[i] = len - i;
} }
fm->fir_sum = 0; fm->fir_sum = 0;
@ -311,6 +311,8 @@ int mad(int *samples, int len, int step)
/* mean average deviation */ /* mean average deviation */
{ {
int i=0, sum=0, ave=0; int i=0, sum=0, ave=0;
if (len == 0)
{return 0;}
for (i=0; i<len; i+=step) { for (i=0; i<len; i+=step) {
sum += samples[i]; sum += samples[i];
} }
@ -319,7 +321,7 @@ int mad(int *samples, int len, int step)
for (i=0; i<len; i+=step) { for (i=0; i<len; i+=step) {
sum += abs(samples[i] - ave); sum += abs(samples[i] - ave);
} }
return sum / (len * step); return sum / (len / step);
} }
int post_squelch(struct fm_state *fm) int post_squelch(struct fm_state *fm)

Loading…
Cancel
Save