mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-07 16:23:38 +03:00
Fix for 32bit long used in long long printNumber.
This commit is contained in:
parent
7e1d891e84
commit
8c725d5736
@ -270,17 +270,18 @@ size_t Print::println(const Printable& x) {
|
|||||||
// Private Methods /////////////////////////////////////////////////////////////
|
// Private Methods /////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
size_t Print::printNumber(unsigned long n, uint8_t base) {
|
size_t Print::printNumber(unsigned long n, uint8_t base) {
|
||||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
char buf[8 * sizeof(n) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||||
char *str = &buf[sizeof(buf) - 1];
|
char *str = &buf[sizeof(buf) - 1];
|
||||||
|
|
||||||
*str = '\0';
|
*str = '\0';
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if(base < 2)
|
if(base < 2) {
|
||||||
base = 10;
|
base = 10;
|
||||||
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
unsigned long m = n;
|
auto m = n;
|
||||||
n /= base;
|
n /= base;
|
||||||
char c = m - base * n;
|
char c = m - base * n;
|
||||||
|
|
||||||
@ -291,17 +292,18 @@ size_t Print::printNumber(unsigned long n, uint8_t base) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printNumber(unsigned long long n, uint8_t base) {
|
size_t Print::printNumber(unsigned long long n, uint8_t base) {
|
||||||
char buf[8 * sizeof(long long) + 1]; // Assumes 8-bit chars plus zero byte.
|
char buf[8 * sizeof(n) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||||
char* str = &buf[sizeof(buf) - 1];
|
char* str = &buf[sizeof(buf) - 1];
|
||||||
|
|
||||||
*str = '\0';
|
*str = '\0';
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2) {
|
||||||
base = 10;
|
base = 10;
|
||||||
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
unsigned long m = n;
|
auto m = n;
|
||||||
n /= base;
|
n /= base;
|
||||||
char c = m - base * n;
|
char c = m - base * n;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user