arduino / arduino/ArduinoCore-API
String::toInt() and atol() behave different on different platforms with a number that is too large.
- 主要语言
- C++
- 星标
- 306
- 派生
- 150
- PR 合并指标
- 30 天内没有已合并 PR
描述
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.
贡献指南
这个仓库没有索引到贡献指南
调研方向
从 String.cpp 中的 String::toInt() 开始,检查 atol() 对超出平台 long 范围的值的行为。在 8-bit 和 32-bit 平台之间比较提议的 strtol() 及 errno 处理方式;当超大输入能够产生一致且有文档说明的结果,并且不会错误处理 LONG_MAX 或 LONG_MIN 时,该 issue 即完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- cpp
- 领域
- embedded-iot
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100