From e6f9ddc58064da203d6a97e2c5cf89d44b647df7 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Wed, 14 Sep 2016 11:21:43 -0400 Subject: [PATCH] Increase buffer size for converting floats + doubles to String's Previously it was too small to print FLT_MAX and DBL_MAX --- 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 533298225..152f85af3 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); }