[PATCH] SysReAllocStringLen should return null terminated strings.
Alexander Kochetkov
al.kochet at gmail.com
Tue Oct 13 03:43:30 CDT 2009
---
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