Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Koepel opened this issue Oct 14, 2022 · 0 comments
Labels

Comments

@Koepel
Copy link

Koepel commented Oct 14, 2022

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.
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.

@per1234 per1234 added the bug label Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants