Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Don't lookup twice.
[simgrid.git] / src / xbt / config.cpp
index 5a9cb8d74abd232002cb3cd824263754884dffa1..c698602c41993cae28e77cff53af252723d09303 100644 (file)
@@ -99,7 +99,12 @@ public:
   static constexpr const char* type_name = "int";
   static inline int parse(const char* value)
   {
-    return parse_long(value);
+    long val = parse_long(value);
+    if (val < INT_MIN)
+      throw std::range_error("underflow");
+    if (val > INT_MAX)
+      throw std::range_error("overflow");
+    return static_cast<int>(val);
   }
 };
 template <> class ConfigType<double> {
@@ -184,7 +189,7 @@ public:
   TypedConfigurationElement(const std::string& key, const std::string& desc, T value, std::function<void(T&)> callback)
       : ConfigurationElement(key, desc), content(std::move(value)), callback(std::move(callback))
   {}
-  ~TypedConfigurationElement() = default;
+  ~TypedConfigurationElement() override = default;
 
   std::string get_string_value() override;
   const char* get_type_name() override;
@@ -260,7 +265,7 @@ public:
   {
     xbt_assert(options.find(name) == options.end(), "Refusing to register the config element '%s' twice.",
                name.c_str());
-    TypedConfigurationElement<T>* variable = new TypedConfigurationElement<T>(name, std::forward<A>(a)...);
+    auto* variable = new TypedConfigurationElement<T>(name, std::forward<A>(a)...);
     XBT_DEBUG("Register cfg elm %s (%s) of type %s @%p in set %p)", name.c_str(), variable->get_description().c_str(),
               variable->get_type_name(), variable, this);
     options[name].reset(variable);