C++: Fix segfault where input/output options are NULL.

This commit is contained in:
Martin Ling 2015-01-18 22:43:02 +00:00
parent 718a9d382f
commit 48d92e2c2e
1 changed files with 16 additions and 10 deletions

View File

@ -1388,12 +1388,15 @@ string InputFormat::description()
map<string, shared_ptr<Option>> InputFormat::options() map<string, shared_ptr<Option>> InputFormat::options()
{ {
const struct sr_option **options = sr_input_options_get(_structure); 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; map<string, shared_ptr<Option>> result;
for (int i = 0; options[i]; i++) if (options)
result[options[i]->id] = shared_ptr<Option>( {
new Option(options[i], option_array), Option::Deleter()); 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; return result;
} }
@ -1525,12 +1528,15 @@ string OutputFormat::description()
map<string, shared_ptr<Option>> OutputFormat::options() map<string, shared_ptr<Option>> OutputFormat::options()
{ {
const struct sr_option **options = sr_output_options_get(_structure); 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; map<string, shared_ptr<Option>> result;
for (int i = 0; options[i]; i++) if (options)
result[options[i]->id] = shared_ptr<Option>( {
new Option(options[i], option_array), Option::Deleter()); 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; return result;
} }