diff --git a/src/libutil/config.cc b/src/libutil/config.cc index 893cdccce..c05a3253b 100644 --- a/src/libutil/config.cc +++ b/src/libutil/config.cc @@ -74,17 +74,25 @@ template<> std::string Setting::to_string() return value; } -template<> void Setting::set(const std::string & str) +template +void Setting::set(const std::string & str) { + static_assert(std::is_integral::value, "Integer required."); try { - value = std::stoi(str); - } catch (...) { + auto i = std::stoll(str); + if (i < std::numeric_limits::min() || + i > std::numeric_limits::max()) + throw UsageError("setting '%s' has out-of-range value %d", name, i); + value = i; + } catch (std::logic_error&) { throw UsageError("setting '%s' has invalid value '%s'", name, str); } } -template<> std::string Setting::to_string() +template +std::string Setting::to_string() { + static_assert(std::is_integral::value, "Integer required."); return std::to_string(value); } @@ -103,6 +111,11 @@ template<> std::string Setting::to_string() return value ? "true" : "false"; } +template class Setting; +template class Setting; +template class Setting; +template class Setting; + void PathSetting::set(const std::string & str) { if (str == "") {