aboutsummaryrefslogtreecommitdiffstats
path: root/src/librtlsdr.c
diff options
context:
space:
mode:
authorSteve Markgraf <steve@steve-m.de>2013-01-02 20:19:19 +0100
committerSteve Markgraf <steve@steve-m.de>2013-01-02 20:19:19 +0100
commit4b057fea0f05ea8aa8e963ea2fcfc23f2f349477 (patch)
tree877cf7904fb437fce2569c79dcde744c9ed3708d /src/librtlsdr.c
parent314683a51ee227e09f8e55af2cf77e15f960e5e5 (diff)
rtlsdr_set_sample_rate(): don't access dev structure before checking for NULL
Thanks to Derek Lieber for reporting this bug. Signed-off-by: Steve Markgraf <steve@steve-m.de>
Diffstat (limited to 'src/librtlsdr.c')
-rw-r--r--src/librtlsdr.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/librtlsdr.c b/src/librtlsdr.c
index 0e39fd9..cb1f3bc 100644
--- a/src/librtlsdr.c
+++ b/src/librtlsdr.c
@@ -965,7 +965,6 @@ int rtlsdr_set_sample_rate(rtlsdr_dev_t *dev, uint32_t samp_rate)
uint16_t tmp;
uint32_t rsamp_ratio;
double real_rate;
- uint32_t rtl_freq = dev->rtl_xtal;
if (!dev)
return -1;
@@ -974,10 +973,10 @@ int rtlsdr_set_sample_rate(rtlsdr_dev_t *dev, uint32_t samp_rate)
if (samp_rate > MAX_SAMP_RATE)
samp_rate = MAX_SAMP_RATE;
- rsamp_ratio = (rtl_freq * TWO_POW(22)) / samp_rate;
+ rsamp_ratio = (dev->rtl_xtal * TWO_POW(22)) / samp_rate;
rsamp_ratio &= ~3;
- real_rate = (rtl_freq * TWO_POW(22)) / rsamp_ratio;
+ real_rate = (dev->rtl_xtal * TWO_POW(22)) / rsamp_ratio;
if ( ((double)samp_rate) != real_rate )
fprintf(stderr, "Exact sample rate is: %f Hz\n", real_rate);