Skip to content

Commit 9492e14

Browse files
committed
String::concat increase buffer size to fit float/double value
1 parent 29d637e commit 9492e14

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

cores/arduino/WString.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,16 @@ unsigned char String::concat(unsigned long num)
334334

335335
unsigned char String::concat(float num)
336336
{
337-
char buf[20];
337+
static size_t const FLOAT_BUF_SIZE = (FLT_MAX_10_EXP + 1) + 2 /* FIXED DECIMAL PLACES */ + 1 /* '-' */ + 1 /* '.' */ + 1 /* '\0' */;
338+
char buf[FLOAT_BUF_SIZE];
338339
char* string = dtostrf(num, 4, 2, buf);
339340
return concat(string, strlen(string));
340341
}
341342

342343
unsigned char String::concat(double num)
343344
{
344-
char buf[20];
345+
static size_t const DOUBLE_BUF_SIZE = (DBL_MAX_10_EXP + 1) + 2 /* FIXED DECIMAL PLACES */ + 1 /* '-' */ + 1 /* '.' */ + 1 /* '\0' */;
346+
char buf[DOUBLE_BUF_SIZE];
345347
char* string = dtostrf(num, 4, 2, buf);
346348
return concat(string, strlen(string));
347349
}

0 commit comments

Comments
 (0)