Skip to content

Commit 4651999

Browse files
committed
dtostrf: fix overflow problem
JIRA: ATLEDGE-315
1 parent 162e0cf commit 4651999

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

cores/arduino/stdlib_noniso.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,14 @@ char * dtostrf(double number, signed char width, unsigned char prec, char *s) {
194194
if (prec > 0) {
195195
*out = '.';
196196
++out;
197-
197+
// Copy character by character to 'out' string
198198
for (unsigned char decShift = prec; decShift > 0; decShift--) {
199199
remainder *= 10.0;
200+
sprintf(out, "%d", (int)remainder);
201+
out++;
202+
remainder -= (double)(int)remainder;
200203
}
201-
sprintf(out, "%0*d", prec, (int)remainder);
202204
}
203205

204206
return s;
205-
}
207+
}

0 commit comments

Comments
 (0)