Commit 7e3fd4e3 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

oleaut32: Fix SysReAllocStringLen implementation.

parent 17bec80f
...@@ -294,6 +294,7 @@ int WINAPI SysReAllocStringLen(BSTR* old, const OLECHAR* str, unsigned int len) ...@@ -294,6 +294,7 @@ int WINAPI SysReAllocStringLen(BSTR* old, const OLECHAR* str, unsigned int len)
return 0; return 0;
if (*old!=NULL) { if (*old!=NULL) {
BSTR old_copy = *old;
DWORD newbytelen = len*sizeof(WCHAR); DWORD newbytelen = len*sizeof(WCHAR);
DWORD *ptr = HeapReAlloc(GetProcessHeap(),0,((DWORD*)*old)-1,newbytelen+sizeof(WCHAR)+sizeof(DWORD)); DWORD *ptr = HeapReAlloc(GetProcessHeap(),0,((DWORD*)*old)-1,newbytelen+sizeof(WCHAR)+sizeof(DWORD));
*old = (BSTR)(ptr+1); *old = (BSTR)(ptr+1);
...@@ -302,7 +303,7 @@ int WINAPI SysReAllocStringLen(BSTR* old, const OLECHAR* str, unsigned int len) ...@@ -302,7 +303,7 @@ int WINAPI SysReAllocStringLen(BSTR* old, const OLECHAR* str, unsigned int len)
* when 'in' is NULL! * when 'in' is NULL!
* Some Microsoft program needs it. * Some Microsoft program needs it.
*/ */
if (str) memmove(*old, str, newbytelen); if (str && old_copy!=str) memmove(*old, str, newbytelen);
(*old)[len] = 0; (*old)[len] = 0;
} else { } else {
/* /*
......
...@@ -5440,6 +5440,20 @@ static void test_SysReAllocStringLen(void) ...@@ -5440,6 +5440,20 @@ static void test_SysReAllocStringLen(void)
} }
} }
} }
/* Some Windows applications use the same pointer for pbstr and psz */
str = SysAllocStringLen(szTest, 4);
ok(str != NULL, "Expected non-NULL\n");
if(str)
{
int changed;
changed = SysReAllocStringLen(&str, str, 1000000);
ok(SysStringLen(str)==1000000, "Incorrect string length\n");
ok(!memcmp(szTest, str, 4*sizeof(WCHAR)), "Incorrect string returned\n");
SysFreeString(str);
}
} }
static void test_BstrCopy(void) static void test_BstrCopy(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment