Piotr Caban : oleaut32: Fix SysReAllocStringLen implementation.

Alexandre Julliard julliard at winehq.org
Wed Dec 16 09:41:37 CST 2009


Module: wine
Branch: master
Commit: 7e3fd4e3c67fef7d70f4372bfd56414a945b61da
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=7e3fd4e3c67fef7d70f4372bfd56414a945b61da

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Tue Dec 15 23:46:42 2009 +0100

oleaut32: Fix SysReAllocStringLen implementation.

---

 dlls/oleaut32/oleaut.c        |    3 ++-
 dlls/oleaut32/tests/vartype.c |   14 ++++++++++++++
 2 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/dlls/oleaut32/oleaut.c b/dlls/oleaut32/oleaut.c
index 72b70e2..89e1ab9 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 a61c777..0c23a11 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)




More information about the wine-cvs mailing list