Skip to content

Commit 1a61a90

Browse files
committed
use less stack on number print
1 parent 0428ad8 commit 1a61a90

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Diff for: cores/arduino/Print.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,7 @@ size_t Print::println(const Printable& x)
202202

203203
size_t Print::printNumber(unsigned long n, uint8_t base)
204204
{
205-
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
206-
char *str = &buf[sizeof(buf) - 1];
207-
208-
*str = '\0';
205+
size_t written = 0;
209206

210207
// prevent crash if called with base == 1
211208
if (base < 2) base = 10;
@@ -214,10 +211,10 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
214211
char c = n % base;
215212
n /= base;
216213

217-
*--str = c < 10 ? c + '0' : c + 'A' - 10;
214+
written += write(c < 10 ? c + '0' : c + 'A' - 10, 1);
218215
} while(n);
219216

220-
return write(str);
217+
return written;
221218
}
222219

223220
size_t Print::printFloat(double number, uint8_t digits)

0 commit comments

Comments
 (0)