arduino / arduino/ArduinoCore-API

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

オープン
#161 コメント 4 件 リアクション 0 件 担当者 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() の動作を調べてください。move 中に reserve 済みの destination がどのように動作するかを検証し、そのうえでコンストラクターが意図された move path に従うこと、および moved-from string が有効なままであることを確認してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
cpp
領域
embedded-iot
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。