From: Yehuda Sadeh Date: Fri, 28 Jun 2013 03:17:42 +0000 (-0700) Subject: ceph_json: reset values X-Git-Tag: v0.67-rc1~128^2~28 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=977df7781b66071e1fe056a7d9e777de7ec491ab;p=ceph.git ceph_json: reset values Call the default constructor if entry not found. Also, reset containers before inserting new data. Signed-off-by: Yehuda Sadeh --- diff --git a/src/common/ceph_json.h b/src/common/ceph_json.h index 7be8ce5bca1c..e11834a3371e 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 void decode_json_obj(list& l, JSONObj *obj) { + l.clear(); + JSONObjIter iter = obj->find_first(); for (; !iter.end(); ++iter) { @@ -152,6 +154,8 @@ void decode_json_obj(list& l, JSONObj *obj) template void decode_json_obj(map& m, JSONObj *obj) { + m.clear(); + JSONObjIter iter = obj->find_first(); for (; !iter.end(); ++iter) { @@ -167,6 +171,8 @@ void decode_json_obj(map& m, JSONObj *obj) template 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 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) {