[PATCH] Fix a segfault in soapy_source_c

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/osmocom-sdr@lists.osmocom.org/.

Vasil Velichkov vvvelichkov at gmail.com
Thu Oct 5 15:54:01 UTC 2017


When the get_gain_names(chan) returns an empty vector calls
set_gain(gain, chan) instead of set_gain(gain, names.front(), chan);

 (gdb) bt
 #0  std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string (__str=..., this=0x7fffffffdb10)
     at /usr/include/c++/7/bits/basic_string.h:424
 #1  soapy_source_c::set_if_gain (this=0x555556b85250, gain=32, chan=0) at ./lib/soapy/soapy_source_c.cc:257
 #2  0x00007fffdf0b82a4 in source_impl::set_if_gain (this=0x555555bb6f30, gain=32, chan=<optimized out>) at ./lib/source_impl.cc:708
 #3  0x00007fffdf3a860d in _wrap_source_sptr_set_if_gain (args=<optimized out>, kwargs=<optimized out>)
     at ./obj-x86_64-linux-gnu/swig/osmosdr_swigPYTHON_wrap.cxx:23069
 #4  0x000055555564f3ca in call_function (oparg=<optimized out>, pp_stack=0x7fffffffdd10) at ../Python/ceval.c:4352
---
 lib/soapy/soapy_source_c.cc | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/lib/soapy/soapy_source_c.cc b/lib/soapy/soapy_source_c.cc
index a645361..e9e7377 100644
--- a/lib/soapy/soapy_source_c.cc
+++ b/lib/soapy/soapy_source_c.cc
@@ -253,16 +253,24 @@ double soapy_source_c::get_gain( const std::string & name, size_t chan )
 
 double soapy_source_c::set_if_gain( double gain, size_t chan )
 {
-    //docs specify RF gain is the first element
-    const std::string name = this->get_gain_names(chan).front();
-    return this->set_gain(gain, name, chan);
+    std::vector<std::string> names = this->get_gain_names(chan);
+    if (names.length()) {
+        //docs specify RF gain is the first element
+        return this->set_gain(gain, names.front(), chan);
+    } else {
+        return this->set_gain(gain, chan);
+    }
 }
 
 double soapy_source_c::set_bb_gain( double gain, size_t chan )
 {
-    //docs specify baseband gain is the last element
-    const std::string name = this->get_gain_names(chan).back();
-    return this->set_gain(gain, name, chan);
+    std::vector<std::string> names =this->get_gain_names(chan);
+    if (names.length()) {
+        //docs specify baseband gain is the last element
+        return this->set_gain(gain, names.back(), chan);
+    } else {
+        return this->set_gain(gain, chan);
+    }
 }
 
 std::vector< std::string > soapy_source_c::get_antennas( size_t chan )
-- 
2.13.6




More information about the osmocom-sdr mailing list