]> granicus.if.org Git - icinga2/commitdiff
Throw saved exception in JSON decoder
authorGunnar Beutner <gunnar@beutner.name>
Mon, 27 Oct 2014 08:28:32 +0000 (09:28 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 27 Oct 2014 08:28:32 +0000 (09:28 +0100)
refs #7452

lib/base/json.cpp

index 6bcf0934331d23cd99e59f31ab800578a4f12479..318b4e24f4faabcffb58d3179f2575058863b7bc 100644 (file)
@@ -177,7 +177,8 @@ public:
 
        void ThrowException(void) const
        {
-               boost::rethrow_exception(m_Exception);
+               if (m_Exception)
+                       boost::rethrow_exception(m_Exception);
        }
 
 private:
@@ -234,7 +235,7 @@ static int DecodeString(void *ctx, const unsigned char *str, size_t len)
        JsonContext *context = static_cast<JsonContext *>(ctx);
 
        try {
-               context->AddValue(String(reinterpret_cast<const char *>(str), reinterpret_cast<const char *>(str) + len));
+               context->AddValue(String(str, str + len));
        } catch (...) {
                context->SaveException();
                return 0;
@@ -329,6 +330,9 @@ Value icinga::JsonDecode(const String& data)
 
                yajl_free(handle);
 
+               /* throw saved exception (if there is one) */
+               context.ThrowException();
+
                BOOST_THROW_EXCEPTION(std::invalid_argument(msg));
        }