Skip to content

Commit 3452948

Browse files
sandeepmistryfacchinm
authored andcommitted
Increase buffer size for converting floats + doubles to String's
1 parent fc57f2e commit 3452948

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

cores/arduino/WString.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2020
*/
2121

22+
#include <float.h>
23+
2224
#include "WString.h"
2325
#include "itoa.h"
2426
#include "avr/dtostrf.h"
@@ -110,14 +112,14 @@ String::String(unsigned long value, unsigned char base)
110112
String::String(float value, unsigned char decimalPlaces)
111113
{
112114
init();
113-
char buf[33];
115+
char buf[FLT_MAX_10_EXP + 4 + decimalPlaces]; // +4, one for: 10, -, ., \0
114116
*this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf);
115117
}
116118

117119
String::String(double value, unsigned char decimalPlaces)
118120
{
119121
init();
120-
char buf[33];
122+
char buf[DBL_MAX_10_EXP + 4 + decimalPlaces]; // +4, one for: 10, -, ., \0
121123
*this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf);
122124
}
123125

0 commit comments

Comments
 (0)