Improved checking of String appending during race conditions.

git-svn-id: http://yate.null.ro/svn/yate/trunk@3137 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2010-03-22 12:15:46 +00:00
parent 1e06cd8aba
commit 53bd36d6b9
1 changed files with 5 additions and 4 deletions

View File

@ -558,13 +558,14 @@ String& String::operator+=(const char* value)
value = 0;
if (value) {
if (m_string) {
int len = ::strlen(value)+length();
int olen = length();
int len = ::strlen(value)+olen;
char *tmp1 = m_string;
char *tmp2 = (char *) ::malloc(len+1);
if (tmp2) {
::strncpy(tmp2,m_string,len);
tmp2[len] = 0;
::strncat(tmp2,value,len);
::strncpy(tmp2,m_string,olen);
tmp2[olen] = 0;
::strncat(tmp2,value,len-olen);
tmp2[len] = 0;
m_string = tmp2;
::free(tmp1);