arduino / arduino/ArduinoCore-API
String::toInt() and atol() behave different on different platforms with a number that is too large.
- Lingua principale
- C++
- Stelle
- 306
- Fork
- 150
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
User axemaster found strange behavior when using String::toInt() with a number that is too large. See the topic in the Arduino forum: [https://forum.arduino.cc/t/toint-bug-how-unfortunate/1041669](https://forum.arduino.cc/t/toint-bug-how-unfortunate/1041669).
The result is different for 8-bit and 32-bit platforms.
It was narrowed down to the undefined behaviour of atol() when a number is too large to fit in a long.
The atol() in String::toInt() in String.cpp could be replaced by strtol() followed by a check for LONG_MAX or LONG_MIN and return zero if that happens. The documentation can stay as it is, because it will return a long, and zero if something is wrong.
To allow LONG_MAX and LONG_MIN as valid input numbers, the errno has to be used. I don't know how that will hold up in a multitasking environment.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Inizia in String.cpp, su String::toInt(), e verifica come si comporta atol() per i valori al di fuori dell'intervallo long della piattaforma. Confronta il strtol() proposto e la gestione di errno sulle piattaforme 8-bit e 32-bit; l'issue è completata quando gli input troppo grandi producono risultati coerenti e documentati senza gestire erroneamente LONG_MAX o LONG_MIN.
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
- 48/100