arduino / arduino/ArduinoCore-API

String::toInt() and atol() behave different on different platforms with a number that is too large.

Abierto
#175 0 comentarios 0 reacciones 0 asignados Ver en GitHub
bug
Lenguaje dominante
C++
Estrellas
306
Forks
150
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Comienza en String.cpp, en String::toInt(), y revisa cómo se comporta atol() con valores fuera del rango long de la plataforma. Compara el strtol() propuesto y el manejo de errno en plataformas de 8-bit y 32-bit; el issue estará terminado cuando las entradas sobredimensionadas produzcan resultados documentados y coherentes sin tratar incorrectamente LONG_MAX o LONG_MIN.

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
48/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.