diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp index 043fda7..dd5e2b2 100644 --- a/cores/arduino/WString.cpp +++ b/cores/arduino/WString.cpp @@ -20,6 +20,14 @@ */ #include "WString.h" +#include + +/*********************************************/ +/* Static Member Initialisation */ +/*********************************************/ + +size_t const String::FLT_MAX_DECIMAL_PLACES = DECIMAL_DIG; +size_t const String::DBL_MAX_DECIMAL_PLACES = DECIMAL_DIG; /*********************************************/ /* Constructors */ @@ -107,15 +115,19 @@ String::String(unsigned long value, unsigned char base) String::String(float value, unsigned char decimalPlaces) { + static size_t const FLOAT_BUF_SIZE = (FLT_MAX_10_EXP + 1) + FLT_MAX_DECIMAL_PLACES + 1 /* '-' */ + 1 /* '.' */ + 1 /* '\0' */; init(); - char buf[33]; + char buf[FLOAT_BUF_SIZE]; + decimalPlaces = decimalPlaces < FLT_MAX_DECIMAL_PLACES ? decimalPlaces : FLT_MAX_DECIMAL_PLACES; *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); } String::String(double value, unsigned char decimalPlaces) { + static size_t const DOUBLE_BUF_SIZE = (DBL_MAX_10_EXP + 1) + DBL_MAX_DECIMAL_PLACES + 1 /* '-' */ + 1 /* '.' */ + 1 /* '\0' */; init(); - char buf[33]; + char buf[DOUBLE_BUF_SIZE]; + decimalPlaces = decimalPlaces < DBL_MAX_DECIMAL_PLACES ? decimalPlaces : DBL_MAX_DECIMAL_PLACES; *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); } diff --git a/cores/arduino/WString.h b/cores/arduino/WString.h index 2cf4cd7..beab233 100644 --- a/cores/arduino/WString.h +++ b/cores/arduino/WString.h @@ -50,6 +50,9 @@ class String typedef void (String::*StringIfHelperType)() const; void StringIfHelper() const {} + static size_t const FLT_MAX_DECIMAL_PLACES; + static size_t const DBL_MAX_DECIMAL_PLACES; + public: // constructors // creates a copy of the initial value. diff --git a/libraries/Wire/examples/i2c_scanner/i2c_scanner.ino b/libraries/Wire/examples/i2c_scanner/i2c_scanner.ino index 295edf7..508de80 100644 --- a/libraries/Wire/examples/i2c_scanner/i2c_scanner.ino +++ b/libraries/Wire/examples/i2c_scanner/i2c_scanner.ino @@ -6,7 +6,7 @@ // can be found in many places. // For example on the Arduino.cc forum. // The original author is not known. -// Version 2, Juni 2012, Using Arduino 1.0.1 +// Version 2, June 2012, Using Arduino 1.0.1 // Adapted to be as simple as possible by Arduino.cc user Krodal // Version 3, Feb 26 2013 // V3 by louarnold diff --git a/platform.txt b/platform.txt index 63179d3..8c4f5eb 100644 --- a/platform.txt +++ b/platform.txt @@ -6,7 +6,7 @@ # https://arduino.github.io/arduino-cli/latest/platform-specification/ name=XInput AVR Boards -version=1.0.5 +version=1.0.6 # AVR compile variables # ---------------------