From e32ee4717c3503875594dc6415dbbbba89245bce Mon Sep 17 00:00:00 2001 From: YantaoZhao Date: Tue, 3 Jul 2018 21:29:18 +0800 Subject: [PATCH] allow nullptr when not care the removed array value --- include/json/value.h | 2 +- src/lib_json/json_value.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/json/value.h b/include/json/value.h index 8a0054cbf..e7a9225d3 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -562,7 +562,7 @@ Json::Value obj_value(Json::objectValue); // {} /** \brief Remove the indexed array element. O(n) expensive operations. - Update 'removed' if removed. + Update 'removed' iff removed. \return true if removed (no exceptions) */ bool removeIndex(ArrayIndex index, Value* removed); diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 01e95486a..c77d1df4d 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1243,7 +1243,8 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) { if (it == value_.map_->end()) { return false; } - *removed = it->second; + if (removed) + *removed = it->second; ArrayIndex oldSize = size(); // shift left all items left, into the place of the "removed" for (ArrayIndex i = index; i < (oldSize - 1); ++i) {