aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/str.cpp7
-rw-r--r--common/str.h2
2 files changed, 6 insertions, 3 deletions
diff --git a/common/str.cpp b/common/str.cpp
index 47dd6eef8c..6ac23126b4 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -32,8 +32,8 @@ const String String::emptyString;
const char *String::emptyString = "";
#endif
-String::String(const char *str, int len)
- : _str(0), _len(0) {
+String::String(const char *str, int len, int capacity)
+: _str(0), _len(0) {
_refCount = new int(1);
@@ -42,6 +42,9 @@ String::String(const char *str, int len)
_capacity = _len = len;
else
_capacity = _len = strlen(str);
+
+ _capacity = MAX(capacity, _capacity);
+
_str = (char *)calloc(1, _capacity+1);
memcpy(_str, str, _len);
_str[_len] = 0;
diff --git a/common/str.h b/common/str.h
index b345000164..1e7fa1577b 100644
--- a/common/str.h
+++ b/common/str.h
@@ -45,7 +45,7 @@ public:
#endif
String() : _str(0), _len(0), _capacity(0) { _refCount = new int(1); }
- String(const char *str, int len = -1);
+ String(const char *str, int len = -1, int capacity = 16);
String(const String &str);
virtual ~String();