]> Dogcows Code - chaz/yoink/blobdiff - src/deserializer.cc
fixed yajl-related deserialization crash
[chaz/yoink] / src / deserializer.cc
index 4c3f8f2caab6a69cc049dc5e79affd8341c04cf6..929c3c12183fdf3c5f10ccee3cbb6e09a7a065ea 100644 (file)
@@ -38,7 +38,7 @@
 namespace dc {
 
 
-class deserializer_impl
+class deserializer::deserializer_impl
 {
 public:
        deserializer_impl(const std::string& filePath, bool comments = false,
@@ -72,9 +72,9 @@ public:
        void throwError()
        {
                unsigned char* errorMsg = yajl_get_error(hand, 0, 0, 0);
-               deserializer::exception error((char*)errorMsg);
+               deserializer::exception problem((char*)errorMsg);
                yajl_free_error(hand, errorMsg);
-               throw error;
+               throw problem;
        }
 
 
@@ -114,11 +114,13 @@ public:
        static int parsedBeginMap(void* ctx)
        {
                ((deserializer_impl*)ctx)->parsed.push(new wrapped_dictionary);
+               return 1;
        }
 
        static int parsedMapKey(void* ctx, const unsigned char* value,
                        unsigned length)
        {
+               // same thing as a string
                return parsedString(ctx, value, length);
        }
 
@@ -180,7 +182,9 @@ public:
 private:
        void init(std::istream& input, bool deleteIn, bool comments, bool check)
        {
-               const yajl_callbacks callbacks =
+               // this has to be static because yajl actually does not copy it into its
+               // internal data structures but rather keeps a pointer to this
+               static const yajl_callbacks callbacks =
                {
                        deserializer_impl::parsedNull,
                        deserializer_impl::parsedBoolean,
@@ -205,10 +209,13 @@ private:
 
 
 deserializer::deserializer(const std::string& filePath, bool comments,
-               bool check) : impl(new deserializer_impl(filePath, comments, check)) {}
+               bool check) :
+       // pass through
+       impl(new deserializer::deserializer_impl(filePath, comments, check)) {}
 
 deserializer::deserializer(std::istream& input, bool comments, bool check) :
-               impl(new deserializer_impl(input, comments, check)) {}
+       // pass through
+       impl(new deserializer::deserializer_impl(input, comments, check)) {}
 
 
 serializable_ptr deserializer::deserialize()
@@ -235,9 +242,12 @@ serializable* deserializer::pullNext()
 
 void deserializer::pop()
 {
+       // pass through
        impl->parsed.pop();
 }
 
 
 } // namespace dc
 
+/** vim: set ts=4 sw=4 tw=80: *************************************************/
+
This page took 0.018426 seconds and 4 git commands to generate.