File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed
Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change 2323#include " itoa.h"
2424#include " deprecated-avr-comp/avr/dtostrf.h"
2525
26+ #include < float.h>
27+
2628/* ********************************************/
2729/* Constructors */
2830/* ********************************************/
@@ -111,15 +113,17 @@ String::String(unsigned long value, unsigned char base)
111113
112114String::String (float value, unsigned char decimalPlaces)
113115{
116+ static size_t const FLOAT_BUF_SIZE = FLT_MAX_10_EXP + FLT_MAX_DECIMAL_PLACES + 1 /* '-' */ + 1 /* '.' */ + 1 /* '\0' */ ;
114117 init ();
115- char buf[33 ];
118+ char buf[FLOAT_BUF_SIZE ];
116119 *this = dtostrf (value, (decimalPlaces + 2 ), decimalPlaces, buf);
117120}
118121
119122String::String (double value, unsigned char decimalPlaces)
120123{
124+ static size_t const DOUBLE_BUF_SIZE = DBL_MAX_10_EXP + DBL_MAX_DECIMAL_PLACES + 1 /* '-' */ + 1 /* '.' */ + 1 /* '\0' */ ;
121125 init ();
122- char buf[33 ];
126+ char buf[DOUBLE_BUF_SIZE ];
123127 *this = dtostrf (value, (decimalPlaces + 2 ), decimalPlaces, buf);
124128}
125129
Original file line number Diff line number Diff line change @@ -58,6 +58,9 @@ class String
5858 typedef void (String::*StringIfHelperType)() const ;
5959 void StringIfHelper () const {}
6060
61+ static size_t const FLT_MAX_DECIMAL_PLACES = 10 ;
62+ static size_t const DBL_MAX_DECIMAL_PLACES = FLT_MAX_DECIMAL_PLACES;
63+
6164public:
6265 // constructors
6366 // creates a copy of the initial value.
You can’t perform that action at this time.
0 commit comments