Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8e67a64

Browse files
use less stack on number print
1 parent 0428ad8 commit 8e67a64

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

‎cores/arduino/Print.cpp‎

Lines changed: 4 additions & 6 deletions
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,11 @@ 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+
c = (c < 10 ? c + '0' : c + 'A' - 10);
215+
written += write(&c, 1);
218216
} while(n);
219217

220-
return write(str);
218+
return written;
221219
}
222220

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /