From 3452948f223438619f9cf1d93cf4f1aae9e94bc4 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Wed, 14 Sep 2016 13:50:52 -0400 Subject: [PATCH] Increase buffer size for converting floats + doubles to String's --- cores/arduino/WString.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp index 71bbc07d..65b117db 100644 --- a/cores/arduino/WString.cpp +++ b/cores/arduino/WString.cpp @@ -19,6 +19,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include "WString.h" #include "itoa.h" #include "avr/dtostrf.h" @@ -110,14 +112,14 @@ String::String(unsigned long value, unsigned char base) String::String(float value, unsigned char decimalPlaces) { init(); - char buf[33]; + char buf[FLT_MAX_10_EXP + 4 + decimalPlaces]; // +4, one for: 10, -, ., \0 *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); } String::String(double value, unsigned char decimalPlaces) { init(); - char buf[33]; + char buf[DBL_MAX_10_EXP + 4 + decimalPlaces]; // +4, one for: 10, -, ., \0 *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); }