]> sigrok.org Git - libsigrok.git/commitdiff
C++: Catch exceptions from stoi() and stod().
authorMartin Ling <redacted>
Sun, 25 Oct 2015 23:30:49 +0000 (23:30 +0000)
committerDaniel Elstner <redacted>
Mon, 26 Oct 2015 06:17:50 +0000 (07:17 +0100)
Fixes bug #483.

bindings/cxx/ConfigKey_methods.cpp

index d391561047f32e234d9c9eb9200e575418ff873d..54af62e804e76f2d8b3c7c0d628b9e17cc3a747c 100644 (file)
@@ -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);