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