From 7e3fd4e3c67fef7d70f4372bfd56414a945b61da Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Tue, 15 Dec 2009 23:46:42 +0100 Subject: [PATCH] oleaut32: Fix SysReAllocStringLen implementation. --- dlls/oleaut32/oleaut.c | 3 ++- dlls/oleaut32/tests/vartype.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/dlls/oleaut32/oleaut.c b/dlls/oleaut32/oleaut.c index 72b70e2369f..89e1ab9dc2c 100644 --- a/dlls/oleaut32/oleaut.c +++ b/dlls/oleaut32/oleaut.c @@ -294,6 +294,7 @@ int WINAPI SysReAllocStringLen(BSTR* old, const OLECHAR* str, unsigned int len) return 0; if (*old!=NULL) { + BSTR old_copy = *old; DWORD newbytelen = len*sizeof(WCHAR); DWORD *ptr = HeapReAlloc(GetProcessHeap(),0,((DWORD*)*old)-1,newbytelen+sizeof(WCHAR)+sizeof(DWORD)); *old = (BSTR)(ptr+1); @@ -302,7 +303,7 @@ int WINAPI SysReAllocStringLen(BSTR* old, const OLECHAR* str, unsigned int len) * when 'in' is NULL! * Some Microsoft program needs it. */ - if (str) memmove(*old, str, newbytelen); + if (str && old_copy!=str) memmove(*old, str, newbytelen); (*old)[len] = 0; } else { /* diff --git a/dlls/oleaut32/tests/vartype.c b/dlls/oleaut32/tests/vartype.c index a61c777ae64..0c23a1143d8 100644 --- a/dlls/oleaut32/tests/vartype.c +++ b/dlls/oleaut32/tests/vartype.c @@ -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)