From f9f4c54bc3074aa24c0a0902f02f1281db4fd17b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Sat, 27 Aug 2016 10:54:35 +0200 Subject: [PATCH] fixed GH #1355: [JSON::Object] After copy-ctor, JSON::Object::_keys still points to keys in map of copied object --- JSON/include/Poco/JSON/Object.h | 13 +++++++++++++ JSON/src/Object.cpp | 11 ++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/JSON/include/Poco/JSON/Object.h b/JSON/include/Poco/JSON/Object.h index f4be10fb2..69920dc55 100644 --- a/JSON/include/Poco/JSON/Object.h +++ b/JSON/include/Poco/JSON/Object.h @@ -303,6 +303,19 @@ inline std::size_t Object::size() const inline void Object::remove(const std::string& key) { _values.erase(key); + if (_preserveInsOrder) + { + KeyPtrList::iterator it = _keys.begin(); + KeyPtrList::iterator end = _keys.end(); + for (; it != end; ++it) + { + if (key == **it) + { + _keys.erase(it); + break; + } + } + } } diff --git a/JSON/src/Object.cpp b/JSON/src/Object.cpp index f55be8149..d81fa3e81 100644 --- a/JSON/src/Object.cpp +++ b/JSON/src/Object.cpp @@ -32,10 +32,19 @@ Object::Object(bool preserveInsertionOrder): _preserveInsOrder(preserveInsertion Object::Object(const Object& copy) : _values(copy._values), - _keys(copy._keys), _preserveInsOrder(copy._preserveInsOrder), _pStruct(0) { + if (_preserveInsOrder) + { + // need to update pointers in _keys to point to copied _values + for (KeyPtrList::const_iterator it = copy._keys.begin(); it != copy._keys.end(); ++it) + { + ValueMap::const_iterator itv = _values.find(**it); + poco_assert (itv != _values.end()); + _keys.push_back(&itv->first); + } + } }