From: Martin Ling Date: Sun, 25 Oct 2015 23:30:49 +0000 (+0000) Subject: C++: Catch exceptions from stoi() and stod(). X-Git-Tag: libsigrok-0.4.0~154 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4aa9a1e5698c74e2295f52313c33804761176fc1;p=libsigrok.git C++: Catch exceptions from stoi() and stod(). Fixes bug #483. --- diff --git a/bindings/cxx/ConfigKey_methods.cpp b/bindings/cxx/ConfigKey_methods.cpp index d3915610..54af62e8 100644 --- a/bindings/cxx/ConfigKey_methods.cpp +++ b/bindings/cxx/ConfigKey_methods.cpp @@ -88,7 +88,11 @@ Glib::VariantBase ConfigKey::parse_string(string value) const variant = g_variant_new_boolean(sr_parse_boolstring(value.c_str())); break; case SR_T_FLOAT: - variant = g_variant_new_double(stod(value)); + try { + variant = g_variant_new_double(stod(value)); + } catch (invalid_argument) { + throw Error(SR_ERR_ARG); + } break; case SR_T_RATIONAL_PERIOD: check(sr_parse_period(value.c_str(), &p, &q)); @@ -99,7 +103,11 @@ Glib::VariantBase ConfigKey::parse_string(string value) const variant = g_variant_new("(tt)", p, q); break; case SR_T_INT32: - variant = g_variant_new_int32(stoi(value)); + try { + variant = g_variant_new_int32(stoi(value)); + } catch (invalid_argument) { + throw Error(SR_ERR_ARG); + } break; default: throw Error(SR_ERR_BUG);