Skip to content

Commit 8c725d5

Browse files
committed
Fix for 32bit long used in long long printNumber.
1 parent 7e1d891 commit 8c725d5

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

cores/esp8266/Print.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -270,43 +270,45 @@ size_t Print::println(const Printable& x) {
270270
// Private Methods /////////////////////////////////////////////////////////////
271271

272272
size_t Print::printNumber(unsigned long n, uint8_t base) {
273-
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
273+
char buf[8 * sizeof(n) + 1]; // Assumes 8-bit chars plus zero byte.
274274
char *str = &buf[sizeof(buf) - 1];
275275

276276
*str = '\0';
277277

278278
// prevent crash if called with base == 1
279-
if(base < 2)
279+
if(base < 2) {
280280
base = 10;
281+
}
281282

282283
do {
283-
unsigned long m = n;
284+
auto m = n;
284285
n /= base;
285286
char c = m - base * n;
286287

287288
*--str = c < 10 ? c + '0' : c + 'A' - 10;
288-
} while(n);
289+
} while (n);
289290

290291
return write(str);
291292
}
292293

293294
size_t Print::printNumber(unsigned long long n, uint8_t base) {
294-
char buf[8 * sizeof(long long) + 1]; // Assumes 8-bit chars plus zero byte.
295+
char buf[8 * sizeof(n) + 1]; // Assumes 8-bit chars plus zero byte.
295296
char* str = &buf[sizeof(buf) - 1];
296297

297298
*str = '\0';
298299

299300
// prevent crash if called with base == 1
300-
if (base < 2)
301+
if (base < 2) {
301302
base = 10;
303+
}
302304

303305
do {
304-
unsigned long m = n;
306+
auto m = n;
305307
n /= base;
306308
char c = m - base * n;
307309

308310
*--str = c < 10 ? c + '0' : c + 'A' - 10;
309-
} while(n);
311+
} while (n);
310312

311313
return write(str);
312314
}

0 commit comments

Comments
 (0)