]> sigrok.org Git - pulseview.git/commitdiff
device: ensure bind_enum() checks availability of Capability::LIST.
authorAurelien Jacobs <redacted>
Thu, 12 Feb 2015 14:46:42 +0000 (15:46 +0100)
committerUwe Hermann <redacted>
Fri, 13 Feb 2015 15:12:41 +0000 (16:12 +0100)
This avoids a segfault calling bind_enum() with a non-initialized gvar_list.

This closes bug #453.

pv/binding/device.cpp
pv/binding/device.hpp

index 224bc23a11079ea4593230a4637a2ff947e6886c..7547a46b341b33d3f472c2fce56812fa491fbe9c 100644 (file)
@@ -62,15 +62,10 @@ Device::Device(shared_ptr<sigrok::Configurable> configurable) :
                auto key = entry.first;
                auto capabilities = entry.second;
 
-               Glib::VariantContainerBase gvar_list;
-
                if (!capabilities.count(Capability::GET) ||
                        !capabilities.count(Capability::SET))
                        continue;
 
-               if (capabilities.count(Capability::LIST))
-                       gvar_list = configurable->config_list(key);
-
                string name_str;
                try {
                        name_str = key->description();
@@ -106,7 +101,7 @@ Device::Device(shared_ptr<sigrok::Configurable> configurable) :
                case SR_CONF_FILTER:
                case SR_CONF_COUPLING:
                case SR_CONF_CLOCK_EDGE:
-                       bind_enum(name, gvar_list, get, set);
+                       bind_enum(name, key, capabilities, get, set);
                        break;
 
                case SR_CONF_EXTERNAL_CLOCK:
@@ -115,15 +110,15 @@ Device::Device(shared_ptr<sigrok::Configurable> configurable) :
                        break;
 
                case SR_CONF_TIMEBASE:
-                       bind_enum(name, gvar_list, get, set, print_timebase);
+                       bind_enum(name, key, capabilities, get, set, print_timebase);
                        break;
 
                case SR_CONF_VDIV:
-                       bind_enum(name, gvar_list, get, set, print_vdiv);
+                       bind_enum(name, key, capabilities, get, set, print_vdiv);
                        break;
 
                case SR_CONF_VOLTAGE_THRESHOLD:
-                       bind_enum(name, gvar_list, get, set, print_voltage_threshold);
+                       bind_enum(name, key, capabilities, get, set, print_voltage_threshold);
                        break;
 
                default:
@@ -141,7 +136,8 @@ void Device::bind_bool(const QString &name,
 }
 
 void Device::bind_enum(const QString &name,
-       Glib::VariantContainerBase gvar_list, Property::Getter getter,
+       const ConfigKey *key, std::set<Capability> capabilities,
+       Property::Getter getter,
        Property::Setter setter, function<QString (Glib::VariantBase)> printer)
 {
        Glib::VariantBase gvar;
@@ -149,7 +145,10 @@ void Device::bind_enum(const QString &name,
 
        assert(configurable_);
 
-       Glib::VariantIter iter(gvar_list);
+       if (!capabilities.count(Capability::LIST))
+               return;
+
+       Glib::VariantIter iter(configurable_->config_list(key));
        while ((iter.next_value(gvar)))
                values.push_back(make_pair(gvar, printer(gvar)));
 
index a8acd1669b00f05c9356ea1faff93dadebbd101e..7dfe02465322b4c5a8c718724bf302922e52783d 100644 (file)
@@ -30,9 +30,7 @@
 
 #include <pv/prop/property.hpp>
 
-namespace sigrok {
-       class Configurable;
-}
+#include <libsigrokcxx/libsigrokcxx.hpp>
 
 namespace pv {
 
@@ -51,7 +49,8 @@ Q_SIGNALS:
 private:
        void bind_bool(const QString &name,
                prop::Property::Getter getter, prop::Property::Setter setter);
-       void bind_enum(const QString &name, Glib::VariantContainerBase gvar_list,
+       void bind_enum(const QString &name,
+               const sigrok::ConfigKey *key, std::set<sigrok::Capability> capabilities,
                prop::Property::Getter getter, prop::Property::Setter setter,
                std::function<QString (Glib::VariantBase)> printer = print_gvariant);
        void bind_int(const QString &name, QString suffix,