1 Star 0 Fork 36

chendexi/boost

forked from src-openEuler/boost 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
boost-1.79-json-array-erase-relocate.patch 1.49 KB
一键复制 编辑 原始数据 按行查看 历史
Liu Zixian 提交于 2022-04-16 23:55 . Update to 1.79.0
From 07d7c3b2e0f8c6b269ba167117cd3e549df2f342 Mon Sep 17 00:00:00 2001
From: Vinnie Falco <[email protected]>
Date: Wed, 13 Apr 2022 05:49:05 -0700
Subject: [PATCH] array::erase relocates correctly
fix #692
---
boost/json/impl/array.ipp | 5 ++++-
libs/json/test/array.cpp | 16 ++++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/boost/json/impl/array.ipp b/boost/json/impl/array.ipp
index 4d067fb5..a2c7fd6d 100644
--- a/boost/json/impl/array.ipp
+++ b/boost/json/impl/array.ipp
@@ -491,8 +491,11 @@ erase(
auto const p = &(*t_)[0] +
(pos - &(*t_)[0]);
destroy(p, p + 1);
- relocate(p, p + 1, 1);
--t_->size;
+ if(t_->size > 0)
+ relocate(p, p + 1,
+ t_->size - (p -
+ &(*t_)[0]));
return p;
}
diff --git a/libs/json/test/array.cpp b/libs/json/test/array.cpp
index 1cc87566..4516cc78 100644
--- a/libs/json/test/array.cpp
+++ b/libs/json/test/array.cpp
@@ -1269,6 +1269,21 @@ class array_test
array{nullptr, "a", "b"}));
}
+ void
+ testIssue692()
+ {
+ array a;
+ object obj;
+ obj["test1"] = "hello";
+ a.push_back(obj);
+ a.push_back(obj);
+ a.push_back(obj);
+ a.push_back(obj);
+ a.push_back(obj);
+ while(a.size())
+ a.erase(a.begin());
+ }
+
void
run()
{
@@ -1283,6 +1298,7 @@ class array_test
testExceptions();
testEquality();
testHash();
+ testIssue692();
}
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ccdxx/boost.git
[email protected]:ccdxx/boost.git
ccdxx
boost
boost
master

搜索帮助