From 6e367f54dad93b476c17b95272281e4f96f93849 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Thu, 29 Sep 2022 09:35:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=81=8D=E5=8E=86=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=88=A0=E9=99=A4=E7=AC=AC=E4=B8=80=E4=B8=AA=E5=85=83?= =?UTF-8?q?=E7=B4=A0=E5=90=8E=E4=B8=8D=E8=83=BD=E7=BB=A7=E7=BB=AD=E9=81=8D?= =?UTF-8?q?=E5=8E=86=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sane/gb_json.cpp | 20 ++++++++++++++++---- sane/gb_json.h | 3 ++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/sane/gb_json.cpp b/sane/gb_json.cpp index 264c511..10262b2 100644 --- a/sane/gb_json.cpp +++ b/sane/gb_json.cpp @@ -32,10 +32,12 @@ namespace gb json::json(char* json_txt) : obj_(0), cur_child_(0), is_array_(false) { + memset(&walk_head_, 0, sizeof(walk_head_)); attach_text(json_txt); } json::~json() { + memset(&walk_head_, 0, sizeof(walk_head_)); clear(); } @@ -100,7 +102,7 @@ namespace gb { cJSON* obj = is_array ? cJSON_CreateArray() : cJSON_CreateObject(); - bzero(obj, sizeof(*obj)); + // bzero(obj, sizeof(*obj)); // cleared in constructor already ! return obj; } @@ -571,10 +573,20 @@ namespace gb if(ele) { - //if(addr) - // *addr = ele->next; + bool cur_child = cur_child_ == obj_->child; + + if(addr) + *addr = ele->next; if (cur_child_ == ele) - cur_child_ = ele->prev; + { + if (cur_child) + { + walk_head_.next = obj_->child; + cur_child_ = &walk_head_; + } + else + cur_child_ = ele->prev; + } if (ele->prev) ele->prev->next = ele->next; if (ele->next) diff --git a/sane/gb_json.h b/sane/gb_json.h index c886364..ad44ea6 100644 --- a/sane/gb_json.h +++ b/sane/gb_json.h @@ -15,7 +15,8 @@ namespace gb class json { cJSON *obj_; - cJSON* cur_child_; + cJSON *cur_child_; + cJSON walk_head_; bool is_array_; cJSON* find_sibling(cJSON* first, const char* name, cJSON*** addr);