arduino / arduino/ArduinoCore-API
String move() and String(String &&rval) breaks operation of reserve()
- Lenguaje dominante
- C++
- Estrellas
- 306
- Forks
- 150
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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;
}
}
```
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Localiza la implementación de String de C++11 e inspecciona move(), operator=, el constructor String(String &&rval) y el comportamiento de reserve(). Verifica cómo se comporta un destino con reserva durante un movimiento y, a continuación, confirma que el constructor sigue la ruta de movimiento prevista y que los strings movidos permanecen en un estado válido.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- cpp
- Área
- embedded-iot
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100