arduino / arduino/ArduinoCore-API

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

Aperta
#161 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C++
Stelle
306
Fork
150
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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;
}
}
```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Individua l'implementazione di String in C++11 ed esamina move(), operator=, il costruttore String(String &&rval) e il comportamento di reserve(). Verifica come si comporta una destinazione con memoria riservata durante uno spostamento, quindi conferma che il costruttore segue il percorso di spostamento previsto e che le stringhe sottoposte a spostamento rimangono valide.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp
Ambito
embedded-iot
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.