Commit 5811cdf7 authored by Dominik Charousset's avatar Dominik Charousset

Fix possible segfault when parsing .ini files

parent c9234ddb
......@@ -60,6 +60,9 @@ public:
return explanation_;
}
/// Returns the full name for this config option as "<category>.<long name>".
std::string full_name() const;
/// Returns the held value as string.
virtual std::string to_string() const = 0;
......
......@@ -43,16 +43,8 @@ public:
}
void add_opts(options_vector& xs) {
for (auto& x : xs) {
std::string key = x->category();
key += '.';
// name can have format "<long>,<short>"; consider only long name
auto name_begin = x->name();
const char* name_end = strchr(x->name(), ',');
key.insert(key.end(), name_begin, name_end);
//key += x->name();
sinks_.emplace(std::move(key), x->to_sink());
}
for (auto& x : xs)
sinks_.emplace(x->full_name(), x->to_sink());
}
void operator()(size_t ln, std::string name, config_value& cv) {
......
......@@ -43,6 +43,18 @@ config_option::~config_option() {
// nop
}
std::string config_option::full_name() const {
std::string res = category();
res += '.';
auto name_begin = name();
const char* name_end = strchr(name(), ',');
if (name_end)
res.insert(res.end(), name_begin, name_end);
else
res += name();
return res;
}
const char* config_option::type_name_visitor::operator()(const std::string&) const {
return "a string";
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment