richedit: Prevent string trunction due to NULL characters.

This commit is contained in:
Dylan Smith 2009-02-07 13:20:46 -05:00 committed by Alexandre Julliard
parent 1ceb903f9d
commit f53f40bcb3
2 changed files with 9 additions and 20 deletions

View File

@ -95,7 +95,6 @@ ME_String *ME_MakeStringB(int nMaxChars);
ME_String *ME_StrDup(const ME_String *s);
void ME_DestroyString(ME_String *s);
void ME_AppendString(ME_String *s1, const ME_String *s2);
ME_String *ME_ConcatString(const ME_String *s1, const ME_String *s2);
ME_String *ME_VSplitString(ME_String *orig, int nVPos);
int ME_IsWhitespaces(const ME_String *s);
int ME_IsSplitable(const ME_String *s);

View File

@ -90,35 +90,25 @@ void ME_DestroyString(ME_String *s)
void ME_AppendString(ME_String *s1, const ME_String *s2)
{
if (s1->nLen+s2->nLen+1 <= s1->nBuffer) {
lstrcpyW(s1->szData+s1->nLen, s2->szData);
s1->nLen += s2->nLen;
}
else
if (s1->nLen+s2->nLen+1 <= s1->nBuffer)
{
memcpy(s1->szData + s1->nLen, s2->szData, s2->nLen * sizeof(WCHAR));
s1->nLen += s2->nLen;
s1->szData[s1->nLen] = 0;
} else {
WCHAR *buf;
s1->nBuffer = ME_GetOptimalBuffer(s1->nLen+s2->nLen+1);
buf = ALLOC_N_OBJ(WCHAR, s1->nBuffer);
lstrcpyW(buf, s1->szData);
lstrcpyW(buf+s1->nLen, s2->szData);
buf = ALLOC_N_OBJ(WCHAR, s1->nBuffer);
memcpy(buf, s1->szData, s1->nLen * sizeof(WCHAR));
memcpy(buf + s1->nLen, s2->szData, s2->nLen * sizeof(WCHAR));
FREE_OBJ(s1->szData);
s1->szData = buf;
s1->nLen += s2->nLen;
s1->szData[s1->nLen] = 0;
}
}
ME_String *ME_ConcatString(const ME_String *s1, const ME_String *s2)
{
ME_String *s = ALLOC_OBJ(ME_String);
s->nLen = s1->nLen+s2->nLen;
s->nBuffer = ME_GetOptimalBuffer(s1->nLen+s2->nLen+1);
s->szData = ALLOC_N_OBJ(WCHAR, s->nBuffer);
lstrcpyW(s->szData, s1->szData);
lstrcpyW(s->szData+s1->nLen, s2->szData);
return s;
}
ME_String *ME_VSplitString(ME_String *orig, int charidx)
{
ME_String *s;