]> sigrok.org Git - libsigrok.git/commitdiff
C++: Fix segfault where input/output options are NULL.
authorMartin Ling <redacted>
Sun, 18 Jan 2015 22:43:02 +0000 (22:43 +0000)
committerMartin Ling <redacted>
Sun, 18 Jan 2015 22:43:02 +0000 (22:43 +0000)
bindings/cxx/classes.cpp

index 9dc003acae70ac863776b3a8be5c9273b59513f9..bb709fe2613092a2a78c2ff7af7810ec4204b95c 100644 (file)
@@ -1388,12 +1388,15 @@ string InputFormat::description()
 map<string, shared_ptr<Option>> InputFormat::options()
 {
        const struct sr_option **options = sr_input_options_get(_structure);
-       auto option_array = shared_ptr<const struct sr_option *>(
-               options, sr_input_options_free);
        map<string, shared_ptr<Option>> result;
-       for (int i = 0; options[i]; i++)
-               result[options[i]->id] = shared_ptr<Option>(
-                       new Option(options[i], option_array), Option::Deleter());
+       if (options)
+       {
+               auto option_array = shared_ptr<const struct sr_option *>(
+                       options, sr_input_options_free);
+               for (int i = 0; options[i]; i++)
+                       result[options[i]->id] = shared_ptr<Option>(
+                               new Option(options[i], option_array), Option::Deleter());
+       }
        return result;
 }
 
@@ -1525,12 +1528,15 @@ string OutputFormat::description()
 map<string, shared_ptr<Option>> OutputFormat::options()
 {
        const struct sr_option **options = sr_output_options_get(_structure);
-       auto option_array = shared_ptr<const struct sr_option *>(
-               options, sr_output_options_free);
        map<string, shared_ptr<Option>> result;
-       for (int i = 0; options[i]; i++)
-               result[options[i]->id] = shared_ptr<Option>(
-                       new Option(options[i], option_array), Option::Deleter());
+       if (options)
+       {
+               auto option_array = shared_ptr<const struct sr_option *>(
+                       options, sr_output_options_free);
+               for (int i = 0; options[i]; i++)
+                       result[options[i]->id] = shared_ptr<Option>(
+                               new Option(options[i], option_array), Option::Deleter());
+       }
        return result;
 }