From be225ca1b627eb4dfc1c2e718f3f392695baeb22 Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Sun, 3 Oct 2010 12:30:21 +0200 Subject: 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 */ Signed-off-by: Martin Szulecki --- src/Dictionary.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); } -- cgit v1.1-32-gdbae