arduino / arduino/ArduinoCore-API

String move() and String(String &&rval) breaks operation of reserve()

未关闭
#161 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
C++
星标
306
派生
150
PR 合并指标
30 天内没有已合并 PR

描述

When #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
operator = uses move() to just update the buffer pointer of the destination
This ignores any reserve() the user has made to ensure the memory is not unnecessarily fragmented.
String(String &&rval) has a similar problem

move() should first check the capacity of the destination and if there is sufficient space copy the source to the destination
String(String &&rval) should use move()

A suggested move() is

```
void String::move(String &rhs) {
if (this != &rhs) {
if (capacity > rhs.size) {
copy(rhs.buffer,rhs.size);
} else {
free(buffer);
buffer = rhs.buffer;
len = rhs.len;
capacity = rhs.capacity;
}
rhs.buffer = NULL;
rhs.len = 0;
rhs.capacity = 0;
}
}
```

贡献指南

这个仓库没有索引到贡献指南

调研方向

找到 C++11 String 实现,并检查 move()、operator=、String(String &&rval) 构造函数以及 reserve() 的行为。验证 reserved destination 在 move 期间的行为,然后确认构造函数遵循预期的 move path,并且 moved-from strings 仍保持有效。

由索引模型根据 Issue 内容生成。

评估

技术栈
cpp
领域
embedded-iot
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。