From 46519997e46f5088d627e537086cab14e8e14e6d Mon Sep 17 00:00:00 2001 From: Krzysztof Sywula Date: Tue, 22 Dec 2015 16:55:54 -0800 Subject: [PATCH] dtostrf: fix overflow problem JIRA: ATLEDGE-315 --- cores/arduino/stdlib_noniso.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cores/arduino/stdlib_noniso.cpp b/cores/arduino/stdlib_noniso.cpp index e583b691..5dabae88 100644 --- a/cores/arduino/stdlib_noniso.cpp +++ b/cores/arduino/stdlib_noniso.cpp @@ -194,12 +194,14 @@ char * dtostrf(double number, signed char width, unsigned char prec, char *s) { if (prec > 0) { *out = '.'; ++out; - + // Copy character by character to 'out' string for (unsigned char decShift = prec; decShift > 0; decShift--) { remainder *= 10.0; + sprintf(out, "%d", (int)remainder); + out++; + remainder -= (double)(int)remainder; } - sprintf(out, "%0*d", prec, (int)remainder); } return s; -} \ No newline at end of file +}