oleaut32: SysReAllocStringLen should return null terminated strings

Alexander Kochetkov al.kochet at gmail.com
Tue Oct 13 05:51:41 CDT 2009


This is another mail with attachment.

This patch implement hidden feature of SysReAllocStringLen. If second
argument of SysReAllocStringLen
is NULL, it should return null terminated strings.
This behavior was tested under XP, 98 and under XP with 95, 98, Me, 2k
compatability modes.
The test contain range test code, which depend on the implementation
of HeapReAlloc. Under some
conditions it fail, but under some compatibility modes it success.
This code is disabled.
May be, there is conflict  with comment of SysReAllocStringLen, says
" Subtle hidden feature: The old string data is still there  when 'in'
is NULL!  Some Microsoft program needs it."
I don't know that programs and cannot test them.
This behavior is need for Texas Instruments Code Composer Studio v3.3.
-------------- next part --------------
From 24e72c54dd4c5d8669604d31f7788284f89c9a45 Mon Sep 17 00:00:00 2001
From: Alexander Kochetkov <al.kochet at gmail.com>
Date: Tue, 13 Oct 2009 12:43:30 +0400
Subject: [PATCH] SysReAllocStringLen should return null terminated strings.

---
 dlls/oleaut32/oleaut.c        |    5 ++++
 dlls/oleaut32/tests/vartype.c |   42 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 46 insertions(+), 1 deletions(-)

diff --git a/dlls/oleaut32/oleaut.c b/dlls/oleaut32/oleaut.c
index 896d6d4..6886c7b 100644
--- a/dlls/oleaut32/oleaut.c
+++ b/dlls/oleaut32/oleaut.c
@@ -306,6 +306,11 @@ int WINAPI SysReAllocStringLen(BSTR* old, const OLECHAR* str, unsigned int len)
 	 * when 'in' is NULL!
 	 * Some Microsoft program needs it.
 	 */
+	 
+	/* Another hidden feature: XP, 98 always return string with
+	 * null terminator.
+	 */
+        (*old)[len] = 0;
       }
     } else {
       /*
diff --git a/dlls/oleaut32/tests/vartype.c b/dlls/oleaut32/tests/vartype.c
index 0321013..c6e92cb 100644
--- a/dlls/oleaut32/tests/vartype.c
+++ b/dlls/oleaut32/tests/vartype.c
@@ -5347,16 +5347,19 @@ static void test_SysReAllocStringLen(void)
   const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
   const OLECHAR szSmaller[2] = { 'x','\0' };
   const OLECHAR szLarger[7] = { 'L','a','r','g','e','r','\0' };
+  const int CHUNK_SIZE = 64; /* It is enough for Wine. Under XP with 95, 98, Me 
+                                compatability mode it should be 16384, to pass range test */
   BSTR str;
+  BSTR oldstr = NULL;
 
   str = SysAllocStringLen(szTest, 4);
   ok (str != NULL, "Expected non-NULL\n");
   if (str)
   {
     LPINTERNAL_BSTR bstr;
-    BSTR oldstr = str;
     int changed;
 
+    oldstr = str;
     bstr = Get(str);
     ok (bstr->dwLen == 8, "Expected 8, got %d\n", bstr->dwLen);
     ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
@@ -5383,6 +5386,43 @@ static void test_SysReAllocStringLen(void)
 
     SysFreeString(str);
   }
+  
+  /* XP, 98 always return null terminated strings */
+  /* Fill Heap with trash */
+  str = SysAllocStringLen(szTest, 4);
+  ok (str != NULL, "Expected non-NULL\n");
+  if (str)
+  {
+    SysReAllocStringLen(&str, NULL, CHUNK_SIZE);
+    ok (str != NULL, "Expected non-NULL\n");
+    if (str)
+    {
+      oldstr = str;
+      memset (str, 0xAB, CHUNK_SIZE * sizeof (OLECHAR));
+      SysFreeString(str);
+    }
+  }
+
+  /* Test for null terminator */
+  str = SysAllocStringLen(szTest, 4);
+  ok (str != NULL, "Expected non-NULL\n");
+  if (str)
+  {
+    SysReAllocStringLen(&str, NULL, 24);
+    ok (str != NULL, "Expected non-NULL\n");
+    if (str)
+    {
+      /* Do not include null terminator of oldstr */
+      /* BSTR end = oldstr + CHUNK_SIZE - 1 - 24; */
+
+      /* Next condition is true for wine, and XP with 95, 98, Me
+         compatability mode. It is false for clean 98, XP. */
+      /* ok (str >= oldstr && str <= end, 
+          "Expected string in range %p-%p, got %p\n", oldstr, end, str); */
+      ok (str[24] == 0, "Expected null terminator, got 0x%04X\n", str[24]);
+      SysFreeString(str);
+    }
+  }
 }
 
 static void test_BstrCopy(void)
-- 
1.6.0.4


More information about the wine-patches mailing list