aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/WString.cpp
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2013-12-31 22:30:55 +0100
committerCristian Maglie <c.maglie@bug.st>2014-01-01 17:22:40 +0100
commit1eee97d9806a76680388746987ecd95b88c36672 (patch)
treec1ea85ba95ae5721b50997b09053149b16aa2810 /cores/arduino/WString.cpp
parentbf370513979ce886816bc4670295c9f6c259d8ef (diff)
Improved portability of String class (maniacbug)
Diffstat (limited to 'cores/arduino/WString.cpp')
-rw-r--r--cores/arduino/WString.cpp21
1 files changed, 10 insertions, 11 deletions
diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp
index 8b6eabe..ed880ce 100644
--- a/cores/arduino/WString.cpp
+++ b/cores/arduino/WString.cpp
@@ -21,7 +21,6 @@
#include "WString.h"
-
/*********************************************/
/* Constructors */
/*********************************************/
@@ -69,7 +68,7 @@ String::String(char c)
String::String(unsigned char value, unsigned char base)
{
init();
- char buf[9];
+ char buf[1 + 8 * sizeof(unsigned char)];
utoa(value, buf, base);
*this = buf;
}
@@ -77,7 +76,7 @@ String::String(unsigned char value, unsigned char base)
String::String(int value, unsigned char base)
{
init();
- char buf[18];
+ char buf[2 + 8 * sizeof(int)];
itoa(value, buf, base);
*this = buf;
}
@@ -85,7 +84,7 @@ String::String(int value, unsigned char base)
String::String(unsigned int value, unsigned char base)
{
init();
- char buf[17];
+ char buf[1 + 8 * sizeof(unsigned int)];
utoa(value, buf, base);
*this = buf;
}
@@ -93,7 +92,7 @@ String::String(unsigned int value, unsigned char base)
String::String(long value, unsigned char base)
{
init();
- char buf[34];
+ char buf[2 + 8 * sizeof(long)];
ltoa(value, buf, base);
*this = buf;
}
@@ -101,7 +100,7 @@ String::String(long value, unsigned char base)
String::String(unsigned long value, unsigned char base)
{
init();
- char buf[33];
+ char buf[1 + 8 * sizeof(unsigned long)];
ultoa(value, buf, base);
*this = buf;
}
@@ -288,35 +287,35 @@ unsigned char String::concat(char c)
unsigned char String::concat(unsigned char num)
{
- char buf[4];
+ char buf[1 + 3 * sizeof(unsigned char)];
itoa(num, buf, 10);
return concat(buf, strlen(buf));
}
unsigned char String::concat(int num)
{
- char buf[12];
+ char buf[2 + 3 * sizeof(int)];
itoa(num, buf, 10);
return concat(buf, strlen(buf));
}
unsigned char String::concat(unsigned int num)
{
- char buf[11];
+ char buf[1 + 3 * sizeof(unsigned int)];
utoa(num, buf, 10);
return concat(buf, strlen(buf));
}
unsigned char String::concat(long num)
{
- char buf[12];
+ char buf[2 + 3 * sizeof(long)];
ltoa(num, buf, 10);
return concat(buf, strlen(buf));
}
unsigned char String::concat(unsigned long num)
{
- char buf[11];
+ char buf[1 + 3 * sizeof(unsigned long)];
ultoa(num, buf, 10);
return concat(buf, strlen(buf));
}