summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@inktank.com>2013-06-27 20:17:42 -0700
committerYehuda Sadeh <yehuda@inktank.com>2013-06-27 21:13:12 -0700
commit977df7781b66071e1fe056a7d9e777de7ec491ab (patch)
tree3219058a77cc8c4e6ffcd708641d455b709a3dda
parent674bbabe8502c69513c80a77473aa2fc29d48e76 (diff)
downloadceph-977df7781b66071e1fe056a7d9e777de7ec491ab.tar.gz
ceph_json: reset values
Call the default constructor if entry not found. Also, reset containers before inserting new data. Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r--src/common/ceph_json.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/common/ceph_json.h b/src/common/ceph_json.h
index 7be8ce5bca1..e11834a3371 100644
--- a/src/common/ceph_json.h
+++ b/src/common/ceph_json.h
@@ -139,6 +139,8 @@ void decode_json_obj(bufferlist& val, JSONObj *obj);
template<class T>
void decode_json_obj(list<T>& l, JSONObj *obj)
{
+ l.clear();
+
JSONObjIter iter = obj->find_first();
for (; !iter.end(); ++iter) {
@@ -152,6 +154,8 @@ void decode_json_obj(list<T>& l, JSONObj *obj)
template<class K, class V>
void decode_json_obj(map<K, V>& m, JSONObj *obj)
{
+ m.clear();
+
JSONObjIter iter = obj->find_first();
for (; !iter.end(); ++iter) {
@@ -167,6 +171,8 @@ void decode_json_obj(map<K, V>& m, JSONObj *obj)
template<class C>
void decode_json_obj(C& container, void (*cb)(C&, JSONObj *obj), JSONObj *obj)
{
+ container.clear();
+
JSONObjIter iter = obj->find_first();
for (; !iter.end(); ++iter) {
@@ -184,6 +190,7 @@ bool JSONDecoder::decode_json(const char *name, T& val, JSONObj *obj, bool manda
string s = "missing mandatory field " + string(name);
throw err(s);
}
+ val = T();
return false;
}
@@ -201,6 +208,8 @@ bool JSONDecoder::decode_json(const char *name, T& val, JSONObj *obj, bool manda
template<class C>
bool JSONDecoder::decode_json(const char *name, C& container, void (*cb)(C&, JSONObj *), JSONObj *obj, bool mandatory)
{
+ container.clear();
+
JSONObjIter iter = obj->find_first(name);
if (iter.end()) {
if (mandatory) {