]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3068] add bigint support to the Element deserializer
authorAndrei Pavel <andrei@isc.org>
Mon, 2 Oct 2023 12:07:39 +0000 (15:07 +0300)
committerAndrei Pavel <andrei@isc.org>
Thu, 5 Oct 2023 14:40:02 +0000 (17:40 +0300)
src/lib/cc/data.cc

index 742a99b861bf2ca089326a7ae6fbc275d706875b..77dfecc1962f649aa7a5bc5e65a2ae1d2f6a0163 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 
 #include <cc/data.h>
+#include <util/bigints.h>
 
 #include <cstring>
 #include <cassert>
@@ -27,6 +28,8 @@
 
 using namespace std;
 
+using isc::util::int128_t;
+
 namespace {
 const char* const WHITESPACE = " \b\f\n\r\t";
 } // end anonymous namespace
@@ -507,21 +510,32 @@ fromStringstreamNumber(std::istream& in, const std::string& file,
     // This will move the pos to the end of the value.
     const std::string number = numberFromStringstream(in, pos);
 
+    // Is it a double?
     if (number.find_first_of(".eE") < number.size()) {
         try {
             return (Element::create(boost::lexical_cast<double>(number),
                                     Element::Position(file, line, start_pos)));
-        } catch (const boost::bad_lexical_cast&) {
-            throwJSONError(std::string("Number overflow: ") + number,
+        } catch (const boost::bad_lexical_cast& exception) {
+            throwJSONError("Number overflow while trying to cast '" + number +
+                           "' to double: " + exception.what(),
                            file, line, start_pos);
         }
-    } else {
+    }
+
+    // Is it an integer?
+    try {
+        return (Element::create(boost::lexical_cast<int64_t>(number),
+                                Element::Position(file, line, start_pos)));
+    } catch (const boost::bad_lexical_cast& exception64) {
+        // Is it a big integer?
         try {
-            return (Element::create(boost::lexical_cast<int64_t>(number),
+            return (Element::create(int128_t(number),
                                     Element::Position(file, line, start_pos)));
-        } catch (const boost::bad_lexical_cast&) {
-            throwJSONError(std::string("Number overflow: ") + number, file,
-                           line, start_pos);
+        } catch (overflow_error const& exception128) {
+            throwJSONError("Number overflow while trying to cast '" + number +
+                           "' to int64 and subsequently to int128: " +
+                           exception64.what() + ", " + exception128.what(),
+                           file, line, start_pos);
         }
     }
     return (ElementPtr());