From bd454e27e1fe98b2525ab6d84406f42a31cd9803 Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Sun, 3 Oct 2010 12:30:21 +0200 Subject: [PATCH] Fix Dictionary copy constructor While iterating over all the keys stored in the source Dictionary to copy them to create the copied Dictonary, the name of the key being copied was only set to a non-NULL value for the first key we copy. This was then leading to an assertion when trying to create a std::string from a NULL pointer. Simple test-case: int main() { PList::Dictionary a; PList::String b("Hello"); PList::String c("Hi!"); PList::Dictionary d; a.Insert("Key", &b); a.Insert("Another Key", &c); std::cout << a.ToXml() << std::endl; d.Insert("dictionary", &a); //CRAAAAAAAAASH! std::cout << d.ToXml() << std::endl; return 0; } /* Output: Key Hello Another Key Hi! terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_S_construct NULL not valid */ --- src/Dictionary.cpp | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/Dictionary.cpp b/src/Dictionary.cpp index d4aac2e..0030df6 100644 --- a/src/Dictionary.cpp +++ b/src/Dictionary.cpp @@ -72,7 +72,7 @@ Dictionary::Dictionary(PList::Dictionary& d) : Structure() subnode = NULL; free(key); key = NULL; - plist_dict_next_item(_node, it, NULL, &subnode); + plist_dict_next_item(_node, it, &key, &subnode); } free(it); } -- 1.7.1