arduino / arduino/ArduinoCore-API
String::toInt() and atol() behave different on different platforms with a number that is too large.
- Ngôn ngữ chính
- C++
- Star
- 306
- Fork
- 150
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
Bắt đầu trong String.cpp tại String::toInt() và xem xét cách atol() hoạt động với các giá trị nằm ngoài phạm vi long của nền tảng. So sánh strtol() được đề xuất và cách xử lý errno trên các nền tảng 8-bit và 32-bit; issue được hoàn tất khi các đầu vào vượt quá phạm vi tạo ra kết quả nhất quán, có tài liệu mà không xử lý sai LONG_MAX hoặc LONG_MIN.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- cpp
- Lĩnh vực
- embedded-iot
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 48/100