arduino / arduino/ArduinoCore-API
String move() and String(String &&rval) breaks operation of reserve()
- Ngôn ngữ chính
- C++
- Star
- 306
- Fork
- 150
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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;
}
}
```
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
Tìm triển khai String của C++11 và kiểm tra move(), operator=, hàm dựng String(String &&rval) và hành vi của reserve(). Xác minh destination đã reserve hoạt động như thế nào trong quá trình move, sau đó xác nhận rằng hàm dựng tuân theo move path dự kiến và các string moved-from vẫn hợp lệ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- cpp
- Lĩnh vực
- embedded-iot
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100